【问题标题】:Win32_LogicalFileSecuritySetting returns an error for some paths, but not othersWin32_LogicalFileSecuritySetting 为某些路径返回错误,但不是其他路径
【发布时间】:2013-10-09 13:56:51
【问题描述】:

我从 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

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

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

【问题讨论】:

  • 请为您的问题添加一些格式并向我们展示相关代码。

标签: powershell permissions wmi fileshare


【解决方案1】:

我相信这是因为:

[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

【讨论】:

  • 我应该怀疑那个代码。谢谢。我用$SharedFolderPath = $Share.Path -replace '\\','\\'修复了它
猜你喜欢
  • 2022-11-18
  • 1970-01-01
  • 1970-01-01
  • 2023-03-12
  • 1970-01-01
  • 1970-01-01
  • 2021-03-14
  • 1970-01-01
  • 2018-09-08
相关资源
最近更新 更多