我尝试过:
$PSinstance.BeginInvoke() | Out-Null
但是当我这样做时,它会等待按下Enter键继续。这很奇怪,因为如果没有无效,它会继续正常运行。我还尝试将其分配给变量,并且其行为方式相同。如果我在该行之后写主机,它也会继续,但是我不希望有任何输出
param(
[Parameter(Mandatory = $true)]
$Location,
[Parameter(Mandatory = $true
)]
$Logs,
[Parameter(Mandatory = $true)]
$date
)
$InitialSessionState = [System.Management.Automation.Runspaces.InitialSessionState]::CreateDefault()
foreach ($Parameter in $PSBoundParameters.Keys) {
$Variable = [System.Management.Automation.Runspaces.SessionStateVariableEntry]::new($Parameter, $PSBoundParameters[$Parameter], $Null)
$InitialSessionState.Variables.Add($Variable)
}
$RunspacePool = [runspacefactory]::CreateRunspacePool(1,[int]$env:NUMBER_OF_PROCESSORS+1, $InitialSessionState, $Host)
$RunspacePool.ApartmentState = "STA"
$RunspacePool.ThreadOptions = "ReuseThread"
$RunspacePool.Open()
$PSinstance = [powershell]::Create().AddScript({
Write-Host "$Location $Logs $date"
})
$PSinstance.RunspacePool = $RunspacePool
$PSinstance.BeginInvoke() | Out-Null
$PSinstance.Streams.Information
答案 0 :(得分:0)
我知道了。在底部,您可以执行以下操作以解决问题:
$PSinstance.RunspacePool = $RunspacePool
$PSinstance.BeginInvoke() | Out-Null
Write-Host "$($PSinstance.Streams.Information)"