get bios information using powershell - powershell

I have a problem with my powershell script.
the problem is (i think)i cant find the right class.
What i would like to acomplish today is that I can write(echo) my PSComputerName. But i keep getting the wrong info.(somethimes i dont get anything like the code below)
(important is that it has to come out of my BIOS)
my script
$bios = Get-WmiObject -Namespace root/hp/instrumentedBIOS -Class hp_biosSetting
echo $bios.PSComputerName
What am i doing wrong
please help

I managed to find what I was looking for.
$bios =Get-WmiObject -Namespace root/hp/instrumentedBIOS -Class HP_BIOSEnumeration
echo $bios.__server

Related

Rename-LocalUser alternative on PowerShell 4.0

I know PS 4.0 is ancient. But we're using it anyway on some dev servers it is not my decision.
I'd like to know if there's an alternative for Rename-LocalUser which requires 5.1+ Even if it needs calling wmic, I'm unsure if how to use that kind of call, please give me some examples in one or the other way.
Thank you
Abraham Zinala has provided the right answer in his helpful comments on how to approach this on older PowerShell versions.
You can either use Get-WmiObject to query the local user, and then invoke the .Rename(..) method:
$myAccount = Get-WmiObject Win32_UserAccount -Filter "name='theAccountIWantToRename'"
$myAccount.Rename('myNewUserName')
Or, recommended use of Get-CimInstance and Invoke-CimMethod since WmiObject is no longer available in newer PowerShell versions:
$myAccount = Get-CimInstance Win32_UserAccount -Filter "name='theAccountIWantToRename'"
Invoke-CimMethod -InputObject $myAccount -MethodName Rename -Arguments #{ Name = 'myNewUserName' }

How to execute, "Run Advertised Programs" with PowerShell

I display all the available applications on the "Run Advertised Programs" using PowerShell.
$tpObject = Get-WmiObject -Namespace ROOT\ccm\Policy\Machine\ActualConfig -Class CCM_SoftwareDistribution `
| Select-Object -Property PKG_Name, PKG_PackageID
This part works fine.
My Question: How do I execute one of these apps using PowerShell. I tried,
$tpObject.ExecuteProgram($ID, $PackageID,$true)
Where I Substituted the $ID and $PackageID for the values discovered in the first step. The code to execute the app gave me an error. I think my syntax is incorrect.
Any advice would be greatly appreciated.
tks

Uninstalling program using powershell

I am trying to uninstall a program/application from system automatically using power shell. When I googled first, advice was to use get-wmiobject and then use uninstall() function.
Code I used:
$app = get-wmiobject -Class Win32_Product | where-object ($_Name -Like "part of product name"}
$app.uninstall()
Error message:
Screen shot attached.
Solution tried: Most of the blogs mentioned that not running as administrator would be the reason for the problem. But, I tried running the code as the administrator and still getting the error message. Any help would be useful.
Thanks,
Manoj Kumar

Delete user profile using Powershell

I am wondering how I can delete user profile by using Powershell?
I know the command of Get-WmiObject Win32_UserProfile which will give me the whole users on the computer.
I have 2 variables of $computername and $username.
So I wants to use the above command to delete on a remote computer (which is $computername) the profile of $username.
How I can do it?
Thanks.
Get-WMIObject can retrieve objects from remote computers with no problem, and not only does the Win32_UserProfile class have a (poorly documented) delete() method, a Win32_UserProfile object can be passed to Remove-WMIObject. This will, to all appearances, properly clean up the registry and files, and does in fact work on remote computers.
References:
Get-Help Get-WMIObject
Get-Help Remove-WMIObject
Win32_UserProfile: https://msdn.microsoft.com/en-us/library/ee886409(v=vs.85).aspx and https://msdn.microsoft.com/en-us/library/windows/desktop/hh830632(v=vs.85).aspx
My own question on this topic

Using WQL query from SCCM in powershell

I have a query in SCCM that will take a printer IP address and return all workstations in SCCM that have the printer installed on it. I am wanting to create a powershell script that will take said query and use the workstations that it returns to then list current print jobs in the print queue on the workstation.
I know that you can use Get-CIMInstance -query to query different things in WMI. That works well if I am trying to find out information locally. However if I dump the WQL query into a Here-String and assign it to a variable and then call it with Get-CIMInstance -query it returns an error saying invalid query. The same thing happens when I use Get-WmiObject -Namespace "root\wmi" -Query $WQlquery
So how would I be able to use the WQL query from SCCM in powershell? Here is an example of what I have so far:
$WQLquery = #"
select SMS_R_System.Name from
SMS_R_System inner join
SMS_G_System_PRINTER_DEVICE on
SMS_G_System_PRINTER_DEVICE.ResourceID =
SMS_R_System.ResourceId where
SMS_G_System_PRINTER_DEVICE.PortName like "10.10.10.10"
"#
Get-CIMInstance -query $WQLquery
Assuming that worked and returned a list of workstation ids, I would then use Get-Printjob cmdlet to list current jobs in each workstations print queue. I have found a few questions posted here already that have helped me get this far. Any additional help would be appreciated. Go easy on me, still a newb here.
You need to specify the namespace for the sccm site root\sms\site_SITECODE and the sccm-server if you're running it from a remote computer. Ex:
$WQLquery = #"
select SMS_R_System.Name from
SMS_R_System inner join
SMS_G_System_PRINTER_DEVICE on
SMS_G_System_PRINTER_DEVICE.ResourceID =
SMS_R_System.ResourceId where
SMS_G_System_PRINTER_DEVICE.PortName like "10.10.10.10"
"#
Get-WmiObject -Query $WQLquery -ComputerName "SCCMSERVER" -Namespace "root\sms\site_PRI"