Jump to content

Recommended Posts

Posted

Hi, I got this profiles delete script from EduGeek to run at startup, and it works but it sometimes seems to hang deleting some profiles, reboot and those left over profiles disappear. It's all a bit wrong, lots of red Powershell warnings.

 

can someone please advise:

 

 

 

$profiles = $null

$profiles = Get-WMIObject -class Win32_UserProfile | Where {((!$_.Special) -and ($_.LocalPath -ne "C:\Users\Administrator") -and ($_.LocalPath -ne "C:\Users\Public") -and ($_.LocalPath -ne "C:\Users\Default"))}

if ($profiles -ne $null) {

$profiles | Remove-WmiObject

}

 

Exit

 

 

 

powershell error attached that appears many many times at startup..

 

 

screen.jpg

Posted

Some problems here, you can't delete profiles using Remove-WmiObject, you need to call the delete method.

 

Get-WMIObject -Class Win32_UserProfile | Where-Object { $_.Special -ine "True"  -and $_.LocalPath -ine "C:\Users\Administrator" -and $_.LocalPath -ine "C:\Users\Public" -and $_.LocalPath -ine "C:\Users\Default"} | ForEach-Object { $_.Delete() }

 

If you want something more complete, I wrote a profile management routine in our startup script that removes student profiles, mandatory, corrupt and temporary profiles, but leaves staff profiles intact. It also uses a AD variable to allow you to purge specific profiles across the network for when roaming profiles need resetting.

You can find it here: http://www.edugeek.net/forums/windows-10/204731-script-deleting-user-profiles-folders.html#post1748036

Posted

Thanks Chris I get:

 

Exception calling "Delete" with "0" argument(s): ""

At line:1 char:304

+ ... _.LocalPath -ine "C:\Users\Default"} | ForEach-Object { $_.Delete() }

+ ~~~~~~~~~~~

+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException

+ FullyQualifiedErrorId : DotNetMethodException

 

when running that command in the code block of your message.

Posted
Thanks Chris I get:

 

Exception calling "Delete" with "0" argument(s): ""

At line:1 char:304

+ ... _.LocalPath -ine "C:\Users\Default"} | ForEach-Object { $_.Delete() }

+ ~~~~~~~~~~~

+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException

+ FullyQualifiedErrorId : DotNetMethodException

 

when running that command in the code block of your message.

 

That could happen if you are not running PowerShell or the ISE as Administrator, deleting profiles requires elevated permissions. It may also be trying to delete a profile that is in use (yours for example) so you may want to add a check for that:

 

Get-WMIObject -Class Win32_UserProfile | Where-Object { $_.Loaded -ine "True" -and $_.Special -ine "True"  -and $_.LocalPath -ine "C:\Users\Administrator" -and $_.LocalPath -ine "C:\Users\Public" -and $_.LocalPath -ine "C:\Users\Default"} | ForEach-Object { $_.Delete() }

Posted
If you make the users members of Domain Guests in AD their profile is automatically cleared at log off, that's what i do for the students and it's worked well for me.
Posted
Group membership is a nice idea, it seems to remove the reg entry but leaves an (empty) folder in C:\users called 'username'.
Posted
The deletion is done by windows, if it leaves a folder it'll be because theres open file locks. Do profile cleaning after a fresh reboot (in the startup script ideally) to avoid this.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...