我在另一个脚本中调用一个脚本:
...
...
powershell C:/temp/script2.ps1"
...
...它在下载了一些东西之后将VM加入到一个域。但是,当脚本运行时,“”的提示符在read-host之前运行,或者完全跳过:
param (
[String]$OU,
[PSCredential]$Credential
)
$ErrorActionPreference="SilentlyContinue"
Stop-Transcript | out-null
$ErrorActionPreference = "Continue"
Start-Transcript -path C:\script2.txt -append
if ([Environment]::UserInteractive) {
if (!$OU) { $OU = Read-Host "Enter Tenant Resource Pool Name (exactly as appears in vCenter inventory)" }
if (!$Credential) { $Credential = Get-Credential -Message "Enter dev domain credentials" }
}
# Add Computer to Dev domain
try {
Add-Computer -DomainName dev.domain.com -OUPath "OU=$OU,dc=dev,dc=domain,dc=com" -ErrorAction stop -Credential $Credential
}
catch {
Write-Warning "Failed to join to domain."
Read-Host -Prompt "Press Enter to exit"
Throw $_
}这显然失败了,因为域连接需要-OUPath,它没有提示。
如果我通过右击运行script2.ps1,它就能工作。当我像这样从其他脚本中运行它时,它会失败:
wget -O C:/temp/script1.ps1 https://script-source.com:8443/script1.ps1 | powershell C:\temp\script1.ps1发布于 2022-06-17 03:01:09
这似乎可以通过在脚本名前面添加一个符号来解决,而不是像我所做的那样用powershell调用它:
powershell_stuff
..
..
& C:/temp/script2.ps1
..
..
morePowershell_stuffhttps://serverfault.com/questions/1103487
复制相似问题