Home Asset Management

Looking for PowerShell help - Getting HW Assets

Eric_KrasnerEric_Krasner Customer Advanced IT Monkey ✭✭✭
In a nutshell, I am trying to get all HW Assets, where the HW Asset type is any type of Laptop or Desktop, where OwnedByUser is not Null.

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_KrasnerEric_Krasner Customer Advanced IT Monkey ✭✭✭
    Answer ✓
    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_obj
        If($Custodian){($Custodians += $Custodian.DisplayName) -and ($Machines += $HWAsset.DisplayName)}

    }

Answers

  • Eric_KrasnerEric_Krasner Customer Advanced IT Monkey ✭✭✭
    This gets all HW Asssets
    # Get HW Asset
    $HWAssets = get-scsmobject -class (get-scsmclass -name 'Cireson.AssetManagement.HardwareAsset')

    This  gets the Custodian of the Asset
    # 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_obj
  • Eric_KrasnerEric_Krasner Customer Advanced IT Monkey ✭✭✭
    Also, for any Cireson folks listening in, I would be great to have a Category for just PowerShell questions, issues, etc.
  • Eric_KrasnerEric_Krasner Customer Advanced IT Monkey ✭✭✭
    Answer ✓
    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_obj
        If($Custodian){($Custodians += $Custodian.DisplayName) -and ($Machines += $HWAsset.DisplayName)}

    }

Sign In or Register to comment.