title: Delete one local user account if another local adminstrator ID exist
body: <p>I have few numbers of server where "tempadmin" and "Administrator" are exist as local admin user. I need to delete "tempadmin" id if "Administrator" is also exist. else "tempadmin" needs to rename as "Administrator". Could anyone help me create one PowerShell script?</p>
  
  <pre><code>cls
  $strComputer = Get-Content "c:\patch\clientlist.txt"
  $password = Read-Host "Enter the password : " -AsSecureString
  
  foreach ($server in $strComputer) {
      Write-Host "Working on server $server"
      if (Test-Connection $server -Quiet) {
          $usertest1 = Get-WMIObject Win32_UserAccount -Filter "LocalAccount=True AND Name='test1'" -ComputerName $server
          if ($usertest1.name -ne 'test1') {
              $user = Get-WMIObject Win32_UserAccount -Filter "LocalAccount=True AND Name='test'" -ComputerName $server
              $result = $user.Rename('test1')
              if ($result.name -eq 'test') {
                  $result
                  # you may just print a message here
              }
              Write-host "$server -&gt; ID renamed and resetting password...."
  
              $user1 = Get-WMIObject Win32_UserAccount -Filter "LocalAccount=True AND Name='test1'" -ComputerName $server
              ([adsi]("WinNT://" + $server + "$user1")).SetPassword("$password")
              Write-Host "$server -&gt; Password reset successfully"
            } else {
              Write-Host "$server -&gt; Test1 ID already exist"
            }  
      } else {
          Write-Host "$server -&gt; server is not reachable"
      }
  }
  </code></pre>
  
  <p>Here I am user "test" and "test1". I tried the above code and I can successfully rename and reset the password. But I am unable to delete if both ID's are exist.</p>