/build/static/layout/Breadcrumb_cap_w.png

Custom Inventory rule with Powershell Script

Anyone know how to format  ShellCommandNumberReturn() for series of Powershell commands?  I am trying to get a single custom inventory item to detect the % of usable battery capacity on my laptops.  We have identified an issue where some laptops batteries are swelling as they start to fail.  We figure calculating the usable battery capacity against the ship date of the unit will give us an indication of units that pose a hazard.


Here are the lines:


$DesignedCapacity = (Get-WmiObject -Class "BatteryStaticData" -Namespace "ROOT\WMI").DesignedCapacity
$FullChargedCapacity = (Get-WmiObject -Class "BatteryFullChargedCapacity" -Namespace "ROOT\WMI").FullChargedCapacity
$BatteryLife = [math]::round(100*$FullChargedCapacity/$DesignedCapacity,2)
Write-Host $BatteryLife


I believe I could create a script to run this regularly and push the output to a text file, the capture that in a custom inventory rule, but I would like to keep it in one command if possible.


0 Comments   [ + ] Show comments

Answers (1)

Posted by: Ziggi 4 years ago
Blue Belt
3

You could simplify it, it's probably the variables causing the issue but see mine below which works and returns the same value as your code does.

ShellCommandTextReturn(cmd /q /c powershell.exe -command "[math]::round(100*(Get-WmiObject -Class "BatteryFullChargedCapacity" -Namespace "ROOT\WMI").FullChargedCapacity/(Get-WmiObject -Class "BatteryStaticData" -Namespace "ROOT\WMI").DesignedCapacity,2)")

It returns


Hope this helps.


Comments:
  • Hi Ziggi,
    The . (period) did not seem to work, but the ; (semicolon) did. - JordanNolan 4 years ago
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