Besitzer eines Ordners ändern

Funktion mit Übergabe von Credentials und Invoke-Command

function setfilesystemowner ([string]$file, [string]$PrincipalAccount, [string]$DC, [string]$AdminAccount, [string]$Password)
{
	$acl = get-acl $file
	$acc = new-object System.Security.Principal.NTAccount($PrincipalAccount)
	$acl.setowner($acc)
	$PW = ConvertTo-Securestring $Password -AsPlainText -force
	$Credential = New-Object System.Management.Automation.PSCredential($AdminAccount,$PW)
	$Session = New-PSSession -ComputerName $DC -Credential $Credential
	Invoke-Command -Session $Session -ScriptBlock {param ($a1,$a2) Set-ACL $a1 $a2} -ArgumentList $file,$acl
	Remove-PSSession $Session
}

Funktion ohne Übergabe von Credentials

function setfilesystemowner ([string]$file, [string]$PrincipalAccount)
{
	$acl = get-acl $file
	$acc = new-object System.Security.Principal.NTAccount($PrincipalAccount)
	$acl.setowner($acc)
	Set-ACL $file $acl
}

Parameter: