Перейти к содержимому

Как cменить пароль локального администратора в домене на серверах через Powershell.

Получаем список серверов или пк

Get-ADComputer -filter * -SearchBase 'DC=adminbd,DC=adminbd,DC=ru' | select -ExpandProperty name | sc c:\comps.txt
Get-ADComputer -filter * -SearchBase 'DC=adminbd,DC=adminbd,DC=ru' | select -ExpandProperty name | sc c:\comps.txt
 
 
$computer = "c:\comps.txt"
foreach ($computerName in (Get-Content $computer))
{
If (Test-Connection -ComputerName $computerName -Count 2 -Quiet)
{
Write-Host "Пытаюсь проверить компьютер на пакеты ping";
Invoke-Command -ComputerName $computerName -ScriptBlock {
#$credential = Get-Credential -UserName "Администратор" -Message "Введите новый пароль";
$UserName="Admin"
$Password=convertto-securestring "пароль" -asplaintext -force
If ($UserName -eq $null)
{
Write-Warning "The username and/or the password is empty! I quit.";
Exit;
}
Set-LocalUser -Name $UserName -Password $Password;
}
} Else
{
Write-Warning "Компьютер не отвечает на Ping.";
}
}

Смена пароля на старых windows ниже 2016

#Get-ADComputer -filter * -SearchBase 'DC=adminbd,DC=adminbd,DC=ru' | select -ExpandProperty name | sc c:\comps.txt
 
 
$computer = "c:\comps.txt"
foreach ($computerName in (Get-Content $computer))
{
If (Test-Connection -ComputerName $computerName -Count 2 -Quiet)
{
Write-Host "Пытаюсь проверить компьютер на пакеты ping";
Invoke-Command -ComputerName $computerName -ScriptBlock {
#$credential = Get-Credential -UserName "Администратор" -Message "Введите новый пароль";
$UserName="Administrator"
#$Password=convertto-securestring "3<KksHhnG}59-<" -asplaintext -force
[adsi]$user = "WinNT://./Administrator";
[adsi]$localPC = "WinNT://."
#$localPC.Children | where {$_.Class -eq "user"} | ft name, description –auto
 
 
 
If ($UserName -eq $null)
{
Write-Warning "The username and/or the password is empty! I quit.";
Exit;
}
$user.SetPassword("пароль")
}
} Else
{
Write-Warning "Компьютер не отвечает на Ping.";
}
}

 

Similar Posts:

Метки:

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *