How to remove extra lines from Get-WMIObject output powershell - 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

Related

Powershell command to delete everything that starts with _

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 *

Get-WmiObject -Class Win32_Product - showing wrong version of program

Get-WmiObject -Class Win32_Product | where-object { $_.name -like "*OfficeScan*" }
Shows me the wrong version number of the TrendMicro OfficeScan Client - the default Version 12.0.1222 when the installed version is 12.0.4430.
I also tried:
Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate
There it doesnt show up at all. It's weird because in the old systemcontrol if i go to deinstallation it shows the correct version:
So I need to somehow extract the information of the actual version to my powershell. I need it for a auto update feature, it has to be using powershell.
Assuming you're using a 64bit system, you're looking in the wrong place in the registry.
I don't have TrendMicro, so using Adobe Reader as an example:
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* |
Where-Object { $_.DisplayName -like "*Adobe Reader*" } |
Select-Object DisplayName, DisplayVersion
If you just want a numerical Version property to use as a comparison, update:
Select-Object -Expand DisplayVersion

How to list all attributes of "-class" in 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

how do i out put from AD or txt

I am trying to run this programme against a a list of remote pc/servers either by AD out TXT and display them in either csv or html if any one can offer some help or advise I would be greatly appreciative.
My only limitation is all my machines run powershell v2 only
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate |
Format-Table –AutoSize
You want to take the output of that command and put it in a file? PowerShell has a lot of tools to do this. However, you need to remove the Format-Table command first.
See, Format-Table is all about making your command output look really good in a PowerShell window, so it's got a lot of hard returns and columns and things defined in it which make sense to the console, but look like garbage when you export it.
For data like this, I think Comma Separated Value is probably the way to go.
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* |
Select-Object DisplayName, DisplayVersion, Publisher, InstallDate |
Export-CSV -NoTypeInfo -Path \\server\share\$($env:ComputerName)_Programs.csv
This example will export a CSV, omitting the import-helper info PowerShell normally adds, using the -NoTypeInformation switch. I figured it'd be useful to know the name of the computer which made the file, so that's just what it will do. Edit -Path to point to a server with a share and away you go. You'll end up with files like this:
ComputerA_Programs.Csv
ComputerB_Programs.Csv
ComputerC_Programs.Csv
If you want to pull from all Ad computers
ForEach ($COMPUTER in (Get-ADComputer -Filter * | Select-Object -ExpandProperty Name))
{if(!(Test-Connection -Cn $computer -BufferSize 16 -Count 1 -ea 0 -quiet))
{write-host "cannot reach $computer" -f red}
else{Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate |
Export-CSV -NoTypeInfo -Path "\\server\share$\$Computer_Programs.csv" -NoTypeInformation}}
for if you have list of computers in text
Foreach ($computer in ($computers= Get-Content "c:\Computers.txt" ))
{if(!(Test-Connection -cn $computer -BufferSize 16 -Count 1 -ea 0 -quiet))
{write-host "cannot reach $computer" -f red}
else{
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate |
Export-CSV -NoTypeInfo -Path "\\server\share$\$Computer_Programs.csv" -NoTypeInformation
}}

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"