我的计算机不在域上,需要添加到域,重新启动,使用域帐户自动登录,然后在其上运行一些PowerShell脚本。
我有一个powershell,它使用域凭据编辑注册表,并使用runonce命令将其设置为登录一次。当我运行powershell时,它会正确编辑注册表,更改到正确的域,然后在等待10秒后重新启动计算机。当计算机重新联机并尝试登录时,它会给出一个"目前没有可用于处理登录请求的登录服务器"如果您输入帐户的域密码,则可以登录,然后运行runonce脚本。我想不必手动输入密码。
这是我目前正在使用的powershell代码。我使用的是powershell v1,因为所有的计算机都有它们,而且它们是Windows 7计算机。
Function Set-AutoLogon{
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
[String[]]$DefaultUsername,
[Parameter(Mandatory=$True,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
[String[]]$DefaultDomainName,
[Parameter(Mandatory=$True,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
[String[]]$DefaultPassword,
[Parameter(Mandatory=$False,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
[AllowEmptyString()]
[String[]]$AutoLogonCount,
[Parameter(Mandatory=$False,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
[AllowEmptyString()]
[String[]]$Script
)
Begin
{
#Registry path declaration
$RegPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
$RegROPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce"
}
Process
{
try
{
#setting registry values
Set-ItemProperty $RegPath "AutoAdminLogon" -Value "1" -type String
Set-ItemProperty $RegPath "DefaultUsername" -Value "$DefaultUsername" -type String
Set-ItemProperty $RegPath "DefaultDomainName" -Value "$DefaultDomainName" -type String
Set-ItemProperty $RegPath "DefaultPassword" -Value "$DefaultPassword" -type String
if($AutoLogonCount)
{
Set-ItemProperty $RegPath "AutoLogonCount" -Value "$AutoLogonCount" -type DWord
}
else
{
Set-ItemProperty $RegPath "AutoLogonCount" -Value "1" -type DWord
}
if($Script)
{
Set-ItemProperty $RegROPath "(Default)" -Value "$Script" -type String
}
else
{
Set-ItemProperty $RegROPath "(Default)" -Value "" -type String
}
}
catch
{
Write-Output "An error had occured $Error"
}
}
End
{
#End
}
}
Set-AutoLogon -DefaultUsername "user" -DefaultDomainName "domain.com" -DefaultPassword "password" -Script "C:\script.bat"
$domain = "domain.com"
$PlainPassword = "password"
$SecurePassword = $PlainPassword | ConvertTo-SecureString -AsPlainText -Force
$user = "user"
$username = "$domain\$user"
$credential = New-Object System.Management.Automation.PSCredential($username,$SecurePassword)
Add-Computer -DomainName $domain -Credential $credential | out-null
Start-Sleep -Seconds 10
restart-computer -force
如果您需要更多信息,请与我们联系 感谢您的帮助:D
答案 0 :(得分:-1)
似乎网络尚未准备就绪。
您可以尝试使用名为“始终在计算机启动和登录时等待网络”的组策略