Hi,
I'm trying to write a script which add user to local admin group.
The problem is that I have user who are based in Poland, chain and so on.
The current script I have works well if the user are in UK because local group is called Administrators but in Poland letters change.
What I like to do is create a global script which will work on any language OS.
This is what I have tried.
functionPing-Machine {
param ($computerName=".");
$result=Test-Connection-ComputerName$computerName-Quiet-Count1;
if ($result-eq"True"){return$true;}
return$false; }
[string]$domainName= ([ADSI]'').name;
$localGroupName
='Administrators'
;
$computerName
=Read-Host'Enter computer name or press <Enter> for localhost'
;
if
(Ping-Machine$computerName
) {
$userName=Read-Host ('Please enter User ID'
);
$computer=[ADSI]"WinNT://$computerName, computer"
;
$computer.psbase.Children |Where-Object { $_.psbase.schemaClassName -eq'group' } |ForEach-Object
{
$objUser=New-ObjectSystem.Security.Principal.NTAccount($_.name) -ErrorActionSilentlyContinue
;
$strSID=$objUser.Translate([System.Security.Principal.SecurityIdentifier]
);
if($strSID.Value -eq"S-1-5-32-544"
) {
$localGroupName=$_.
name;
#continue;
}
$strSID.Value =''
; }
$UserAdd= ([ADSI]"WinNT://$computerName/$localGroupName,group").Invoke('Add',"WinNT://$userDomain/$userName"
);
Write-Host"User have been added into local admin group"-ForegroundColor
Green
}
else
{
Write-Warning"$computerName is turned off"
;