Win32_LogicalFileSecuritySetting为某些路径返回错误,但不返回其他路径

时间:2013-10-03 01:41:21

标签: powershell permissions wmi fileshare

我从Microsoft获得了一个脚本,该脚本使用以下方法从远程计算机获取NTFS安全设置。

$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

我从前一次调用Win32_Share获得了路径。第一个工作正常,第二个给出错误:

> 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

唯一不同的是路径:

  

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

我可以连接到共享并查看安全权限。我实际上在本地管理员组中,该组可以完全控制问题共享。

有没有人知道我为什么会收到错误(因而没有结果对象)?

1 个答案:

答案 0 :(得分:0)

我认为这是因为:

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

给出

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

白色空间也被转义,尝试:

Get-WmiObject -Class Win32_LogicalFileSecuritySetting -Filter "Path='C:\\Program Files\\AdventNet\\ME\\OpManager\\Reports'" -ComputerName $Computer
相关问题