HP BIOS Battery Health Settings - powershell

I am attempting to change the BIOS battery charging settings with PowerShell and will eventually deploy it using Intune. I am interested in doing this because I have some users that leave their computers plugged in full-time and it ruins the battery within a year. Changing this setting will only allow the computer to charge up to a specified limit which will hopefully increase the batteries overall lifespan.
I am having issues with my code which is giving me a "The Term ' ' is not recognized as the name of a cmdlet, functions, script file, or operable program". I am using the following documentation to create the script and am using an HP computer that has been verified to have this setting in the BIOS.
https://developers.hp.com/hp-client-management/blog/managing-battery-health-settings-hpcmsl-and-intune
$setting = Get-HPBIOSSettingValue -Name "Battery Health Manager"
if ($setting -eq "Let HP manage my battery charging") {
exit 0
}
Set-HPBIOSSettingValue -Name "Battery Health Manager" -value "Let HP manage my battery charging"
exit 0
For the purpose of this exercise I don't really need to test the detect script because I already know what this setting is set to. Does anyone know what I am doing wrong? The script also failed when I saved it as a .ps1. I have a feeling there is something very basic that I am missing because I am new to powershell.

Sounds like you don't have the HP Powershell module installed.
The command Get-HPBIOSSettingValue and Set-HPBIOSSettingValue are not native to Windows - you'll need to download the relevant HP module and install it - try Powershell Gallery.

Related

PowerShell - showing a message on remote computer screen

