I have this part of code -
$result = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |
Select-Object DisplayName, Publisher, InstallDate, UnistallString |
Where-Object InstallDate -GT 20180201 |
Where-Object UnistallDate -NotMatch " " |
Sort-Object -Property InstallDate -Descending |
Format-Table –AutoSize
$result
With the result of this command I get an array of objects, but if I try to access in it I get no result.
Example:
$result.UnisistallString. How can I access in it to get only the attributes of that parameter? Because with that then I need to print on video the name of the program and the unistall path.
You should not use the Format-Table cmdlet if you need to access the data in your code later. Also you have a typo in your example and the select statement. This should work:
$result = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |
Select-Object DisplayName, Publisher, InstallDate, UninstallString |
Where-Object InstallDate -GT 20180201 |
Sort-Object -Property InstallDate -Descending
Now Access it using:
$result.UninstallString
Related
I am planning to extract the CPU details to my powershell requirement. Below is the highlighted parameter that I am trying to extract.
I have tried using Get-WmiObject Win32_Process or Get-Process but no luck with it. Can you guide with the cmdlet which can be helpful for this
Updated Question
Get-Counter '\Process(*)\% Processor Time' |
Select-Object -ExpandProperty countersamples |
Select-Object -Property instancename, cookedvalue|
Sort-Object -Property cookedvalue -Descending |
Select-Object| ft InstanceName,#{L='CPU';E={($_.Cookedvalue/100).toString('P')}} -AutoSize
I am using this code as suggested in the below comments. and below is the output which I am receiving.
However if you compare the value for PS output and the task manager screenshot, its quite different, since in task manager most of them are 0
Updated Part 2
I have extracted this code from another post.
$NumberOfLogicalProcessors=(Get-WmiObject -class Win32_processor | Measure-Object -Sum NumberOfLogicalProcessors).Sum
(Get-Counter '\Process(*)\% Processor Time').Countersamples | Sort cookedvalue -Desc | ft -a instancename, #{Name='CPU %';Expr={[Math]::Round($_.CookedValue / $NumberOfLogicalProcessors)}}
This may be working, but I would like to get your opinions on these since the value for this is dynamic and pretty difficult to verify
try this:
$Utilization = #()
Get-WmiObject Win32_PerfFormattedData_PerfProc_Process | Sort-Object -Property PercentProcessorTime -descending | ? { $_.name -inotmatch '_total|idle' } | % {$Utilization += [PSCustomObject]#{'Process Name' = $_.Name; 'pid' = $_.IDProcess; 'Usage' = $_.PercentProcessorTime}}
I want to filter a command result using two conditions. Here are my commands
$list=Get-PnpDevice | Sort-Object -Property Name | Where-Object -Property ConfigurationFlags -NotLike '*DISABLED*' | ft Name, InstanceId -AutoSize
and the next filter is
$list=Get-PnpDevice | Sort-Object -Property Name | Where-Object -Property FriendlyName -like '*touch screen*' | ft Name, InstanceId -AutoSize
both of them works separately but I want to join them using and command. I tried to use -AND as following command but it keeps raising errors
Get-PnpDevice | Sort-Object -Property Name | Where-Object{
( ConfigurationFlags -NotLike '*DISABLED*') -and
( FriendlyName -like '*touch screen*' ) }| ft Name, InstanceId -AutoSize
Simply use the The $_ automatic variable in your Where-Object to reference the property names:
Get-PnpDevice | Sort-Object -Property Name | Where-Object{
( $_.ConfigurationFlags -NotLike '*DISABLED*') -and
( $_.FriendlyName -like '*touch screen*' ) }| ft Name, InstanceId -AutoSize
You can pipe 'Where' clauses together... it's simpler syntax and easier to read
Get-PnpDevice | Sort-Object -Property Name | Where ConfigurationFlags -NotLike '*DISABLED*' | Where FriendlyName -like '*touch screen*' | ft Name, InstanceId -AutoSize
I need to get a list of locally installed software from a PC.
I'm using the following piece of code for this :
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* |
Select-Object DisplayName, DisplayVersion, Publisher, InstallDate |
Format-Table -AutoSize > app32.txt
Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |
Select-Object DisplayName, DisplayVersion, Publisher, InstallDate |
Format-Table -AutoSize > app64.txt
Then I need a single list of installed software sorted by DisplayName column.
Trying to use:
cat apps*.txt |
where {$_ -ne ""} |
Sort-Object -Property #{Expression="DisplayName"} |
sc all_apps.txt
But in fact the list is not sorted in alphabetic order at column DisplayName and also the result file contains empty strings which should not be included
Don't use Format-Table like that. Format-Table is for presenting information to the user, not presenting information to other commands. It turns the output into a string instead of objects that PowerShell can manipulate.
Try:
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* |
Select-Object DisplayName, DisplayVersion, Publisher, InstallDate |
Export-Csv -Path app32.csv -NoTypeInformation
Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |
Select-Object DisplayName, DisplayVersion, Publisher, InstallDate |
Export-Csv -Path app64.csv -NoTypeInformation
Import-Csv app32.csv, app64.csv |
Where-Object { -not [System.String]::IsNullOrWhitespace($_.DisplayName) } |
Sort-Object -Property DisplayName |
Export-Csv -Path all_apps.csv -NoTypeInformation
Or, alternately:
Get-ItemProperty -Path HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*, HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |
Where-Object { -not [System.String]::IsNullOrWhitespace($_.DisplayName) } |
Sort-Object -Property DisplayName |
Select-Object DisplayName, DisplayVersion, Publisher, InstallDate |
Export-Csv -Path app64.csv -NoTypeInformation
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | export-csv app32.csv -NoTypeInformation
Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | export-csv app64.csv -NoTypeInformation
$softwarelist = import-csv -Path ".\app32.csv"
$softwarelist += import-csv -path ".\app64.csv"
$Softwarelist | Sort-Object -Property DisplayName
Basically I used export-csv instead of just writing it to a txt file, this allows powershell to use import-csv and when it brings it in it recognises the different properties; when it gets the content from a .txt it just reads in a big ol' string.
Using += we can add both files together and then just sort-object on them to display them how you like.
Edit: I should add you could skip writing them out as a CSV and instead just store them in a variable and use that. Something like:
$softwarelist = Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate
$softwarelist += Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate
$Softwarelist | Sort-Object -Property DisplayName
How can I club these two ?
Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*|`
Where-Object {$_.displayname -like "*Database Engine Services*" } | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate |Format-Table -AutoSize
Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate |
Where-Object {($_.displayname -like "*Engagement*") } |`
Format-Table –AutoSize
I went with a RegEx approach to condensing your Where-Object filtering to a single instance, but you could also use -OR to also bring it into a single instance. Also, there is no need to do a Select-Object into a Format-Table as just using Format-Table will let you specify what properties to display.
Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object {
$_.DisplayName -match '^Database Engine Services|Engagement'
} | Format-Table DisplayName, DisplayVersion, Publisher, InstallDate -AutoSize
Here is the alternative using -OR with your -LIKE statement:
Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object {
$_.DisplayName -LIKE 'Database Engine Services*' -OR $_.DisplayName -LIKE '*Engagement*'
} | Format-Table DisplayName, DisplayVersion, Publisher, InstallDate -AutoSize
Get-WmiObject -list | where-object {$_.name -match "win32"} | Select-Object
name,methods,properties
This displays the name, methods and properties of each Win32 class and I wanted to get this information into a CSV file.
The following however outputs doesn't output the same information.
Get-WmiObject -list | where-object {$_.name -match "win32"} | Select-Object
name,methods,properties | Export-CSV "c:\output.csv"
How can I do this?
(Updated my script as it had an error.)
You need to do some extra manual work and make sure you expand the names and join them by some delimiter:
$methods = #{n='Methods';e={ ($_.Methods | select -expand Name) -join ';'}}
$properties = #{n='Properties';e={ ($_.Properties | select -expand Name) -join ';'}}
Get-WmiObject -List |
Where-Object {$_.Name -like "Win32_*"} |
Select-Object Name,$methods,$properties |
Export-Csv .\win32.csv -NoTypeInformation
The problem here is that each WMI Object has properties that themselves are arrays and Output-CSV can't really handle that.
To fix this, you'd need to handle the arrays of arrays explicitly.
WHat specifically do you want to be output?