[英]PowerShell script to check if directory is shared or not?
I am using the following command in PowerShell 2.0 to check if the particular folder is shared or not but I am getting an error. 我在PowerShell 2.0中使用以下命令来检查特定文件夹是否共享,但出现错误。
[bool](Get-WmiObject -Class Win32_Share -ComputerName ravenPC -Filter "Path='D:\websites\website1'")
Also, I want to store the value of bool in a variable and check it each time if it's true or false. 另外,我想将bool的值存储在变量中,并在每次检查是对还是错时对其进行检查。 Can someone help me on this. 有人可以帮我吗
The error I get is as follows: 我得到的错误如下:
Get-WmiObject : Invalid query At line:1 char:21 + [bool](Get-WmiObject <<<< -Class Win32_Share -ComputerName ravenPC -Filter "Path='D:\websites\website1'") + CategoryInfo : InvalidOperation: (:) [Get-WmiObject], ManagementException + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
您需要在WMI查询中转义反斜杠:
[bool](Get-WmiObject -Class Win32_Share -ComputerName ravenPC -Filter "Path='D:\\websites\\website1'")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.