as

AppSense – Personalisierung: Benutzerdaten automatisiert verschieben (MoveDataToGroup)

Das folgende Skript verschiebt automatisiert Benutzerdaten von einer Personalisierungsgruppe in eine andere. Dies kann in Migrationsszenarien sehr hilfreich sein.

Dazu liest das Skript eine CSV Datei, in der sich die Benutzerkennungen befinden, ein und arbeitet diese ab.

Im Skript muss unter Variablen der AppSense Server und die Domäne angegeben werden!

#-----Auslesen des Skriptpfad-----------------------------------------------
function Get-ScriptDirectory {
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
Split-Path $Invocation.MyCommand.Path
}
#---------------------------------------------------------------------------
#-----Variablen-------------------------------------------------------------
$AppSenseServer = "APPSENSESERVER"
$UDomain = "DOMAIN"
$SourceGroupName = "Migration"
$DestinationGroupName = "PG01"
$global:LogFile = Join-Path (Get-ScriptDirectory) "AppSense_Migration.log"
#---------------------------------------------------------------------------
#-----Read user file--------------------------------------------------------
$logText = "{0:yyyy-MM-dd  HH-mm-ss} - ERROR - No user file found" -f (Get-Date)
$userlist = Join-Path (Get-ScriptDirectory) "appsense_migrate_user.csv"
If (-NOT (test-path "$userlist")){$logText | out-file -Append $global:LogFile; EXIT 2}
Else {$global:UserList = Get-Content $userlist}
#---------------------------------------------------------------------------
#-----Load Appsense module--------------------------------------------------
import-module "c:\program files\AppSense\Environment Manager\Personalization Server\API\Modules\EMPImportExport"
$pmClient = [PSProxy]::ConnectWindows($AppSenseServer)
If ($? -eq $False){$logText = "{0:yyyy-MM-dd  HH-mm-ss} - ERROR - Cannot reach Appsense server $AppSenseServer" -f (Get-Date); $logText | out-file -Append $global:LogFile; EXIT 3}
Else{$logText = "{0:yyyy-MM-dd  HH-mm-ss} - SUCCESS - Connected Appsense server $AppSenseServer" -f (Get-Date); $logText | out-file -Append $global:LogFile}
#---------------------------------------------------------------------------
#-----Functions-------------------------------------------------------------
function fu_MoveDataToGroup ($MUser){
write-host "Migrate user $MUser. Please wait..."
$ReutrnCode = $pmClient.MoveDataToGroup("$UDomain\$MUser",$SourceGroupName,$DestinationGroupName,0,0)
switch ($ReutrnCode.ErrorCode){
-1 {$logText = "{0:yyyy-MM-dd  HH-mm-ss} - ERROR - $MUser - user or group does not exist" -f (Get-Date);write-host $logText;$logText | out-file -Append $global:LogFile}
0 {$logText = "{0:yyyy-MM-dd  HH-mm-ss} - ERROR - $MUser - data exists in destination group but override not set" -f (Get-Date);write-host $logText;$logText | out-file -Append $global:LogFile}
1 {$logText = "{0:yyyy-MM-dd  HH-mm-ss} - SUCCESS - $MUser - OK, always migrated" -f (Get-Date);write-host $logText;$logText | out-file -Append $global:LogFile}
2 {$logText = "{0:yyyy-MM-dd  HH-mm-ss} - SUCCESS - $MUser - worked OK but new group’s whitelists don’t match old (warning)" -f (Get-Date);write-host $logText;$logText | out-file -Append $global:LogFile}
}
}
#---------------------------------------------------------------------------
#-----Migrate user----------------------------------------------------------
foreach ($entry in $global:UserList){
If ($entry){fu_MoveDataToGroup $entry}
}
#---------------------------------------------------------------------------
Start-Process -FilePath "C:\windows\system32\notepad.exe" -ArgumentList "$global:LogFile"

 

Hinterlasse eine Antwort

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *