该脚本如下所示。Write-Host "Installation text and guidelines"
我应该把Write-Host代码放在哪里,以便在powershell中执行以下代码时,它会显示在控制台中?
`Using Module '.\Monitoring.psm1'
[CmdletBinding()]
Param(
[ValidateSet('Single', 'Multiple')]
[string] $Architecture = '',
[string] $AzureTenantId = '',
[switch] $SkipUserCheck
)
try {
Import-Module -Name "$($PSScriptRoot)\lib_pwsh\Instrumentation.psm1" -Force
Import-Module (Join-Path -Path $PSScriptRoot -ChildPath "\Monitoring.psm1") -Force
Send-Event "Evaluating dependencies"
$depCheck = Test-Dependencies
if ($null -ne $depCheck){
foreach ($_ in $depCheck){
Send-Event $_ -WriteOutput
}
throw "Dependency evaluation failed. Terminating uninstallation. "
}
Connect-Azure -SkipUserCheck:$SkipUserCheck
$controlParameters = [MonitoringUninstall]::new()
$controlParameters.ManualSelection = $false
Do {
Get-UninstallArchitecture -controlParameters $controlParameters
Clear-Scrollback
} Until ($controlParameters.IsValid())
Uninstall -controlParameters $controlParameters
}
Catch {
Send-Event -Message ("{0}`n{1}" -f $_.Exception.Message, $_.ScriptStackTrace) -WriteOutput
Send-Error -Message "An error has occured:`n $_" -Exception $_.Exception
If ([Environment]::UserInteractive) {
Read-Host "Press enter to continue and exit"
}
Exit
}
`
我试图把代码放在“使用模块”上面,但它给出了一个错误。我需要它在脚本运行时在控制台窗口中显示安装和指南消息。
1条答案
按热度按时间u3r8eeie1#
你的错误说明了什么?
我猜该错误与“Write-Host”无关。在这种情况下,应该执行Write-Host,但由于“using”而生成错误。
尝试导入模块..