Pulling Data from MS Intune Devices

Hello All

I am new to Powershell (currently worthing through the courses on Pluralsight to get my knowledge up to date)

I am trying to make a script that I can run that will pull data on enrolled devices in Intune.

The data I need to pull is Device ID, Device Name, and OS - I can do this using the below and it exports the data out to a CSV file for me.

Get-MgDeviceManagementManagedDevice | select-object id, deviceName, OperatingSystem | Export-csv -Path $csvFilePath

But I also need the data stored in Get-Computerinfo | select-object CsPCSystemType

So I can tell if its a laptop, or a desktop. But I don’t know how to run the 2 commands together and export all the data to 1 CSV file.

Would someone be able to advise what I am missing, please? or even if there is a better way to do this.

Many Thanks

Hi, welcome to the forum :wave:

Store the results of your queries in variables, then build custom objects.

$DeviceInfo = Get-MgDeviceManagementManagedDevice
$ComputerInfo = Get-ComputerInfo

[PSCustomObject] @{
    DeviceName = $DeviceInfo.DeviceName
    OS         = $DeviceInfo.OperatingSystem
    SystemType = $ComputerInfo.CsPCSystemType
} | Export-Csv -Path $CSVFilePath -NoTypeInformation

By the way, when posting code in the forum, please can you use the preformatted text </> button. It really helps us with readability, and copying and pasting your code. If you can’t see the </> in your toolbar, you will find it under the gear icon.

How to format code on PowerShell.org