PowerShell Enable Disable Delete

<#

.Synopsis
    Command to Enabled / Disable Local Account from Machine/s

.DESCRIPTION    
    Gets input from file and Enables / Disables local Account

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

    Header--> Server,Account
    Data  --> Servername1,TestAccount

    Update Syntax as Needed:
    /active:yes
    /active:no 
            
#>

  
  # Import List of Computers and Accounts  
  $MyData=Import-CSV C:\TEMP\Enable_LocalAccount.csv
  
  # Command to enable local computer account 
  $MyCommand={
  
      Net User $Args /active:yes 
      Get-WMIObject Win32_UserAccount -Filter "Name='$Args'" | Select Caption, Disabled
  
  }
  
  # Loop through records 
  Foreach($Computer in $MyData){
      # Executes command on machines from file
      Invoke-Command $Computer.Server -ScriptBlock $MyCommand -ArgumentList $Computer.Account | Format-Table | Out-File C:\temp\MyFile.csv -Append
  }
  
  
        

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