Tech Community Live: Microsoft Intune
Mar 20 2024, 07:30 AM - 11:30 AM (PDT)
Microsoft Tech Community

Execute PowerShell script and collect output

Iron 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?

6 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/

@Rudy_Ooms_MVP We have this script below 

$computer = $env:COMPUTERNAME
$namespace = "ROOT\CIMV2"
$classname = "Win32_InstalledWin32Program"

Write-Output "====================================="
Write-Output "COMPUTER : $computer "
Write-Output "CLASS : $classname "
Write-Output "====================================="

Get-WmiObject -Class $classname -ComputerName $computer -Namespace $namespace |
Select-Object Name,Vendor

 

 

Which is giving below mention output on local device

 

Mozilla Firefox (x64 en-US) Mozilla
Mozilla Maintenance Service Mozilla
Microsoft 365 - en-us Microsoft Corporation
Microsoft 365 Apps for enterprise - en-us Microsoft Corporation
Microsoft OneDrive Microsoft Corporation
Microsoft OneNote - en-us Microsoft Corporation
USBPcap 1.5.4.0 Tomasz Mon
FortiClient Fortinet Technologies Inc
Rapid7 Insight Agent Rapid7, Inc.
ImageRight Document Converter Vertafore, Inc.
Remote Desktop Microsoft Corporation
OpenSSL (64-bit) Shining Light Productions
ImageRight PDF Printer Vertafore, Inc.
Local Administrator Password Solution Microsoft Corporation
Microsoft Teams Meeting Add-in for Microsoft Office Microsoft
NVIDIA Graphics Driver 537.79 NVIDIA Corporation
Zoom (64-bit) Zoom
Microsoft Update Health Tools Microsoft Corporation
Power BI Report Builder Microsoft Corporation
Google Chrome Google LLC
DisplayLink Graphics DisplayLink Corp.
Microsoft Edge Microsoft Corporation
Microsoft Edge Update
Microsoft Edge WebView2 Runtime Microsoft Corporation
Npcap Nmap Project
Lenovo Vantage Service Lenovo Group Ltd.
Wireshark 4.2.2 x64 The Wireshark developer community, https://www.wiresha...
Microsoft Visual C++ 2015-2022 Redistributable (x64) - 14.38.33130 Microsoft Corporation
ImageRight Microsoft Add In Vertafore, Inc.
Jabra Xpress GN Audio A/S
Configuration Manager Support Center Microsoft Corporation
Teams Machine-Wide Installer Microsoft Corporation
Microsoft Intune Management Extension Microsoft Corporation
Adobe Acrobat Reader Adobe Systems Incorporated
Clean Your Device Lenovo
ImageRight Desktop Vertafore, Inc.
Microsoft Teams classic Microsoft Corporation
Microsoft Visual Studio Code (User) Microsoft Corporation

 

Now i want to send this script to other device and capture that with me using Intune , would you please suggest i can collect 

 

 

Hi... You could convert that script in a proactive remediation... buttttt maybe its worth looking at Intune Pivot that is going to be released in the feature (technical take off)

https://techcommunity.microsoft.com/t5/endpoint-management-events/advanced-analytics-supercharge-rea...

In which you can query this information realtime from the device.... with a kql query...
I am aware about that new feature but if i wanted to get this kind of information using proactive remediation then do i need to compress the data into any kind of format your little guidence will help me, I will adjust the script accordingly