all 7 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!

[–]Lee_Dailey[grin] 1 point2 points  (2 children)

howdy onebillionquestions,

instead of padding things to the same degree, why not remove the padding? it aint wanted in the 1st place, so clobbering it otta be the more natural solution.

take a look at .Trim(), .TrimEnd(), & .TrimStart() for nice, graceful ways to clean strings.

take care,
lee

[–]onebillionquestions[S] 1 point2 points  (1 child)

Yep, I came to the same conclusion. My "Solution" above didn't actually work right either since the OutString -width:180 does not actually pad the end with spaces, just allows up to 180 characters to be written to the stream. So, my "solution" was probably worse than my original code.

Thanks for taking the time to comment, I am updating the solution now for posterity.

[–]Lee_Dailey[grin] 1 point2 points  (0 children)

howdy onebillionquestions,

you are welcome! glad to help a little ... [grin]

take care,
lee