Looking for PowerShell help - Getting HW Assets
I can get HW Assets, I can get the Custodian (OwnedbyUser) of an Asset. Having a harder time putting it all together. Any help would be great
Best Answer
-
Eric_Krasner Customer Advanced IT Monkey ✭✭✭OK, I figured it out. If anyone else was interested ...Import-Module smlets$Custodians = @()$Machines = @()# Define the EndUser HW Asset Types$HWAssetTypesToInclude = @('Enum.8334b87e4c2549b2935f58eff64cb7eb','Enum.a7e452f127534536b7acf9509929eb0d','Enum.2d2f43e1d72d43b08c2b9aabac43a51a','Enum.7c691b50e88a4999bc139f4e189eaafd','Enum.3d687739c5d34b46bcaaefd81b87c539','Enum.1190ee287de442eeacc8c283a98212df','Enum.5fb8bcd1821840bba2e8e5da4e33404e')# Define the HW Asset Status I want to filter on$HWAssetStatus = 'Cireson.AssetManagement.HardwareAssetStatusEnum.Deployed'# Get HW Asset Deployed and End User Types$HWAssets = get-scsmobject -class (get-scsmclass -name 'Cireson.AssetManagement.HardwareAsset') | Where { ($HWAssetTypesToInclude -contains $_.HardwareAssetType -and $HWAssetStatus -eq $_.HardwareAssetStatus)}# Get the Custodians for each of the HW Assets$GetCustodians = foreach ($HWAsset in $HWAssets){# Custodian RelationShip$OwnedByUser_relclass_id = 'cbb45424-b0a2-72f0-d535-541941cdf8e1'$OwnedByUser_relclass_obj = Get-SCSMRelationshipClass -id $OwnedByUser_relclass_id$Custodian = Get-SCSMRelatedObject -SMObject $HWAsset -Relationship $OwnedByUser_relclass_objIf($Custodian){($Custodians += $Custodian.DisplayName) -and ($Machines += $HWAsset.DisplayName)}}3
Answers