Question

I got a script from Microsoft that uses the following method to get NTFS security settings from a remote machine.

$SharedFolderPath=[regex]::Escape("D:\UserSetup");
$SharedNTFSSecs = Get-WmiObject -Class Win32_LogicalFileSecuritySetting -Filter "Path='$SharedFolderPath'" -ComputerName $Computer

$SharedFolderPath=[regex]::Escape("C:\Program Files\AdventNet\ME\OpManager\Reports");
$SharedNTFSSecs = Get-WmiObject -Class Win32_LogicalFileSecuritySetting -Filter "Path='$SharedFolderPath'" -ComputerName $Computer

I got the paths from a previous call to Win32_Share. The first one works fine, the second gives an error:

> Get-WmiObject : Invalid query  At line:1 char:118
> + $SharedFolderPath=[regex]::Escape("C:\Program Files\AdventNet\ME\OpManager\Reports"); $SharedNTFSSecs =
> Get-WmiObject <<<<   -Class Win32_LogicalFileSecuritySetting -Filter
> "Path='$SharedFolderPath'" -ComputerName $Computer
>     + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], ManagementException
>     + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

The only thing different is the path:

D:\UserSetup
C:\Program Files\AdventNet\ME\OpManager\Reports

I can connect to the share and view the security permissions. I am effectively in the local administrators group and that group has full control over the problem share.

Does anyone have any clue why I'm getting an error (and consequently no resulting object)?

Was it helpful?

Solution

I beleive that this is because :

[regex]::Escape("C:\Program Files\AdventNet\ME\OpManager\Reports")

gives

C:\\Program\ Files\\AdventNet\\ME\\OpManager\\Reports

The white space is escaped also, try :

Get-WmiObject -Class Win32_LogicalFileSecuritySetting -Filter "Path='C:\\Program Files\\AdventNet\\ME\\OpManager\\Reports'" -ComputerName $Computer
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top