【发布时间】:2021-01-22 21:48:45
【问题描述】:
我的脚本中有以下代码行,从我的管理笔记本电脑运行到服务器。代码在脚本块内
# If a proxy server is needed, execute these commands with the proxy URL and port.
[Environment]::SetEnvironmentVariable("https_proxy","http://{proxy-url}:{proxy-port}","Machine")
$env:https_proxy = [System.Environment]::GetEnvironmentVariable("https_proxy","Machine")
# For the changes to take effect, the agent service needs to be restarted after the proxy environment variable is set.
Restart-Service -Name himds
# Install the package
msiexec /i c:\temp\AzureConnectedMachineAgent.msi /l*v c:\temp\installationlog.txt /qn | Out-String
# The agent service needs to be restarted after the proxy environment variable is set in order for the changes to take effect.
Restart-Service -Name himds
# Run connect command
& "$env:ProgramFiles\AzureConnectedMachineAgent\azcmagent.exe" >> $logfolder\$logfile connect `
--service-principal-id $appId `
--service-principal-secret $password `
--resource-group $resourceGroup `
--tenant-id $tenantId `
--location $location `
--subscription-id $subscriptionId
问题是我在运行脚本时在我的 Powershell(在我的管理笔记本电脑上)屏幕中没有得到任何输出。我知道运行该 exe 会产生输出。输出应该类似于在本地机器上运行或使用脚本的以下命令结束时的样子
$输出 | Out-File -FilePath .\AzureArc.txt -append
也尝试过 Start-Transcript 和 Stop-Transcript,但均未显示日志。
提示我应该尝试什么,以便在脚本执行时将日志显示在屏幕上
编辑:从脚本块添加了几乎完整的代码。还将 >> $logfolder$logfile 添加到 azcmagent.exe 的末尾,这使我能够将日志收集到文件中,但在运行脚本时无法让它们显示在 Powershell 上。
【问题讨论】:
-
“代码在脚本块内”请发布完整的上下文,或创建一个可以重现此行为的最小示例。
-
@MathiasR.Jessen 我现在几乎共享了脚本块内的整个脚本。
标签: azure powershell