troubleshooting Question

deleting profiles while skipping admin

Avatar of ivan rosa
ivan rosaFlag for United States of America asked on
PowershellWindows BatchScripting Languages
10 Comments1 Solution244 ViewsLast Modified:
Hello folks,
i have created the following script to remove profiles from PCs, however what change would i make to skip the administrator profile?

$CLIENT = Get-Content "c:\Temp\computers.txt"
foreach($PC in $CLIENT){
    # Testing PC connectivity
    if(Test-Connection $PC -Count 1 -Quiet){
        # Gathering users from c:\users
        foreach($PCuser in (Get-ChildItem "\\$pc\c$\users" -Directory)){
            # delete  recursively
            RD "\\$PC\c$\Users\$($\Desktop\*.*"
            RD "\\$PC\c$\Users\$($\Downloads\*.*"
            RD "\\$PC\c$\Users\$($\Documents\*.*"
            RD "\\$PC\c$\Users\$($\Music\*.*"
            RD "\\$PC\c$\Users\$($\Pictures\*.*"
            RD "\\$PC\c$\Users\$($\Videos\*.*"
        Write-Warning "$PC is offline"

or if anybody has a a batch that'd be great too

Thanks for looking
ivan rosa

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 10 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros