0

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:\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 

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.

2
  • "Code is inside of scriptblock" please either post the full context, or create a minimal example with which this behavior can be reproduced. Commented Jan 22, 2021 at 12:00
  • @MathiasR.Jessen I have now pretty much shared whole script which is inside of script block. Commented Jan 22, 2021 at 13:49

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.