When I am running commands or installing software remotely using PowerShell - Invoke-Command etc I would like sometimes to be able to show a message on the remote screen so the user knows something is happening, or when work done etc.
I would like to if possible make this message look as professional as possible, e.g. better than just a standard winform message box if it can be done? perhaps more the style of the Windows 10 ones with coloured background and use of image if possible.
Spent a while googling but most seem to relate to using obsolete methods such as net-send or using msg.exe.
Thanks
https://michlstechblog.info/blog/powershell-show-a-messagebox/
So the issue really isnt creating the messagebox itself, its having it show on the users session.
So when you run a command against a system, youre using your creds to run the command therefore it wont show in the users session. You can get around this by running it in the users context using a task scheduler. I have a script that does all this for you but, id hate to recreate the wheel and will have to wait till monday (when im at work) to post it here.
It accepts user input in your sessions that outputs it to a vbs, which then copies it over the message to the users machine, and a task schedule is set to run immediately for the user thats logged in.
edit: The script is this without the task scheduler. I just invoke gwmi win32_computersystem | Select -ExpandProperty username to get the current user logged in and add it to the task.
#Prompt for messge
$strMSG = Read-Host -Prompt "Enter message"
#deleting vbs if it exists
del C:\brief\test.vbs
#creating vbs from scratch so it doesnt override
New-Item C:\brief\test.vbs
#Appending each the values to a seperate line
Add-Content C:\brief\test.vbs 'Set objShell = Wscript.CreateObject("WScript.Shell")'
Add-Content C:\brief\test.vbs "strText = `"$strMSG`""
Add-Content C:\brief\test.vbs 'intButton = objShell.Popup(strText,0,"Computer Support",48)'
#calling on the script
& cscript C:\brief\test.vbs
Found a great solution here which appears on quick testing to work well for displaying a toast notification on a remote machine
https://smsagent.blog/2019/06/11/just-for-fun-send-a-remote-toast-notification/

Getting CimException: Invalid property when using Get-Disk with no parameters

I have a script which makes use of the Get-Disk command in Powershell. Intermittently, I get an error when using Get-Disk with no parameters:
$disk = Get-Disk | Where-Object { $_.Location -eq $Location }
Microsoft.Management.Infrastructure.CimException: Invalid property
at Microsoft.Management.Infrastructure.Internal.Operations.CimAsyncObserverProxyBase`1.ProcessNativeCallback(OperationCallbackProcessingContext callbackProcessingContext, T currentItem, Boolean moreResults, MiResult operationResult, String errorMessage, InstanceHandle errorDetailsHandle)
where $Location is the disk location (similar to PCIROOT(0)#PCI(1500)#PCI(0000)#SAS(P00T01L00)). The script this line is run from is part of our VM provisioning script, which gets run after the clone and VMWare customization script is run. This error does not always happen, and if I go and run the script manually later it succeeds every time leading me to believe it is a race condition of some sort. Any ideas as to why Get-Disk isn't working reliably?
Ultimately, this script is being kicked off from vRealize Orchestrator (vRO, formerly vCenter Orchestrator or vCO) using the Guest Script Manager plugin. This detail may not be relevant, but this script has only failed running when kicked off by this plugin.
Additional details:
Powershell Version: 4.0
OS Version: Windows Server 2012 R2
Hypervisor: VMWare vCenter Version 6.0.0 Build 5112533
vRO Version: 7.2
I ended up provisioning the disks with diskpart instead of the storage cmdlets, which works without issue. Although I did find out that our script is running while the Windows installation is still completing, which may account for the storage cmdlets not working properly.
Follow Up: I did confirm that the storage cmdlets were indeed not working due to the Windows installation still completing. Now that I figured out how to wait for completion, the storage cmdlets work fine every time.

Task sequence variable for OS, I want to install

I'm verry beginer in powershell, I'm wonking in a project, the goal it's to set the Biossetting like disabling or enabling the secureBoot and UEFI mode, while installing windows 7 or 10 by MDT.
I'm working with Dell and hp computer, I have the script for setting the bios of hp or dell
Hp:
$bios=Get-WmiObject -Namespace root/hp/instrumentedBIOS -Class HP_BIOSSettingInterface
$bios.SetBIOSSetting("UEFI Boot Options", "Enable","")
Dell:
(Get-WmiObject DCIM_BIOSService -namespace root\dcim\sysman -ComputerName .).SetBIOSAttributes($null,$null,"Secure Boot","1")
Then, my first problem these command is not working in any computer I need to install some modules, some cmdlet from hp or dell website, I want to know if make my script ".exe", it's gonna work in every-computer ?
Because I need to run my script with with deployement of windows.
My second and difficult task, I want to know with variable task sequence to use in my script, to detect the os of the tasksequence, I find this code in internet, after too much research in internet
$TaskPath = "$($MdtDrive):\Task Sequences"
$ControlPath = "$MDtroot\Control"
$OSPath = "$($MdtDrive):\Operating Systems"
$OS = (Get-ChildItem -Path $OSPath | Out-GridView -PassThru -Title "Select required OperatingSystem").Name
This code detect if the OS of the task sequence I want install in my computer is windos 7 or windows 10?
Thanks !
If I recall correctly from my days of systems deployment, Dell and HP both make dedicated tools for settigns BIOS configuration. Just make sure you run it in WinPE. Depending on which BIOS settings you change you make even have to boot WinPE twice to make sure the OS installs the way you want.
Dell: http://en.community.dell.com/techcenter/enterprise-client/w/wiki/7532.dell-command-configure
HP: https://deploymentbunny.com/2010/10/18/enable-tpm-via-task-sequence-on-hp-boxes/
Although it is definitely possible to make these settings in WMI I would only look to it as a last resort. Windows has to be compatible with every piece of hardware, whereas Dell/HP tools are targeted at their systems. It's like using a scalpel vs a Swiss army knife.
I have some difficults I’m working in a script who set the bios configuration while installing windows 7 or 10 by MDT, then my first question is:
Wich variable I can use to identify the os of the new task sequence I mean the current os the mdt preparing to install in the computer after the user select the os during the installation.
I’m wondering if this code doying the job
$OS = Get-ChildItem -Path $OSPath | Out-GridView -PassThru -Title “Select required OperatingSystem”
$OSPath = “$($MdtDrive):\Operating Systems”

Get HDD serial numbers using Powershell

I am archiving a large number of HDD's at my company, and I have a powershell script that grabs the hostname and user list from a Windows OS installation, and I would like to programatically find the serial number of the drive as well. I have the following bit of Powershell code (mostly completed) that should do this, but there's a complication as well.
$Disks = Get-WMIObject -class win32_PhysicalMedia
$SerialNumber = foreach($Disk in $Disks) {IF ($Disk.SerialNumber -ne ' WD-WCC2EAV91692') {[do something here]}}
I am connecting the drives with a USB HDD dock, and it seems that if the computer is booted with the drive connected internally (via SATA cables, I haven't tested externally yet), then the SerialNumber field is populated. However, if I connect it after the computer has booted up, the SerialNumber field is always blank. Is there a way to have the computer re-scan for this info when I connect the drive, or is this info only gathered at boot-up, for example, by the BIOS or something?
AFAIK the SerialNumber is optional and provided by the driver. So if the USB-dock driver is not providing the information to Windows, then there's no easy way to retrieve it.
This thread (look for "Maxim Shatskih") says that IOCTL_SCSI_PASS_THROUGH is supported by USBSTOR, so it would be possible to write or find a program that can get the serial number from a USB attached drive, by passing the appropriate SCSI command to the drive (get mode page 80h).
A package that may do what you need is sg3_utils for Windows (it was originally written for Linux but ported to Windows).
I just tested booting the computer up with the HDD in the USB dock, and I got the same result. Technically, the SerialNumber field wasn't blank, but was all zero's instead of the actual serial number, which is probably just the same difference. It's seeming like it may be more work than it's worth to do this as a part of the script (assuming it's even possible), so I will likely just continue scanning the SN barcode into the script. It's an extra step, but only takes a couple seconds.
Thanks everyone for the input.

Powershell - Refresh SNMP from registry or do a SNMPServiceResetEvent

I've written a powershell script that writes registry entries for network drivers to change DCB settings. Things like turning DCB on and off, defining traffic classes and bandwidth groups. After writing the values to registry sometimes you cannot see the changes with SNMP remotely. Though this is inconsistent.
I've scoured the web to see if there is a way to force SNMP to get its values from registry again. We have a script that sets the values in SNMP which automatically changes the registry. I'm trying to go the opposite way and set the values in the registry and have the MIB updated. I've tried reseting the SNMP service and network device in the script with no luck.
After modifying the registry, do a SetEvent on the global event named
"SNMPServiceResetEvent". (That is, do a CreateEvent to that named event and
then do a SetEvent). That should cause the agent to reintialize using the
current registry values.
Jeff Kelley
Microsoft / Windows CE Networking
The only thing I've found that sounds like what I need is the above quote, though futher research suggests he is talking about C++ or C#. Is there a way to do what he suggests in powershell? I found a New-Event commandlet though I'm unsure of its suitability to the current task. Code I've tried:
$snmpService = New-Event -sourceidentifier dcbScriptSnmpReset -sender SNMPServiceResetEvent -messagedata "Reset SNMP to refresh Registry"
Though there is no Set-Event commandlet and I don't know how to proceed.
Any help or leads would be much appreciated.
Thanks,
Marcus
Apparently I misunderstood how SNMP worked and now I can get it to update values entered into the registry by enabling and disabling the network adapter and stopping and starting the SNMP service:
Stop-Service $snmpService.Name
$adaptor = Get-WmiObject -Class Win32_NetworkAdapter | Where-Object {$_.DeviceID -eq $deviceID }
$adaptor.Disable()
$adaptor.Enable()
Start-Service $snmpService.Name