How can I reference device attributes in a PowerShell script monitor?

For example:

 

All devices of a certain type have an attribute of "SerialNumber" in the WUG device properties.

 

I want to pass the SerialNumber to an external API from a PowerShell script. How can I reference the SerialNumber attribute in a Powershell script?


  • Mike Rockwell (Progress Software)

    The percent variable for Attributes is NOT available in PowerShell. However, you can get it via the API. This is using the WhatsUpGoldPS PS modul which makes coding so much easier.

     

    1. $wugServer = "127.0.0.1"
    2. $userID = "" #WUG user that has access
    3. $userPass = "" #WUG user password
    4.  
    5. $pwd = convertto-securestring $userPass -asplaintext -force;
    6. $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $userID, $pwd;
    7.  
    8. $deviceID = [int]("%Device.DatabaseID")
    9.  
    10. Connect-WUGServer -Protocol https -serverUri $wugServer -Credential $cred -IgnoreSSLErrors
    11.  
    12. $attributeValue = (Get-WUGDeviceAttribute -DeviceId $deviceID -Names "Windows_SerialNumber").value

     

  • Actually, you can access the Percent Variables for attributes in Powershell.

     

    Example:

     

    $attributeValue = "%Device.Attribute.SerialNumber "

     

    However, please note that there is a space after SerialNumber. Without that space, the attribute won't be parsed.

    • Mike Rockwell (Progress Software)

      Yes, for PowerShell Actions, but not PowerShell Monitors.