1
votes

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.

[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. 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
1
Maybe you can use something like this(tested on my local machine) if(Get-WmiObject -Class Win32_Share | Select-String -pattern "yourFolder"){ echo "Is Shared"; }Hackerman
Bro, this doesn't work. no error, but no output comes :(CodeX

1 Answers

2
votes

You need to escape the backslashes in your WMI query:

[bool](Get-WmiObject -Class Win32_Share -ComputerName ravenPC -Filter "Path='D:\\websites\\website1'")