Home » PowerShell » Powershell: Add Domain User To Local Admin Grp Output In Text File

Powershell: Add Domain User To Local Admin Grp Output In Text File


By This Powershell Script You Can Add a Domain User to the local Administrators group on the local or a remote computer. You can change the computer.txt and user.txt file path. You have to specify computer name in the computer.txt and domain user id into user.txt which you would like to add into Local Administrator Group.

This Script will generate a Result output file in .txt format on C: Drive


###########################################################################
#
# NAME: Add Domain User To Local Admin Grp Output In Text File
#
# AUTHOR: J.Malek (www.malekjakir.com) Email: malek dot one zero four zero at gmail dot com
#
#
###########################################################################

$computerName = Get-Content c:\computer.txt
$userName = Get-Content c:\user.txt
if (!$computerName) {$comutperName = “$env:computername”}
[string]$domainName = ([ADSI]”).name
foreach($comp in $computerName)
{
foreach($user in $userName)
{
try{
([ADSI]“WinNT://$comp/Administrators,group”).Add(“WinNT://$domainName/$user”)
Write-Host
“User $domainName\$user is now local administrator on $comp.” | Out-file -Append C:\Result.txt
}
catch {“Error – $_” | Out-File -Append C:\Error.txt}
}
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: