Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 8583

Why does my search fail?

$
0
0

$NetBIOS = get-content env:computername

$objWMI = get-wmiobject -computername $NetBIOS -Namespace root\CIMV2 -Query "Select * from Win32_OfflineFilesItem"  | Where { $_.Path -like "*$NetBIOS*" } | Select -first 1

foreach ($obj in $objWmi) 

   {

      if ($obj -match $NetBIOS) {New-Item -ItemType directory -Path \\acmecom\dfs\programs\dfscheck\Enabled\$NetBIOS} 

      Else {New-Item -ItemType directory -Path \\acme.com\dfs\programs\dfscheck\Disabled\$NetBIOS}

   }

 

_____________________________________________________________________________________

 

the code above works.   What I'm trying to do is find out workstations that are not connect to our corporate DFS share.   If they are then  $objWMI will contain the string \userdata\    If it is a user who is NOT connected to DFS then the string \userdata\ is NOT present.

 

So I've tried the following.

if ($obj -match "\userdata\")

if ($obj -like "\userdata\")

 

And neither one works.   Why?  I need to know when \userdata\ is found inside the $obj variable.    So what am I doing wrong in my code?

 

 

 

 


Viewing all articles
Browse latest Browse all 8583

Latest Images

Trending Articles



Latest Images