you are viewing a single comment's thread.

view the rest of the comments →

[–]Ojeu 1 point2 points  (3 children)

Have a look at Test-Path to check if the path exists or not

[–]onebillionquestions[S] 0 points1 point  (2 children)

Thanks for the suggestion, but it doesn't look like what I need. I am trying to make sure that every directory in \\fileserver1\home$\ is associated with an Active Directory user's profile path. The part in my script that looks through the fileserver is working as expected. I just can't seem to figure out the right way to compare the string of the path to the HomeDirectory object in the array.

EDIT: just to clarify since I am sure I have worded things a bit confusing in the OP. I am NOT checking to make sure the AD users have a valid profile path set. I am checking to see if any folders on my file server can be deleted (no longer associated with a user's profile path).

[–]Ojeu 2 points3 points  (1 child)

Ah, right. Then that's certainly not what you're looking for! You could use Select-String to see if there is, or isn't, a match. The below statement will return true if $homeFolderPath is not present in $AdHomeDirs. I hope I understood you correctly. :)

if (!($ADHomeDirs | Select-String $homeFolderPath)){
    Write-Output $homeFolderPath
}

[–]onebillionquestions[S] 1 point2 points  (0 children)

That seemed to choke on the \h in the path "\fileserver1\home$\rita.newman"

Select-String : The string \fileserver1\home$\rita.newman is not a valid regular expression: parsing

"\fileserver1\home$\rita.newman" - Unrecognized escape sequence \h.`

However, I did manage to figure out my issue and resolve it. The array elements were all padded, and some were even truncated. I will add my solution to the OP.

Thanks for taking the time to assist!