这里有我下面的代码。在哪里添加Get-Credentials或DomainCredentials以绕过这些功能的整个用户名/密码输入?
$username = "username"
$password = "password"
$secstr = New-Object -TypeName System.Security.SecureString
$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr
if ($env:computername.contains("A00"))
{
Write-Host "Computer name:" $env:computername
}else{
Write-Host "Please enter your desired computer name: [Default $env:computername]:"
$computername = Read-Host
$renamecomputer = $true
$cred = Get-Credential
if ($computername -eq "" -or $computername -eq $env:computername) { $computername = $env:computername; $renamecomputer = $false }
$cred = Get-Credential
}
if ($env:USERDOMAIN.contains("CHB"))
{
Write-Host "Domain name:" $env:USERDOMAIN
}else{
Write-Host "Adding $computername to the domain"
Add-Computer -DomainName "domain.local"
$cred = Get-Credential
if ($renamecomputer -eq $true) { Rename-Computer -NewName $computername}
$cred = Get-Credential
}