I have the following script written to list all the user directories on selected Terminal Servers.
It outputs them into a grid view, but what I want to be able to do is select the name from the grid view and have the script then delete the folder.
Let's say I specify the server TS-1 and it brings back the list of users. I'll use Fred as an example.
The list will have it showing as fred 09/20/2014 08:01:07
When I click fred in the gridview I get an error of Remove-Item : Cannot find drive. A drive with the name 'fred 09/20/2014 08' does not exist.
I know I'm missing a minor part of the script, but I can't seem to find what I'm looking for when researching it. I'm assuming it's looking for the literal path of the folder I want to delete.
#Prompt for a computer to connect to
$computer = Read-Host "Please enter a computer name"
gci \\$computer\c$\Users | % {"$_ $($_.LastWriteTime)"} |
Sort-object name |
Out-GridView -PassThru | select |
Remove-Item