Execute PowerShell script and collect output

%3CLINGO-SUB%20id%3D%22lingo-sub-2448387%22%20slang%3D%22en-US%22%3EExecute%20PowerShell%20script%20and%20collect%20output%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2448387%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20trying%20to%20execute%20a%20PowerShell%20script%20on%20all%20Intune%20managed%20machines%20and%20collect%20the%20output%20of%20the%20script%20afterwards.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3EEcho%20%22Hello%20world!%22%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20managed%20to%20upload%20and%20execute%20the%20PowerShell%20script%20using%20Devices%20%26gt%3B%20Policy%20%26gt%3B%20Scripts%20sections%2C%20but%20I%20cannot%20get%20the%20output%20of%20the%20script.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20is%20the%20right%20approach%20to%20collect%20such%20data%3F%20Where%20can%20I%20see%20the%20%22Hello%20world!%22%20printed%2C%20or%20what%20system%20should%20I%20use%20to%20retrieve%20the%20information%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2448387%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EIntune%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMobile%20Device%20Management%20(MDM)%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESoftware%20Management%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2449024%22%20slang%3D%22en-US%22%3ERe%3A%20Execute%20PowerShell%20script%20and%20collect%20output%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2449024%22%20slang%3D%22en-US%22%3EHi%2C%3CBR%20%2F%3E%3CBR%20%2F%3ECan%20you%20give%20us%20some%20more%20info%20what%20you%20are%20trying%20to%20accomplish%3F%20so%20we%20can%20help%20you%3CBR%20%2F%3E%3CBR%20%2F%3EAn%20example%20to%20write%20the%20output%20to%20a%20file%3CBR%20%2F%3E%3CBR%20%2F%3EWrite-Error%20-Message%20%22Forced%20Fail%22%20-Category%20OperationStopped%3CBR%20%2F%3Emkdir%20%22c%3A%5Ctemp%22%3CBR%20%2F%3Eecho%20%22Forced%20Fail%22%20%7C%20out-file%20c%3A%5Ctemp%5CFail.txt%3C%2FLINGO-BODY%3E
Contributor

I am trying to execute a PowerShell script on all Intune managed machines and collect the output of the script afterwards.

 

 

Echo "Hello World from $env:computername"

 

 

I managed to upload and execute the PowerShell script using Devices > Policy > Scripts sections, but I cannot get the output of the script.

 

What is the right approach to collect such data? Where can I see the "Hello world from MY-DEVICE" printed, or what system should I use to retrieve the information?

3 Replies
Hi,

Can you give us some more info what you are trying to accomplish? so we can help you

An example to write the output to a file

Write-Error -Message "Forced Fail" -Category OperationStopped
mkdir "c:\temp"
echo "Forced Fail" | out-file c:\temp\Fail.txt
Thank you!

There are around 50 intune managed machines in our org. I need to execcute the PowerShell script on all of those machines (this I can accomplich) and collect the output. Your example is perfect for showing how the write a file to C:\Temp, but how can I, as an intune admin collect the file from the 50 intune managed machines?
Hi,

You could take a look on how I did the same with the laps solution or bitlocker.
A perfect method to get back some information and reports...

https://call4cloud.nl/2021/05/the-laps-reloaded/