When you create a sensor, you must upload a PowerShell script or enter the PowerShell commands in the text box provided during configuration. These commands return the values for the sensor attributes.

PowerShell Script Examples

The following examples contain the settings and code needed. You can also visit https://code.vmware.com/samples?id=4930 for more Sensors samples.

Note: Any sensor that returns a date-time data type value uses the ISO format.
  • Check remaining battery
    • Value Type: integer
    • Execution Context: User
      $battery_remain=(Get-WmiObject win32_battery).estimatedChargeRemaining |
      Measure-Object -Average | Select-Object -ExpandProperty Averageecho $battery_remain
  • Get Serial Number
    • Value Type: String
    • Execution Context: User
      $os=Get-WmiObject Win32_bios -ComputerName $env:computername -ea silentlycontinue
      echo $os.SerialNumber
  • Get system date
    • Value Type: DateTime
    • Execution Context: User
      $date_current = get-Date -format s -DisplayHint Date
      echo $date_current
  • Check if TPM is enabled
    • Value Type: Boolean
    • Execution Context: Administrator
      $obj = get-tpm
      echo $obj.TpmReady
  • Check if TPM is locked
    • Value Type: Boolean
    • Execution Context: Administrator
      $obj = get-tpm
      echo $obj.LockedOut
  • Get TPM Locked Out Heal Time
    • Value Type: String
    • Execution Context: Administrator
      $tpm=get-tpm
      echo $tpm.LockoutHealTime
  • Check if SMBIOS is present
    • Value Type: Boolean
    • Execution Context: User
      $os = Get-WmiObject Win32_bios -ComputerName $env:computername -ea silentlycontinue
      echo $os.SMBIOSPresent
  • Check SMBIOS BIOSVersion
    • Value Type: Boolean
    • Execution Context: User
      $os = Get-WmiObject Win32_bios -ComputerName $env:computername -ea silentlycontinue
      echo $os.SMBIOSBIOSVersion
  • Get BIOS version
    • Value Type: String
    • Execution Context: User
      $os = Get-WmiObject Win32_bios -ComputerName $env:computername -ea silentlycontinue
      echo $os.Version
  • Get BIOS status
    • Value Type: String
    • Execution Context: User
      $os = Get-WmiObject Win32_bios -ComputerName $env:computername -ea silentlycontinue
      echo $os.Status
  • Get average CPU usage (%)
    • Value Type: Integer
    • Execution Context: User
      cpu_usage= Get-WmiObject win32_processor | Select-Object -ExpandProperty LoadPercentage
      echo $cpu_usage
  • Get average memory usage
    • Value Type: Integer
    • Execution Context: User
      $os = Get-WmiObject win32_OperatingSystem
      $used_memory = $os.totalvisiblememorysize - $os.freephysicalmemory
      echo $used_memory
  • Get average virtual memory usage
    • Value Type: Integer
    • Execution Context: User
      $os = Get-WmiObject win32_OperatingSystem
      $used_memory = $os.totalvirtualmemorysize - $os.freevirtualmemory
      echo $used_memory
  • Get average network usage
    • Value Type: Integer
    • Execution Context: User
      $Total_bytes=Get-WmiObject -class Win32_PerfFormattedData_Tcpip_NetworkInterface
      |Measure-Object -property BytesTotalPersec -Average |Select-Object -ExpandProperty Average
      echo ([System.Math]::Round($Total_bytes))
  • Get average memory usage for a process
    • Value Type: String
    • Execution Context: User
      $PM = get-process chrome |Measure-object -property PM -Average|Select-Object -ExpandProperty Average
      $NPM = get-process chrome |Measure-object -property NPM -Average|Select-Object -ExpandProperty Average
      echo [System.Math]::Round(($PM+$NPM)/1KB)
  • Check if a process is running or not
    • Value Type: Boolean
    • Execution Context: User
       $chrome = Get-Process chrome -ea SilentlyContinue
      			if($chrome){
      				echo $true
      				}
      			else{
      				echo $false
      				}
  • Check if Secure Boot is enabled
    • Value Type: Boolean
    • Execution Context: Administrator
      try { $bios=Confirm-SecureBootUEFI }
      catch { $false }
      echo $bios
  • Active Network Interface
    • Value Type: String
    • Execution Context: User
      $properties = @(‘Name’,’InterfaceDescription’)
      $physical_adapter = get-netadapter -physical | where status -eq "up" 
      |select-object -Property $properties
      echo $physical_adapter
  • Check the PowerShell version
    • Value Type: String
    • Execution Context: User
      $x = $PSVersionTable.PSVersion
      echo "$($x.Major).$($x.Minor).$($x.Build).$($x.Revision)"
  • Check Battery max capacity
    • Value Type: Integer
    • Execution Context: User
      $max_capacity = (Get-WmiObject -Class "BatteryFullChargedCapacity" -Namespace "ROOT\WMI").FullChargedCapacity | Measure-Object -Sum | 
      Select-Object -ExpandProperty Sum
      echo $max_capacity
  • Check Battery Charging Status
    • Value Type: String
    • Execution Context: User
      $charge_status = (Get-CimInstance win32_battery).batterystatus
      $charging = @(2,6,7,8,9)
      if($charging -contains $charge_status[0] -or $charging -contains $charge_status[1] )
      {
                      echo "Charging"
                      }else{  
                      echo "Not Charging"
      }
  • Active Power Management Profile
    • Value Type: String
    • Execution Context: Administrator
      $plan = Get-WmiObject -Class win32_powerplan -Namespace root\cimv2\power 
      -Filter "isActive='true'" 
      echo $plan
  • Check if Wireless is present
    • Value Type: Boolean
    • Execution Context: User
      $wireless = Get-WmiObject -class Win32_NetworkAdapter -filter "netconnectionid like 'Wi-Fi%'"
      	if($wireless){echo $true}
      	else {echo $false}
  • Get Java version
    • Value Type: String
    • Execution Context: User
      $java_ver = cmd.exe /c "java -version" '2>&1'
      echo $java_ver