\nIt only seems to work some of the times. Is there a better way to write it?<\/p>\n<\/blockquote>\n<\/aside>\n
Could the user still be logged in? If it does not work, do you get an error message?<\/p>\n
Is the Goverlan thing an agent installed on the machine?<\/p>\n
If you run it as system you can force log all the users out and then try to delete it?<\/p>","upvoteCount":0,"datePublished":"2018-09-27T19:46:01.000Z","url":"https://community.spiceworks.com/t/deleting-a-user-profile-via-powershell-script/675781/3","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
User needs to be logged out, but the profile I am trying to delete is logged out. I don’t get any error message. Goverlan is installed because I can remote into it.<\/p>","upvoteCount":0,"datePublished":"2018-09-27T19:49:22.000Z","url":"https://community.spiceworks.com/t/deleting-a-user-profile-via-powershell-script/675781/4","author":{"@type":"Person","name":"spiceuser-sqqz9","url":"https://community.spiceworks.com/u/spiceuser-sqqz9"}},{"@type":"Answer","text":"\n\n
<\/div>\n
BobalonGaterau:<\/div>\n
\nUser needs to be logged out, but the profile I am trying to delete is logged out. I don’t get any error message. Goverlan is installed because I can remote into it.<\/p>\n<\/blockquote>\n<\/aside>\n
What if you just try<\/p>\n
$us = \"User ID\"\nremove-item \"c:\\users\\$us\" -Recurse -Force -Verbose\n<\/code><\/pre>\nDoes the account you run it as have the right permissions?<\/p>","upvoteCount":0,"datePublished":"2018-09-27T19:56:05.000Z","url":"https://community.spiceworks.com/t/deleting-a-user-profile-via-powershell-script/675781/5","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
You should not use the profile directory to identify it, as it is not guaranteed to be the same as the username.<\/p>","upvoteCount":1,"datePublished":"2018-09-27T20:18:18.000Z","url":"https://community.spiceworks.com/t/deleting-a-user-profile-via-powershell-script/675781/6","author":{"@type":"Person","name":"tulioarends","url":"https://community.spiceworks.com/u/tulioarends"}},{"@type":"Answer","text":"
What is another way for me to identify the user profile? We have our usernames all formatted the same so it usually works.<\/p>","upvoteCount":0,"datePublished":"2018-09-27T20:45:09.000Z","url":"https://community.spiceworks.com/t/deleting-a-user-profile-via-powershell-script/675781/7","author":{"@type":"Person","name":"spiceuser-sqqz9","url":"https://community.spiceworks.com/u/spiceuser-sqqz9"}},{"@type":"Answer","text":"\n\n
<\/div>\n
Neally:<\/div>\n
\n\n\n
<\/div>\n
BobalonGaterau:<\/div>\n
\nUser needs to be logged out, but the profile I am trying to delete is logged out. I don’t get any error message. Goverlan is installed because I can remote into it.<\/p>\n<\/blockquote>\n<\/aside>\n
What if you just try<\/p>\n
$us = \"User ID\"\nremove-item \"c:\\users\\$us\" -Recurse -Force -Verbose\n<\/code><\/pre>\nDoes the account you run it as have the right permissions?<\/p>\n<\/blockquote>\n<\/aside>\n
That would work, but I also need to remove the registry directory for the user.<\/p>","upvoteCount":0,"datePublished":"2018-09-27T20:52:06.000Z","url":"https://community.spiceworks.com/t/deleting-a-user-profile-via-powershell-script/675781/8","author":{"@type":"Person","name":"spiceuser-sqqz9","url":"https://community.spiceworks.com/u/spiceuser-sqqz9"}},{"@type":"Answer","text":"\n\n
<\/div>\n
BobalonGaterau:<\/div>\n
\nThat would work, but I also need to remove the registry directory for the user.<\/p>\n<\/blockquote>\n<\/aside>\n
well, add more code to do that?<\/p>","upvoteCount":1,"datePublished":"2018-09-27T20:59:57.000Z","url":"https://community.spiceworks.com/t/deleting-a-user-profile-via-powershell-script/675781/9","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
Just saw this.<\/p>\n
What happens when it doesn’t work? What errors do you see? DO you have a PowerShell Transcript where it fails?<\/p>","upvoteCount":0,"datePublished":"2018-09-27T21:21:41.000Z","url":"https://community.spiceworks.com/t/deleting-a-user-profile-via-powershell-script/675781/10","author":{"@type":"Person","name":"DoctorDNS","url":"https://community.spiceworks.com/u/DoctorDNS"}},{"@type":"Answer","text":"\n\n
<\/div>\n
BobalonGaterau:<\/div>\n
\nWhat is another way for me to identify the user profile? We have our usernames all formatted the same so it usually works.<\/p>\n<\/blockquote>\n<\/aside>\n
The SID of the user.<\/p>\n
$us = Get-ADUser \"user\" | select -ExpandProperty SID\nGet-WmiObject -Class Win32_UserProfile | Where {$_.SID -eq $us)} | Remove-WmiObject\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2018-09-28T10:17:32.000Z","url":"https://community.spiceworks.com/t/deleting-a-user-profile-via-powershell-script/675781/11","author":{"@type":"Person","name":"tulioarends","url":"https://community.spiceworks.com/u/tulioarends"}},{"@type":"Answer","text":"I’ve found that you actually also need to tell powershell to start an admin session, even if you are an admin, to delete a user profile with it. It would be helpful to get an error log.<\/p>","upvoteCount":1,"datePublished":"2018-09-28T12:49:05.000Z","url":"https://community.spiceworks.com/t/deleting-a-user-profile-via-powershell-script/675781/12","author":{"@type":"Person","name":"aileencjr","url":"https://community.spiceworks.com/u/aileencjr"}}]}}
Neally
(Neally)
September 27, 2018, 7:44pm
2
Welcome!
If you post code, please use the insert code button! Please and thank you!
Hi, and welcome to the PowerShell forum!
Don’t apologize for being a “noob” or “newbie” or “n00b.” There’s just no need – nobody will think you’re stupid, and the forums are all about asking questions. Just ask!
Use a descriptive subject. Don't say "Need help" or "PowerShell Help", actually summarize what the problem is. It helps the rest of us keep track of which problem is which.
Don’t post massive scripts. We’re all volunteers and we don’t have time to read all that, nor will we copy, past…