Hello, I’m a newbie with PS and found this script on Netwrix’s website and even referenced the same script shared on here. I’ve made changes to the $Outfile and $Rootpath as suggested. I get the “where-object” below referencing the “foreach” parameter error and I’m not sure how to correct this.<\/p>\n
Advertisement
Any help would be greatly appreciated.<\/p>\n
Advertisement
Thanks!<\/p>\n
PS C:\\windows\\system32> $OutFile = “C:\\FileShareACL\\Permissions1.csv” # Insert folder path where you want to save your file and its name \n$Header = “Folder Path,IdentityReference,AccessControlType,IsInherited,InheritanceFlags,PropagationFlags” \n$FileExist = Test-Path $OutFile \nIf ($FileExist -eq $True) {Del $OutFile} \nAdd-Content -Value $Header -Path $OutFile \n$RootPath = “\\servername\\shareT” # Insert your share path \n$Folders = dir $RootPath -recurse | where {$.psiscontainer -eq $true} foreach ($Folder) in ($Folders){ \n$ACLs = get-acl $Folder.fullname | ForEach-Object `{ $<\/em>.Access } \nForeach ($ACL in $ACLs){ \n$OutInfo = $Folder.Fullname + “,” + $ACL.IdentityReference + “,” + $ACL.AccessControlType + “,” + $ACL.IsInherited + “,” + $ACL.InheritanceFlags + “,” + $ACL.PropagationFlags \nAdd-Content -Value $OutInfo -Path $OutFile \n}<\/p>\n
Where-Object : A positional parameter cannot be found that accepts argument ‘foreach’. \nAt line:7 char:37<\/p>\n
\n
… -recurse | where {$_.psiscontainer -eq $true} foreach ($Folder) in ( …<\/li>\n
Hello, I’m a newbie with PS and found this script on Netwrix’s website and even referenced the same script shared on here. I’ve made changes to the $Outfile and $Rootpath as suggested. I get the “where-object” below referencing the “foreach” parameter error and I’m not sure how to correct this.<\/p>\n
Any help would be greatly appreciated.<\/p>\n
Thanks!<\/p>\n
PS C:\\windows\\system32> $OutFile = “C:\\FileShareACL\\Permissions1.csv” # Insert folder path where you want to save your file and its name \n$Header = “Folder Path,IdentityReference,AccessControlType,IsInherited,InheritanceFlags,PropagationFlags” \n$FileExist = Test-Path $OutFile \nIf ($FileExist -eq $True) {Del $OutFile} \nAdd-Content -Value $Header -Path $OutFile \n$RootPath = “\\servername\\shareT” # Insert your share path \n$Folders = dir $RootPath -recurse | where {$.psiscontainer -eq $true} foreach ($Folder) in ($Folders){ \n$ACLs = get-acl $Folder.fullname | ForEach-Object `{ $<\/em>.Access } \nForeach ($ACL in $ACLs){ \n$OutInfo = $Folder.Fullname + “,” + $ACL.IdentityReference + “,” + $ACL.AccessControlType + “,” + $ACL.IsInherited + “,” + $ACL.InheritanceFlags + “,” + $ACL.PropagationFlags \nAdd-Content -Value $OutInfo -Path $OutFile \n}<\/p>\n
Where-Object : A positional parameter cannot be found that accepts argument ‘foreach’. \nAt line:7 char:37<\/p>\n
\n
… -recurse | where {$_.psiscontainer -eq $true} foreach ($Folder) in ( …<\/li>\n
I think you’re just missing a pipeline character.<\/p>\n
$Folders = dir $RootPath -recurse | where {$_.psiscontainer -eq $true} foreach ($Folder) in ($Folders){\n<\/code><\/pre>\n
Should be:<\/p>\n
$Folders = dir $RootPath -recurse | where {$_.psiscontainer -eq $true} | foreach ($Folder) in ($Folders){\n<\/code><\/pre>","upvoteCount":1,"datePublished":"2020-05-14T18:14:48.000Z","url":"https://community.spiceworks.com/t/ntfs-script/762718/2","author":{"@type":"Person","name":"big-green-man","url":"https://community.spiceworks.com/u/big-green-man"}},{"@type":"Answer","text":"
If you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>\n