Me and an college is currently working on moving the data from an old file server to a new file server with a brand new directory structure. After the files have been migrated we have to move the ACLs on the folders on level two, we where planing on doing this with a powershell script that looked something like this:
$import = Import-Csv C:\test\acl.csv foreach ($row in $import) { Get-acl $row.source | set-acl $row.target }
By using a “.” after the variable to pin-point which property to use. Since the old server is Windows 2008 r2 and uses powershell 2 using the dot to point out proeperties ain`t supported.
I then tried to throw in some variables in the foreach loop with select-item to get the data I needed, unlucky for me this didn´t work either. It looked like this:
$import = Import-Csv C:\test\acl.csv foreach ($row in $import) { $source = $row | select source $target = $row | select target Get-acl $source | set-acl $target }
The problem here is that “$variable | select property” is an PSCustomObject and get-acl and set-acl wants a string-object. If you pipe the variable to get-member($variable | select property | get-member) you will find out what type you have, in this example it looked like this “TypeName: System.Management.Automation.PSCustomObject”. To get a string you need to use -ExpandProperty with select-item, after doing this the script will work on both old(powershell 2.0) and newer versions and will look like this:
$import = Import-Csv C:\test\acl.csv foreach ($row in $import) {$source = $row | select -ExpandProperty source $target = $row | select -ExpandProperty target Get-acl -Path $source | set-acl -Path $target }