{"componentChunkName":"component---src-templates-articles-index-jsx","path":"/articles/powershell-manage-user-profiles/","result":{"data":{"props":{"adsense":true,"adsenseMobile":null,"byLine":"","canonical":"https://staging.business.com/articles/powershell-manage-user-profiles/","content":"<p>A common pain point in an IT administrator's career is managing user profiles. User profiles are a ubiquitous part of a Windows IT pro's life—especially those that manage virtual desktop environments like Remote Desktop Services (RDS).</p>\n<p><picture class=\"aligncenter full\">IT pros have to deal with corrupted user registry hives and files that need to be shared across all user profiles; they also need to figure out how to recreate corrupt profiles and so on. </picture><br><picture class=\"aligncenter full\"><source srcset=\"/images/content/5b6/bc52a1039eb861a8b4598/1200_-900- 1200w, /images/content/5b6/bc52a1039eb861a8b4598/668_-501- 668w, /images/content/5b6/bc52a1039eb861a8b4598/320_-240- 320w\" sizes=\"668px, 100%\"></source></picture><br>What was once a frustrating experience has gotten a little less frustrating with PowerShell. Here are a few ways that PowerShell can make managing Windows user profiles easier.</p>\r\n<h2>Enumerating User Profiles</h2>\r\n<p>It's easy to take a peek at user profiles on the file system on a single Windows computer. Simply look in the <strong>C:Users</strong> folder. However, when you do this not only are you not getting the full picture, it's also troublesome due to potential file system access problems. There's a better way and that's through WMI.  <br><br>In WMI, a class exists called <strong>Win32_UserProfile</strong>. This class contains all of the profiles that exist on a machine and lots of other useful information that a simple file system folder won't show you.</p>\r\n<p>Using PowerShell you can access this WMI class with the <strong>Get-CimInstance</strong> or <strong>Get-WmiObject</strong> cmdlets. In Figure 1 below, we're finding the first user profile on the local computer. You'll notice many useful tidbits of information like LastUseTime, SID and from here, you can also drill down further and get specific paths like Desktop, Documents, Favorites, etc.</p>\r\n<p><picture class=\"aligncenter full\"><source srcset=\"/images/content/5b6/bc65d92a3a4da668b4589/1200_-721- 1200w, /images/content/5b6/bc65d92a3a4da668b4589/668_-401- 668w, /images/content/5b6/bc65d92a3a4da668b4589/320_-192- 320w\" sizes=\"668px, 100%\"></source><img src=\"/images/content/5b6/bc65d92a3a4da668b4589/900-541-\" alt=\"\" width=\"900\" height=\"541\" data-content-img-id=\"5b6bc65d92a3a4da668b4589\"></picture></p>\r\n<p>Since this is part of WMI, we can easily extend this from a single computer to many computers using the <strong>ComputerName</strong> parameter. In order to be compatible with down-level operating systems, we can use the Get-WmiObject cmdlet here to enumerate user profiles on the MEMBERSRV1 and CLIENT2 computers.</p>\r\n<blockquote>Get-WmiObject -Class Win32_UserProfile -ComputerName 'MEMBERSRV1','CLIENT2'<br><br>\n</blockquote>\r\n<h2>Removing User Profiles</h2>\r\n<p>Another common task when managing user profiles is removing them. I can't count how many times I've had to remove user profiles because something got corrupted and I just needed the user to log in again and recreate it. At one time, I would simply have the user log off and remove the C:Users&lt;UserName&gt; folder from the file system. Usually it works, sometimes it doesn't. What I didn't realize was that I was actually leaving some remnants behind. The proper way to do this—and the easier way—is to initiate a removal via WMI.</p>\r\n<p>Using the same WMI class we just went over, it's possible to not only just view profiles but I can completely remove them as well. This is the same as going into the User Profiles box under System settings and hitting the Delete button.</p>\r\n<p><picture class=\"aligncenter med\"><source srcset=\"/images/content/5b6/bc6a192a3a4de668b4583/742_-780- 742w, /images/content/5b6/bc6a192a3a4de668b4583/412_-433- 412w, /images/content/5b6/bc6a192a3a4de668b4583/206_-216- 206w\" sizes=\"(min-width: 870px) 412px, (min-width: 400px) 38vw, 62%\"></source><img src=\"/images/content/5b6/bc6a192a3a4de668b4583/410-431-\" alt=\"\" width=\"410\" height=\"431\" data-content-img-id=\"5b6bc6a192a3a4de668b4583\"></picture></p>\r\n<p>To do this, I'll enumerate the user profiles again and this time apply a filter to pick a single user profile to remove. In this case, I'd like to remove the user profile called Administrator.CLIENT1. I can do this by using PowerShell's <strong>Where-Object</strong> cmdlet and some string manipulation to grab the user folder name from the LocalPath property—that section is shown below in bold.</p>\r\n<blockquote>Get-WmiObject -Class Win32_UserProfile | <strong>where {$_.LocalPath.split('')[-1] -eq 'Administrator.CLIENT1'}</strong> | foreach {$_.Delete()}<br><br>\n</blockquote>\r\n<p>Once I'm able to narrow down that single profile I can then call the <strong>Delete()</strong> method for each object that Get-WmiObject outputs—in this case only 1—which will then remove the user profile from the file system as well as the registry.</p>\r\n<blockquote>Get-WmiObject -Class Win32_UserProfile | where {$_.LocalPath.split('')[-1] -eq 'Administrator.CLIENT1'} <strong>| foreach {$_.Delete()}<br><br></strong>\n</blockquote>\r\n<p>Again, if you'd like to extend this to multiple computers you'd simply use the –ComputerName parameter on Get-WmiObject.</p>\r\n<blockquote>Get-WmiObject -Class Win32_UserProfile –ComputerName CLIENT1,CLIENT2 | where {$_.LocalPath.split('')[-1] -eq 'Administrator.CLIENT1'} | foreach {$_.Delete()}<br><br>\n</blockquote>\r\n<h2>Use WMI, Not The File System</h2>\r\n<p>You've now seen an easy way to enumerate and remove Windows user profiles. If you weren't aware of the WMI class <strong>Win32_UserProfile</strong> you may have been correlating the C:Users&lt;Username&gt; folder as the profile. Now you can see there's much more to the user profile than a simple file system folder. Use WMI the next time you need to query or remove user profiles from computers in your environment.</p>\n","docType":"article","guid":"articles_66f327c539dfb7e8ee58b1aaf054919d","lastModified":"2018-09-06T07:00:00.000Z","published":"2018-09-06T07:00:00.000Z","structuredData":null,"subtitle":"Managing Windows user profiles can be time consuming and tedious. Here are some tips.","template":"v1","title":"How To Manage User Profiles With PowerShell","type":"article","author":{"avatar":null,"bio":"Adam Bertram is a 20-year veteran of IT and experienced online business professional. He's an entrepreneur, IT influencer, Microsoft MVP, blogger, trainer and content marketing writer for multiple technology companies. Adam is also the founder of the popular IT career development platform TechSnips. Catch up on Adam's articles at adamtheautomator.com, connect on LinkedIn, or follow him on Twitter at @adbertram or the TechSnips Twitter account at @techsnips_io.","name":"Adam Bertram","image":null,"slug":null,"social":{"facebook":"","linkedin":"https://www.linkedin.com/in/adambertram/","twitter":"https://twitter.com/adbertram","website":"https://www.adamtheautomator.com/"},"status":"enabled","title":null,"type":"Contributing Writer","user":{"imagePath":"https://staging.business.com/images/undefined","profile":{"company":"eGain Communications","jobTitle":"Product Management Analyst","website":""}}},"breadcrumbs":null,"channels":{"primary":{"name":"Technology","slug":"technology"},"sub":{"name":"Technology Solutions","slug":"technology-solutions"}},"meta":{"robots":"index, follow","description":"Managing Windows user profiles can be time consuming and tedious. Here are some tips on how to leverage PowerShell.","title":"Manage Windows User Profiles With PowerShell - How To - business.com"},"parsedContent":{"toc":[{"id":"enumerating-user-profiles","title":"Enumerating User Profiles"},{"id":"removing-user-profiles","title":"Removing User Profiles"},{"id":"use-wmi,-not-the-file-system","title":"Use WMI, Not The File System"}],"json":[{"component":"p","children":["A common pain point in an IT administrator's career is managing user profiles. User profiles are a ubiquitous part of a Windows IT pro's life—especially those that manage virtual desktop environments like Remote Desktop Services (RDS)."]},{"component":"p","children":[{"component":"picture","props":{"className":"aligncenter full"},"children":["IT pros have to deal with corrupted user registry hives and files that need to be shared across all user profiles; they also need to figure out how to recreate corrupt profiles and so on. "]},{"component":"br"},{"component":"picture","props":{"className":"aligncenter full"},"children":[{"component":"source","props":{"srcSet":"/images/content/5b6/bc52a1039eb861a8b4598/1200_-900- 1200w, /images/content/5b6/bc52a1039eb861a8b4598/668_-501- 668w, /images/content/5b6/bc52a1039eb861a8b4598/320_-240- 320w","sizes":"668px, 100%"}}]},{"component":"br"},"What was once a frustrating experience has gotten a little less frustrating with PowerShell. Here are a few ways that PowerShell can make managing Windows user profiles easier."]},{"component":"h2","props":{"id":"enumerating-user-profiles"},"children":["Enumerating User Profiles"]},{"component":"p","children":["It's easy to take a peek at user profiles on the file system on a single Windows computer. Simply look in the ",{"component":"strong","children":["C:Users"]}," folder. However, when you do this not only are you not getting the full picture, it's also troublesome due to potential file system access problems. There's a better way and that's through WMI.  ",{"component":"br"},{"component":"br"},"In WMI, a class exists called ",{"component":"strong","children":["Win32_UserProfile"]},". This class contains all of the profiles that exist on a machine and lots of other useful information that a simple file system folder won't show you."]},{"component":"p","children":["Using PowerShell you can access this WMI class with the ",{"component":"strong","children":["Get-CimInstance"]}," or ",{"component":"strong","children":["Get-WmiObject"]}," cmdlets. In Figure 1 below, we're finding the first user profile on the local computer. You'll notice many useful tidbits of information like LastUseTime, SID and from here, you can also drill down further and get specific paths like Desktop, Documents, Favorites, etc."]},{"component":"p","children":[{"component":"picture","props":{"className":"aligncenter full"},"children":[{"component":"source","props":{"srcSet":"/images/content/5b6/bc65d92a3a4da668b4589/1200_-721- 1200w, /images/content/5b6/bc65d92a3a4da668b4589/668_-401- 668w, /images/content/5b6/bc65d92a3a4da668b4589/320_-192- 320w","sizes":"668px, 100%"}},{"component":"img","props":{"src":"/images/content/5b6/bc65d92a3a4da668b4589/900-541-","alt":"","width":"900","height":"541","data-content-img-id":"5b6bc65d92a3a4da668b4589"}}]}]},{"component":"p","children":["Since this is part of WMI, we can easily extend this from a single computer to many computers using the ",{"component":"strong","children":["ComputerName"]}," parameter. In order to be compatible with down-level operating systems, we can use the Get-WmiObject cmdlet here to enumerate user profiles on the MEMBERSRV1 and CLIENT2 computers."]},{"component":"blockquote","children":["Get-WmiObject -Class Win32_UserProfile -ComputerName 'MEMBERSRV1','CLIENT2'",{"component":"br"},{"component":"br"}]},{"component":"h2","props":{"id":"removing-user-profiles"},"children":["Removing User Profiles"]},{"component":"p","children":["Another common task when managing user profiles is removing them. I can't count how many times I've had to remove user profiles because something got corrupted and I just needed the user to log in again and recreate it. At one time, I would simply have the user log off and remove the C:Users<UserName> folder from the file system. Usually it works, sometimes it doesn't. What I didn't realize was that I was actually leaving some remnants behind. The proper way to do this—and the easier way—is to initiate a removal via WMI."]},{"component":"p","children":["Using the same WMI class we just went over, it's possible to not only just view profiles but I can completely remove them as well. This is the same as going into the User Profiles box under System settings and hitting the Delete button."]},{"component":"p","children":[{"component":"picture","props":{"className":"aligncenter med"},"children":[{"component":"source","props":{"srcSet":"/images/content/5b6/bc6a192a3a4de668b4583/742_-780- 742w, /images/content/5b6/bc6a192a3a4de668b4583/412_-433- 412w, /images/content/5b6/bc6a192a3a4de668b4583/206_-216- 206w","sizes":"(min-width: 870px) 412px, (min-width: 400px) 38vw, 62%"}},{"component":"img","props":{"src":"/images/content/5b6/bc6a192a3a4de668b4583/410-431-","alt":"","width":"410","height":"431","data-content-img-id":"5b6bc6a192a3a4de668b4583"}}]}]},{"component":"p","children":["To do this, I'll enumerate the user profiles again and this time apply a filter to pick a single user profile to remove. In this case, I'd like to remove the user profile called Administrator.CLIENT1. I can do this by using PowerShell's ",{"component":"strong","children":["Where-Object"]}," cmdlet and some string manipulation to grab the user folder name from the LocalPath property—that section is shown below in bold."]},{"component":"blockquote","children":["Get-WmiObject -Class Win32_UserProfile | ",{"component":"strong","children":["where {$_.LocalPath.split('')[-1] -eq 'Administrator.CLIENT1'}"]}," | foreach {$_.Delete()}",{"component":"br"},{"component":"br"}]},{"component":"p","children":["Once I'm able to narrow down that single profile I can then call the ",{"component":"strong","children":["Delete()"]}," method for each object that Get-WmiObject outputs—in this case only 1—which will then remove the user profile from the file system as well as the registry."]},{"component":"blockquote","children":["Get-WmiObject -Class Win32_UserProfile | where {$_.LocalPath.split('')[-1] -eq 'Administrator.CLIENT1'} ",{"component":"strong","children":["| foreach {$_.Delete()}",{"component":"br"},{"component":"br"}]}]},{"component":"p","children":["Again, if you'd like to extend this to multiple computers you'd simply use the –ComputerName parameter on Get-WmiObject."]},{"component":"blockquote","children":["Get-WmiObject -Class Win32_UserProfile –ComputerName CLIENT1,CLIENT2 | where {$_.LocalPath.split('')[-1] -eq 'Administrator.CLIENT1'} | foreach {$_.Delete()}",{"component":"br"},{"component":"br"}]},{"component":"h2","props":{"id":"use-wmi,-not-the-file-system"},"children":["Use WMI, Not The File System"]},{"component":"p","children":["You've now seen an easy way to enumerate and remove Windows user profiles. If you weren't aware of the WMI class ",{"component":"strong","children":["Win32_UserProfile"]}," you may have been correlating the C:Users<Username> folder as the profile. Now you can see there's much more to the user profile than a simple file system folder. Use WMI the next time you need to query or remove user profiles from computers in your environment."]}]},"resource":null,"sponsorship":null,"thumbnail":{"path":"https://staging.business.com/images/content/5cf/ffdf07b4374ac348b4576/1500-0-","caption":"Undrey/Shutterstock","isBlurred":false},"bestPicks":null},"related":{"relatedArticles":[{"title":"PowerShell: Everything You Need to Know","canonical":"https://www.business.com/articles/powershell-everything-you-need-to-know/","slug":"powershell-everything-you-need-to-know","thumbnail":"https://www.business.com/images/content/5b8/998581039eb8f738b457b/1500-0-","dek":"What you need to know to unlock Microsoft PowerShell's full capabilities.","lastModified":"2018-09-05T17:00:00Z","published":"2018-09-05T17:00:00Z","sponsored":false},{"title":"Essential PowerShell Cmdlets For Auditing And Maintaining Storage","canonical":"https://www.business.com/articles/powershell-for-storage/","slug":"powershell-for-storage","thumbnail":"https://www.business.com/images/content/5d0/18e065a215ea2498b4588/1500-0-","dek":"PowerShell v5 offers some new features for managing storage.","lastModified":"2018-09-04T11:00:00Z","published":"2018-09-04T11:00:00Z","sponsored":false},{"title":"Essential PowerShell Cmdlets For Managing Active Directory","canonical":"https://www.business.com/articles/powershell-active-directory-cmdlets/","slug":"powershell-active-directory-cmdlets","thumbnail":"https://www.business.com/images/content/5cf/90cab7b4374ab068b456f/1500-0-","dek":"Administering Active Directory is one of the most critical roles in any Windows network.","lastModified":"2018-09-04T08:00:00Z","published":"2018-09-04T08:00:00Z","sponsored":false},{"title":"How and When to Create and Use PowerShell Modules","canonical":"https://www.business.com/articles/powershell-modules/","slug":"powershell-modules","thumbnail":"https://www.business.com/images/content/5cf/a71415a215e501f8b457a/1500-0-","dek":"Step-by-step instructions on creating and using modules.","lastModified":"2018-09-05T08:00:00Z","published":"2018-09-05T08:00:00Z","sponsored":false},{"title":"How to Create a Web Scraping Tool in PowerShell","canonical":"https://www.business.com/articles/create-web-scraping-tool-in-powershell/","slug":"create-web-scraping-tool-in-powershell","thumbnail":"https://www.business.com/images/content/5d0/06c899c658acc288b458a/1500-0-","dek":"Write a tool in PowerShell that will gather all the data from a web page.","lastModified":"2018-09-05T09:00:00Z","published":"2018-09-05T09:00:00Z","sponsored":false},{"title":"Microsoft Azure vs. Amazon Web Services: Cloud Comparison","canonical":"https://www.business.com/articles/azure-vs-aws-cloud-comparison/","slug":"azure-vs-aws-cloud-comparison","thumbnail":"https://www.business.com/images/content/5cf/ff3445a215ed86a8b459d/1500-0-","dek":"Which one is right for your business?","lastModified":"2018-05-25T07:00:00Z","published":"2018-05-25T07:00:00Z","sponsored":false},{"title":"From COVID-19 to Hurricane Season: Disaster Preparedness for Small Business","canonical":"https://www.business.com/articles/business-disaster-prep/","slug":"business-disaster-prep","thumbnail":"https://www.business.com/images/content/5e7/a495e5a215eb11d8b4569/1500-0-","dek":"Natural disasters – whether a hurricane, tornado or outbreak like COVID-19 – can have a disastrous effect on small businesses, but they don't have to. Here's how to weather a disaster successfully.","lastModified":"2020-03-25T15:19:00Z","published":"2018-09-26T07:00:00Z","sponsored":false},{"title":"How To Manage IIS Application Pools With PowerShell","canonical":"https://www.business.com/articles/powershell-manage-iis-application-pools/","slug":"powershell-manage-iis-application-pools","thumbnail":"https://www.business.com/images/content/5d0/0067d5a215edb1a8b4585/1500-0-","dek":"Where you turn when you're managing an IIS web server. farm with potentially dozens or h","lastModified":"2018-09-06T08:00:00Z","published":"2018-09-06T08:00:00Z","sponsored":false},{"title":"Use PowerShell to Make WSUS Suck Less","canonical":"https://www.business.com/articles/powershell-windows-software-update-services/","slug":"powershell-windows-software-update-services","thumbnail":"https://www.business.com/images/content/5b8/eca2d92a3a4ee5a8b4574/1500-0-","dek":"Windows Software Update Services can use PowerShell to work with servers and Windows.","lastModified":"2018-09-04T10:00:00Z","published":"2018-09-04T10:00:00Z","sponsored":false},{"title":"How to Manage File System ACLs with PowerShell","canonical":"https://www.business.com/articles/powershell-manage-file-system-acl/","slug":"powershell-manage-file-system-acl","thumbnail":"https://www.business.com/images/content/5cf/9f88e7b437486498b4568/1500-0-","dek":"Adjusting permissions on thousands of folders can be time consuming without PowerShell.","lastModified":"2018-09-05T11:00:00Z","published":"2018-09-05T11:00:00Z","sponsored":false},{"title":"How To Remove Pre-Installed Windows 10 Applications With PowerShell","canonical":"https://www.business.com/articles/remove-pre-installed-windows-10-applications-powershell/","slug":"remove-pre-installed-windows-10-applications-powershell","thumbnail":"https://www.business.com/images/content/5d0/b99037b4374d0428b4567/1500-0-","dek":"How to quickly and easily uninstall pre-installed Windows 10 apps using PowerShell.","lastModified":"2018-09-05T08:00:00Z","published":"2018-09-05T08:00:00Z","sponsored":false},{"title":"Your Guide to Creating a Small Business Marketing Plan","canonical":"https://www.business.com/articles/sample-marketing-plan-outline-and-template/","slug":"sample-marketing-plan-outline-and-template","thumbnail":"https://www.business.com/images/content/5f3/3e1765a215eb62d8b4567/1500-0-","dek":"Follow these templates and guidelines to get started on creating your business's marketing plan.","lastModified":"2020-08-12T12:28:00Z","published":"2018-03-02T13:00:00Z","sponsored":false}],"relatedReviews":[{"doc_type":"category","thumbnail":"https://staging.business.com/images/rz/5df908cc5a215e8c4a8b4568/conferencecall_Antonio_Diaz_Getty.jpg","canonical":"https://staging.business.com/categories/best-conference-call-services/","title":"The Best Conference Call Services of 2021","dek":"Which conference call service is right for your business in 2021? We review the top-rated services.","slug":"best-conference-call-services","lastModified":"2021-03-17T18:17:00Z"},{"doc_type":"category","thumbnail":"https://staging.business.com/images/rz/5df3d8695a215e58428b4570/POS_GETTY_DERO2084.jpg","canonical":"https://staging.business.com/categories/best-pos-systems/","title":"The Best POS Systems of 2021","dek":"Before you choose a POS system, check out our reviews of the best picks for 2021. ","slug":"best-pos-systems","lastModified":"2021-03-17T17:33:00Z"},{"doc_type":"category","thumbnail":"https://staging.business.com/images/rz/5e00d4787b43745d6a8b456e/Laptop_undrey_getty.jpg","canonical":"https://staging.business.com/categories/employee-monitoring-software/","title":"The Best Employee Monitoring Software of 2021","dek":"We've narrowed down the best employee monitoring software for businesses. Check out our best picks and reviews.","slug":"employee-monitoring-software","lastModified":"2021-03-05T15:40:00Z"}],"relatedSponsoredArticles":null}},"pageContext":{"displayModified":"2018-09-06T07:00:00.000Z","template":"v1","title":"How To Manage User Profiles With PowerShell","meta":{"robots":"index, follow"},"docType":"articles","slug":"powershell-manage-user-profiles","canonical":"https://staging.business.com/articles/powershell-manage-user-profiles/","skipTOC":false}},"staticQueryHashes":[]}