PoshCode Logo PowerShell Code Repository

Bulk Delprof by AlphaSun 12 months ago
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/6296"></script>download | new post

This script provides a way to bulk delete profiles on a system. Utilizes the Delprof2.exe program.

As configured below, the script will only LIST accounts in a “WhatIf” style. To actually perform the Delprof, remove the comment on Line 14.

  1. # Prompt for Search String
  2. $Input = Read-Host      'Dot-sourced path to input file (eg .\Targets.txt)'
  3. Write-Host              ' '
  4. Write-Host              'Wildcard characters * and ? can be used in the pattern'
  5. Write-Host              ' '
  6. $Include = Read-Host    'Include profiles that match this naming pattern'
  7. $Exclude = Read-Host    'Exclude profiles that match this naming pattern'
  8.  
  9. $Date = Get-Date -Format yyyyMMdd.hhmm
  10. $Targets = Get-Content $Input
  11. foreach ($target in $Targets) {
  12.  
  13.         delprof2 /l /c:\\$target /ed:$Exclude /id:$Include >> .\Delprof_$Date.log       ## LIST profiles
  14.         # delprof2 /c:\\$target /ed:$Exclude /id:$Include >> .\Delprof_$Date.log        ## REMOVE profiles
  15. }
  16.  
  17. # Wait for user acknowledgement
  18. Write-Host -NoNewLine "Press any key to continue..."
  19. $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me