Hi,
I wonder if anyone can help me with the powershell script (below) for deleting cached local user profiles on multiple Terminal servers.
The script runs without errors but cannot find the location of user profiles and as such cannot display them.
Please see script below, I pasted only the sections that's not working.
#Run through each computer in the computers variable to compile a list of unique user accounts across all servers
ForEach ($computer in $Computers) {
#use WMI to find all users with a profile on the servers
Try{
[array]$users = Get-WmiObject -ComputerName $computer Win32_UserProfile -filter "LocalPath Like 'C:\\Users\\%'" -ea stop
}
Catch {
Write-Warning "$($error[0]) "
Break
}
#compile the profile list and remove the path prefix leaving just the usernames
$profilelist = $profilelist + $users.localpath -replace "C:\\users\\"
#filter the user names to show only unique values left to prevent duplicates from profile existing on multiple computers
$uniqueusers = $profilelist | Select-Object -Unique
}
#adds the unique users to the combo box
ForEach($user in $uniqueusers) {
[void] $objCombo.Items.Add($user)
}
$objForm.Controls.Add($objCombo)
$objForm.Topmost = $True
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
}
Function DeleteProfile {
#Add the path prefix back to the selected user
$selectedUser = "C:\Users\$selecteduser
I wonder if anyone can help me with the powershell script (below) for deleting cached local user profiles on multiple Terminal servers.
The script runs without errors but cannot find the location of user profiles and as such cannot display them.
Please see script below, I pasted only the sections that's not working.
#Run through each computer in the computers variable to compile a list of unique user accounts across all servers
ForEach ($computer in $Computers) {
#use WMI to find all users with a profile on the servers
Try{
[array]$users = Get-WmiObject -ComputerName $computer Win32_UserProfile -filter "LocalPath Like 'C:\\Users\\%'" -ea stop
}
Catch {
Write-Warning "$($error[0]) "
Break
}
#compile the profile list and remove the path prefix leaving just the usernames
$profilelist = $profilelist + $users.localpath -replace "C:\\users\\"
#filter the user names to show only unique values left to prevent duplicates from profile existing on multiple computers
$uniqueusers = $profilelist | Select-Object -Unique
}
#adds the unique users to the combo box
ForEach($user in $uniqueusers) {
[void] $objCombo.Items.Add($user)
}
$objForm.Controls.Add($objCombo)
$objForm.Topmost = $True
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
}
Function DeleteProfile {
#Add the path prefix back to the selected user
$selectedUser = "C:\Users\$selecteduser