Home > database >  Batch script to delete Computer Objects from the ARS portal
Batch script to delete Computer Objects from the ARS portal

Time:05-02

I used the below script to delete bulk users from the ARS portal [Dell Active Roles]

Connect-QADService  -Proxy -Credential (Get-Credential)
Import-Csv "C:\IT\DeleteUser.csv" | foreach{Remove-QADObject $_.UserPrincipalName}

I have modified the above script like in below to remove computer objects but it gives the below error.

@echo off
powershell.exe Connect-QADService  -Proxy -Credential (Get-Credential) Import-Csv "C:\IT\Computer.csv" | foreach{Remove-QADObject $_.HostName}

Is it possible to eliminate the prompt for credentials from the above command?

Error:

PS C:\> Connect-QADService  -Proxy -Credential (Get-Credential) Import-Csv "C:\IT\Computers.csv" | foreach{Remove-QADComputer $_.HostName}

cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
Credential
Connect-QADService : A positional parameter cannot be found that accepts argument 'C:\IT\Computers.csv'.
At line:1 char:1
  Connect-QADService  -Proxy -Credential (Get-Credential) Import-Csv "C ...
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      CategoryInfo          : InvalidArgument: (:) [Connect-QADService], ParameterBindingException
      FullyQualifiedErrorId : PositionalParameterNotFound,ActiveRoles.ManagementShell.Commands.ConnectCmdlet

Error while changing it to ADComputer:

PS C:\> Connect-QADService  -Proxy -Credential (Get-Credential) Import-Csv "C:\IT\Computers.csv" | foreach{Remove-ADComputer $_.HostName}

cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
Credential
Connect-QADService : A positional parameter cannot be found that accepts argument 'C:\IT\Computers.csv'.
At line:1 char:1
  Connect-QADService  -Proxy -Credential (Get-Credential) Import-Csv "C ...
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      CategoryInfo          : InvalidArgument: (:) [Connect-QADService], ParameterBindingException
      FullyQualifiedErrorId : PositionalParameterNotFound,ActiveRoles.ManagementShell.Commands.ConnectCmdlet

Computers.csv contains

Hostname
A00001
A00002
A00003
B00001
C01241

CodePudding user response:

You are trying to use the command import-csv in the middle of the call to Connect-QADService. Note how all of the other parameters have been passed in with a - e.g. -proxy

I doubt the command Connect-QADService has a parameter of -import-csv

You want the Connect, and the import commands to be seperated. If you need it all in one line and running from CMD for what ever reason, try this:

@echo off 
powershell.exe "Connect-QADService -Proxy -Credential (Get-Credential); Import-Csv 'C:\IT\Computer.csv' | foreach { Remove-QADObject $_.HostName }"

(note the semi-colon depicting the end of the Connect-QADService command before we run the import)

CodePudding user response:

@echo off powershell.exe "Connect-QADService -Proxy -Credential (Get-Credential); Import-Csv 'C:\IT\Computer.csv' | foreach { Remove-QADObject $_.HostName -force }"

  • Related