Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

azure - Powershell don't give output after running exe

I have following line of code in my script which I'm running from my management laptop to servers. Code is inside of scriptblock

# 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:empAzureConnectedMachineAgent.msi /l*v c:empinstallationlog.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:ProgramFilesAzureConnectedMachineAgentazcmagent.exe" >> $logfolder$logfile connect  `
    --service-principal-id $appId `
    --service-principal-secret $password `
    --resource-group $resourceGroup `
    --tenant-id $tenantId `
    --location $location `
    --subscription-id $subscriptionId 

problem is that I don't get any output of that in my Powershell (on my management laptop) screen when running the script. I know that running that exe gives output. Output should look something like when running on local machine or when using following command end of script

$output | Out-File -FilePath .AzureArc.txt -append

enter image description here

Tried also Start-Transcript and Stop-Transcript but did not display logs neiher.

Tips what should I try so that I would get logs to show on my screen while script i

EDIT: Added pretty much whole code from scriptblock. Added also >> $logfolder$logfile to end of azcmagent.exe which made that I was able to collect logs to file but were not able do get them to show on Powershell while running script.

question from:https://stackoverflow.com/questions/65842893/powershell-dont-give-output-after-running-exe

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you want to write output to screen you would need to add some write-output, Write-Host or verbose Code is inside the scriptblock/azcmagent.exe. Since you have not pasted your code it would be hard to specify where to add this. Here re some examples>>

eg.

Get-Mailbox -ResultSize unlimited | Where-Object HasPicture -eq $true -Verbose

or

$data = "My data to output"
Write-Host $data -ForegroundColor Green

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...