How to list all attributes of "-class" in powershell - powershell

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

Related

filter Get-Service by username

I'm trying to get all the services that run under the user system, but just them (not from other users). I don't find a way to filter the result by the user name.
I tried many options, include Get-WmiObject.
Is there a command or a parameter like -IncludeUserName (Works with Get-Process) that makes it possible?
Thank you
Property called StartName is the username
below will filter out StartName = LocalSystem
Get-WmiObject -Class Win32_Service | Where-Object {$_.StartName -eq 'LocalSystem'}

When does PowerShell filter results when using a Property flag?

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

Get-WmiObject from AD OU

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.

Powershell - get the output from this Get-WmiObject command (getting the number of cores using powershell)

So my aim is to get the number of cores on the machine my powershell script runs on and work with it as an integer. Some googleing lead me to this nice and simple command to get the number of cores:
Get-WmiObject -Class Win32_ComputerSystem | fl NumberOfLogicalProcessors
Which displays an output like this:
NumberOfLogicalProcessors : 4
Now my issue is, how so I extract the number "4" from this? I tried .Split(":") but the output is not a string so that doesn't work. Next I tried
PS C:\Windows\system32> Get-WmiObject -Class Win32_ComputerSystem | fl NumberOfLogicalProcessors | select NumberOfLogicalProcessors
But this just yields:
"NumberOfLogicalProcessors
--------------------------------------"
Not helpful. What am I missing? What is this Get-WmiObject returning and how do I work with it?
Edit:
Thank you mhu, that did the trick!
Don't use Format-List (fl), but directly select the required property, like this:
Get-WmiObject -Class Win32_ComputerSystem | select "NumberOfLogicalProcessors" -ExpandProperty "NumberOfLogicalProcessors"
As said by Mike, you could shorten this to:
Get-WmiObject -Class Win32_ComputerSystem | select -ExpandProperty "NumberOfLogicalProcessors"

How to remove extra lines from Get-WMIObject output powershell

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