읽기 호스트가 실행되기 전에 Powershell 스크립트 자격 증명 프롬프트가 나타납니다.

읽기 호스트가 실행되기 전에 Powershell 스크립트 자격 증명 프롬프트가 나타납니다.

다른 스크립트 내에서 스크립트를 호출합니다.

...
...
powershell C:/temp/script2.ps1"
...
...

몇 가지 항목을 다운로드한 후 VM을 도메인에 조인합니다. 그러나 스크립트가 실행되면 "컴퓨터 추가" 프롬프트가 읽기 호스트 이전에 실행되거나 완전히 건너뜁니다.

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

답변1

이 문제는 내가 했던 것처럼 powershell로 호출하는 대신 스크립트 이름 앞에 앰퍼샌드를 추가하면 해결되는 것 같습니다.

powershell_stuff
..
..
& C:/temp/script2.ps1
..
..
morePowershell_stuff

이 게시물의 아이디어:다른 Powershell 스크립트를 실행하고 끝날 때까지 기다리는 Powershell 스크립트

관련 정보