###Erstellung eines Benutzer-Verzeichnises / js / 2020 # erforderliche Provisioning-Parameter der Resource: # $username # wird immer von Tenfold mitgeliefert # $NTDomain # NT-Domänenname # $Server # Server auf dem das Skript laufen soll (einmalig winrm quickconfig ausführen) # $Path # Name der Dateifreigabe z.B. "\\server\share" # erforderliche Resourcenbedingungen: # "Resource - New" # "Resource - Delete" ############################################################## # return 0; $userName = $params.request.person.masterdata.userName $rti = $params.request.type.id $NTDomain = $params.ntdomain $Path = $params.path $server = $params.server $userpath = "$path\$username" $port = 5985 ##### Check connections ############################################################ if (-not (Test-NetConnection -ComputerName $server -Port $port )){ throw "error: Server $server an Port $port nicht erreichbar!" } #################################################################################### else{ Invoke-Command -ComputerName $server -Credential $cred -ConfigurationName homedir -ScriptBlock { #SessionRegistrierung auf dem Server einmalig ausführen #Register-PSSessionConfiguration -Name homedir -RunAsCredential 'ntdom\myuser' -force If ((Test-Path $using:path)){ ### Verzeichnis erstellen... If ((!( Test-Path $using:userPath)) -and ( $using:rti -eq 1)) { New-Item $using:userPath -ItemType directory $acl = Get-Acl $using:userPath $permission = "$using:Username","FullControl","ContainerInherit,ObjectInherit","None","Allow" $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission $ID = New-object System.Security.Principal.NTAccount($using:NTDomain,$using:userName) $acl.SetAccessRule($accessRule) $acl.SetOwner($ID) $acl | Set-Acl $using:userPath } ###Verzeichnis löschen... If (( Test-Path $using:userPath ) -and ( $using:rti -eq 3) ) { Remove-Item -Recurse -Force $using:userPath -ErrorAction SilentlyContinue } } } } ####################################################################################