PowerShell Local Account Delete

<#

.Synopsis
    Command to remove local account from machine/s

.DESCRIPTION    
    Gets input from file and removes local account from machine

.EXAMPLE
    Run script with rights on machines
    Have correctly prepared CSV file for input

    Header--> Server,Account
    Data  --> Servername1,AccountToDelete
            
#>

  
  # Import List of Computers and Accounts  
  $MyData=Import-CSV C:\TEMP\Remove_LocalAccount.csv
  
  # Loop through records 
  Foreach($Computer in $MyData){   
  
      # Command to delete local computer account 
      $MyCommand={Net USER $Args /Delete}
  
      # Executes command on machines from file
      Invoke-Command $Computer.Server -ScriptBlock $MyCommand -ArgumentList $Computer.Account 
  }
   
  
        

2020 | Scott W. Head  |  Sr. Systems Admin | Certified Microsoft Windows Server Administrator