$RegistryPath = 'HKLM:\Software\Lansweeper' $DesignedCapacity = (Get-WmiObject -Class "BatteryStaticData" -Namespace "ROOT\WMI").DesignedCapacity $Designed = 'BatteryDesignedCapacity' $CurrentCapacity = (Get-WmiObject -Class "BatteryFullChargedCapacity" -Namespace "ROOT\WMI").FullChargedCapacity $Current = 'BatteryCurrentCapacity' $Batteryhealth = [math]::Round(100*$CurrentCapacity/$DesignedCapacity) $Health = 'Batteryhealth' # Create the key if it does not exist If (-NOT (Test-Path $RegistryPath)) { New-Item -Path $RegistryPath -Force | Out-Null} # Now set the value New-ItemProperty -Path $RegistryPath -Name $Designed -Value $DesignedCapacity -PropertyType STRING -Force New-ItemProperty -Path $RegistryPath -Name $Current -Value $CurrentCapacity -PropertyType STRING -Force New-ItemProperty -Path $RegistryPath -Name $Health -Value $Batteryhealth -PropertyType STRING -Force