Hi
the following Power Shell Script add the AD domain user to the local admin group on the client machine.
Here my script
>
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true,Position=1)]
[ValidateSet("User","Group")]
[String]
$ObjectType,
[Parameter(Mandatory=$true,Position=2)]
[ValidateScript({($_.split("\").count -eq 2)})]
[string]$ObjectName,
[Parameter(Position=3)]
[String[]]$ComputerName=$env:COMPUTERNAME
)
$ResultsFile = "c:\temp\result.csv"
$ObjDomain = $ObjectName.Split("\")[0]
$ObjName = $ObjectName.Split("\")[1]
$ComputerCount = $ComputerName.Count
$count = 0
Add-Content -Path $ResultsFile -Value "ComputerName,Status,Comments"
foreach($Computer in $ComputerName) {
$count++
$Status=$null
$Comment = $null
Write-Host ("{0}. Working on {1}" -f $Count, $Computer)
if(Test-Connection -ComputerName $Computer -Count 1 -Quiet) {
Write-Verbose "$Computer : Online"
try {
$GroupObj = [ADSI]"WinNT://$Computer/Administrators"
$GroupObj.Add("WinNT://$ObjDomain/$ObjName")
$Status = "Success"
$Comment = "Added $ObjectName $ObjectType to Local administrators group"
Write-Verbose "Successfully added $ObjectName $ObjectType to $Computer"
} catch {
$Status = "Failed"
$Comment = $_.toString().replace("`n","").replace("`r","")
Write-Verbose "Failed to add $ObjectName $ObjectType to $Computer"
}
Add-Content -Path $ResultsFile -Value ("{0},{1},{2}" -f $Computer,$Status,$Comment )
} else {
Write-Warning "$Computer : Offline"
Add-Content -Path $ResultsFile -Value ("{0},{1}" -f $Computer,"Offline")
}
}
I run that script with following command
AddocalAdminGroupMembers.ps1 -ObjectType User -ObjectName "domain\User" -ComputerName "test"
domain\user , I put here my domain and username and -ComputerName put here my client computer name
I have 100 different domain users and 100 different computers I have to add these to the local admin group, it means I have to run that script 100 times
My question is:
Is there anyway to add all username and computername in one step? for example with CSR file
Regards