I have a csv file with two columns "Path" and "Owner".
I've created the below script and it can read from the CSV file, but when I attempt to assign the variables from the csv it fails.
Import-Csv C:\test\output.csv | ForEach-Object {
$Path = $_.path
$owner = $_.owner
"The username is $Path and the owner is $owner"
}
ForEach-Object {
$Path = $_.path
$owner = $_.owner
$Account = New-Object -TypeName System.Security.Principal.NTAccount -ArgumentList '$owner'
$Acl = Get-Acl -Path $Path
$Acl.SetOwner($Account)
Set-Acl -Path $owner -AclObject $Acl
}
The output is correct from the first segment and shows the path and the owner, but the second part doesn't set the owner according to the path.