如何在GPO中运行powershell脚本来更改Windows管理员密码?

问题描述 投票:0回答:0

我有一个包含 Samba 4 的域。我使用装有 Windows 10 和 RSAT 的工作站来管理它。

我想创建一个 GPO 来更改 Windows 管理员用户密码。

创建以下脚本。在 Windows 10 计算机上运行它,我能够更改密码。然后我创建了一个GPO在域计算机启动时执行,但它不起作用。

脚本:

# Save current execution policy
$currentExecutionPolicy = Get-ExecutionPolicy

# Temporarily disable execution policy (make it possible to run scripts)
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

# Set the local Administrator user path
$computer = "."
$adminUser = [ADSI]"WinNT://$computer/Administrator,user"

# Set a new password that will be assigned to the local Administrator user
$newPassword = "mypassword"

# Attempting to change the local Administrator user password
try {
    $adminUser.SetPassword($newPassword)
    $adminUser.SetInfo()
    Write-Host "Local Administrator user password has been successfully changed!"
    Start-Sleep -Seconds 5
} catch {
    Write-Host "An error occurred while changing the Administrator user password: $_"
    Start-Sleep -Seconds 5
    
}

# Restore the original execution policy
Set-ExecutionPolicy -Scope Process -ExecutionPolicy $currentExecutionPolicy
powershell samba gpo
© www.soinside.com 2019 - 2024. All rights reserved.