If I use the code:
get-wmiObject win32_computersystem | select *
I get all the properties that this wmiobject has. I want to filter it, so that all the properties starting with _ (underscore) are filtered out. But I can't find the command to do this.
Could someone help me out?
You should use Get-CimInstance instead of Get-WmiObject. If you read the help for Select-Object you will learn that you can include desired properties and you can exclude properties if you like:
Get-CimInstance -ClassName CIM_ComputerSystem |
Select-Object -ExcludeProperty __* -Property *
Disclaimer: I have no knowledge of PowerShell.
From Select-Object/Parameters, I would try -ExcludeProperty
Specifies the properties that this cmdlet excludes from the operation. Wildcards are permitted.
get-wmiObject win32_computersystem | Select-Object -ExcludeProperty _* -Property *
Related
Question
When I use the command Get-WmiObject -Class Win32_Volume -Property DriveLetter, does PowerShell filter the results in the exection of the cmdlet? Does it return everything first and then select the requested and other essential properties? Does it provide a special query that returns only the requested data? How would I be able to discover this?
Yes it gives the detailed information for the volumes; Basically you should select the property after piping it.
But for this case it is always to use query and then piping it which will give a much detailed information.
Get-WmiObject -Query "Select * from win32_volume" | Select DriveLetter
or
Get-WmiObject -Class Win32_Volume -Property DriveLetter | Select DriveLetter
try it:
Get-WmiObject -Class Win32_Volume | where __GENUS -eq 1 | select __GENUS, __CLASS
In your example,
Get-WmiObject -Class 'Win32_Volume' -Property 'DriveLetter'
the command doesn't filter anything. There is a -Filter argument for Get-WmiObject that uses WQL to filter the results when it's retrieving the objects. It performs the query:
SELECT * FROM $CLASS WHERE $FILTERTEXT
I am running powershell command below
Get-wmiobject -class win32_logicaldis
I want to list all other attributes for -class. How can I do it?
I tried get-wmiobject | get-member, it was asking me to input a class value which I dont know what options I have.
Get-WMIObject -List| Where{$_.name -match "^Win32_"} | Sort Name | Format-Table Name
I have a simple problem that I can't seem to work through. I need to know what servers are still running server 2008/R2.
I know that Win32_OperatingSystem's Name property contains the information that I'm looking for. I would like to be able to run Get-WmiObject against a collection of servers in an OU.
There are two problems that I'm having:
I can't figure out how to redirect the output of Get-ADComputer to something that Get-WmiObject -ComputerName can use. I think Get-ADComputer is outputting objects of type Microsoft.ActiveDirectory.Management.ADComputer, and Get-WmiObject is looking for type System.Management.ManagementObject. Here's what I came up with but it doesn't appear to work.
Get-WmiObject Win32_OperatingSystem -ComputerName (Get-ADComputer -filter * -SearchBase "OU=Member Servers,DC=Company,DC=Com" | select #{L="ComputerName";e={$_."name"}}) -Property name, csname | select csname, name | Format-Table -AutoSize
My temp workaround: I was able to create a CSV that contains the list of server names. I was able to use the CSV to run Get-WmiObject against. However, the OU contains "dead" servers. So when I try to run Get-WmiObject using the CSV-list of servers that came from AD there are connection timeouts and PowerShell waits a period of time to see if the dead server will respond. This really slows down the operation & we are working to clean this up. Until that happens, Is there a way to only pass the server names that pass a Test-Connection to Get-WmiObject?
Get-WmiObject win32_operatingsystem -ComputerName (Get-Content C:\Users\user1\Desktop\Servers.csv) -Property name, csname | select csname, name | Format-Table -AutoSize
Pick the name component first then it will pass it to the next pipeline object (select -object)
Get-WmiObject Win32_OperatingSystem -ComputerName ((Get-ADComputer -filter * -SearchBase "OU=Member Servers,DC=Company,DC=Com").Name)
Note: -ComputerName: accepts a string object so you cannot pass a base type object directly to that.
I'm having a hell of a time with what seems like an utterly bizarre issue. I'm basically trying to inventory a bunch of workstations via WinRM and the Invoke-Command PowerShell cmdlet, but I'm running into grief when I try to execute more than one Get-WMIObject call at a time.
In this case, I'm specifically trying to get the model and serial number of the workstations and pipe them out to a CSV, making it important that the two commands are executed in the same Scriptblock, giving me something very similar to the below, basically.
Invoke-Command -ScriptBlock { Get-WmiObject Win32_ComputerSystem | Select Model ; Get-WmiObject win32_SystemEnclosure | Select serialnumber } -ComputerName (Get-ADComputer -Server [domain I care about] -filter 'name -Like "[types of computers I care about]"' | Select-Object -expand Name)
Even when run locally, Get-WmiObject Win32_ComputerSystem | Select Model ; Get-WmiObject win32_SystemEnclosure | Select serialnumber only returns the first command. I've tried swapping them around and the first command executes, while the second does not. Some of my colleagues report that it works just fine for them, others see the same result as me, and it doesn't seem to be a version issue, as one of the people for whom this works is running the same version of PowerShell as I am. (5.0.10240.16384)
Screenshot below of a few different command combinations. Anyone have any idea what's going on here?
If you change the list in the select-object cmdlets so both include the properties output by each, you will get the result you want (I think).
Invoke-Command -ScriptBlock { Get-WmiObject Win32_ComputerSystem | Select Model,SerialNumber ; Get-WmiObject win32_SystemEnclosure | Select model,serialnumber } -ComputerName localhost
That will get you output to the screen which should include all of the info. If you just want objects you can just capture the output and see that all of the properties are there.
$objects=Invoke-Command -ScriptBlock { Get-WmiObject Win32_ComputerSystem | Select Model ; Get-WmiObject win32_SystemEnclosure | Select serialnumber } -ComputerName (Get-ADComputer -Server [domain I care about] -filter 'name -Like "[types of computers I care about]"' | Select-Object -expand Name)
If you execute $objects | format-list * you will see that you have two objects, one with a Model and one with a SerialNumber.
Outputting different objects to a single CSV is another issue altogether. You get columns in the CSV based on the properties in the first object, so you will lose the SerialNumber property in the CSV.
I am running the following query to get the video driver version number
Get-WmiObject Win32_videoController | where {$_.Name -like "Nvidia*"} | Format-table -HideTableHeaders DriverVersion
It returns the data I want plus about 4 extra lines. One before the output and 3 after. It doesn't look like it's going to show up properly in the post.
PS F:\>
Get-WmiObject Win32_videoController | where {$_.Name -like "Nvidia*"} | Format-table -HideTableHeaders DriverVersion
9.18.13.3250
PS F:\>
If you want to determine the driver version, forget about Format-Table. Simply do this:
Get-WmiObject Win32_VideoController -Filter "Name LIKE 'Nvidia%'" |
Select-Object -Expand DriverVersion
Note: You can also use the aliases gwmi for Get-WmiObject and select for Select-Object. Beware, though, that aliases may not be present during script execution depending on your environment. They're basically a means to reduce the amount of typing required in an interactive console.
Not sure exactly if this is what you want but give this a try.
This will only display the "Unique" driver versions. This will get rid of the dupe entrys
Get-WmiObject Win32_videoController | Where {$_.Name -like "Nvidia*"} | Select-Object DriverVersion -Unique | Format-Table -HideTableHeaders