Trying to reach out to one server (by name) and search for the Profile DIR for each username's existence from the list of users, whom I need to delete. After many many attempts, still seeing a result of "$User profile not found." Even though I can see that it is clearly in the DIR. When I run one specific test for one user, it shows up.. example: `
$DelUser = "user.name"
$ProfileUser = "\\dc1\P$\Profiles\$DelUser" + ".V6"
if ([System.IO.Directory]::Exists($ProfileUser)) {
"......$DelUser..... EXISTS!"
else {
"$DelUser Path NOT FOUND!"
}
}
Pulling from the source (txt) file (I've also tried using a csv file with import-csv
with same results) I try to go through the list and search for the existence of each user folder with the below code.
User folders are in the user.name.V6
format.
Below a sample with some commented alternate attempts.
$DelUser = Get-Content -Path C:\DelFolder\Delete-DC1-Users.txt
$UserPath = "\\DC1\P$\Profiles\$User" + ".V6"
foreach ($User in $DelUser) {
if ([System.IO.Directory]::Exists($UserPath)) {
Write-Host "$UserPath EXISTS"
#if (Test-Path -Path $UserPath) {
# if ($UserPath) {
# Write-Host "$User Folder Exists"
}
else {
Write-Host "$User Folder DOES NOT EXIST"
}
}
And at best I'll see the $User Folder DOES NOT EXIST
even though it does in fact exist on the server.
I've also tried using Test-Path
to no avail, as seen above in the commented out lines.
Thank you! P.S. My first posted question here, so my apologies for any mishaps or mistakes!