Test-Netconnection from a list.
$complist = Get-Content "C:\scraps\lists\ff-108.txt"
foreach($item in $complist){
$pingtest = Test-Connection -ComputerName $item -Quiet -Count 1 -ErrorAction SilentlyContinue
if($pingtest){
Write-Host($item + " is online")
}
else{
Write-Host($item + " is not reachable")
}
}
From the Registry — Checking both keys for software
$INSTALLED = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, UninstallString
$INSTALLED += Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, UninstallString
$INSTALLED | ?{ $_.DisplayName -ne $null } | sort-object -Property DisplayName -Unique | Format-Table -AutoSize
Then load those results and search for firefox
$SEARCH = 'firefox'
$RESULT =$INSTALLED | ?{ $_.DisplayName -ne $null } | Where-Object {$_.DisplayName -match $search }
$RESULT
Examples from the web
To fetch CPU utilization
$Processor = (Get-WmiObject -ComputerName $Exchserver -Class win32_processor -ErrorAction Stop | Measure-Object -Property LoadPercentage -Average | Select-Object Average).Average
To fetch memory utilization
$ComputerMemory = Get-WmiObject -ComputerName $Exchserver -Class win32_operatingsystem -ErrorAction Stop
$Memory = ((($ComputerMemory.TotalVisibleMemorySize - $ComputerMemory.FreePhysicalMemory)*100)/ $ComputerMemory.TotalVisibleMemorySize) $RoundMemory = [math]::Round($Memory, 2)
From PDQ
#############################################################################
# Option A: This is if you just have the name of the process; partial name OK
$ProcessName = "cpu"
# Option B: This is for if you just have the PID; it will get the name for you
# $ProcessPID = "6860"
# $ProcessName = (Get-Process -Id $ProcessPID).Name
$CpuCores = (Get-WMIObject Win32_ComputerSystem).NumberOfLogicalProcessors
$Samples = (Get-Counter "\Process($Processname*)\% Processor Time").CounterSamples
$Samples | Select `
InstanceName, @{Name="CPU %";Expression={[Decimal]::Round(($_.CookedValue / $CpuCores), 2)}}
#############################################################################
Testing it
Look to make sure the format is correct for process time. See the example below how it is different to the example above:
(Get-Counter -ListSet Processor).Counter
\Processor(*)\% Processor Time
Run the get-counter with ().counter. Edit the script with the correct processor time from the output.
After modifying for your correct processor time format this is what the output will look like:
InstanceName CPU %
------------ -----
0 7.57
1 9.50
2 8.73
3 13.76
_total 9.89
Misc
system generated total for all processors
Get-Counter '\Processor(*)\% Processor Time' -Continuous |
select -expand CounterSamples |
where{$_.InstanceName -eq '_total'}
extend the pipeline for continuous monitoring
Get-Counter '\Processor(*)\% Processor Time' -Continuous |
select -expand CounterSamples |
where{$_.InstanceName -eq '_total' -and $_.CookedValue -gt 40} |
ForEach{Write-Host $_.CookedValue -fore Red}
(Get-Counter '\Process(*)\% Processor Time').CounterSamples | Where-Object {$_.CookedValue -gt 5}
$CpuCores = (Get-WMIObject Win32_ComputerSystem).NumberOfLogicalProcessors
(Get-Counter "\Process(*)\% Processor Time").CounterSamples | Select InstanceName, @{Name="CPU %";Expression={[Decimal]::Round(($_.CookedValue / $CpuCores), 2)}}
# monitor endlessly for processes exceeding 10% CPU load within 4 seconds
# monitoring interval (in seconds)
[ValidateRange(1,120)][int]$seconds = 4
# minimum percentage per core to report:
[ValidateRange(0,100)][int]$minpercentage = 10
# find out number of logical processors:
$cores = [Environment]::ProcessorCount
# get first snapshot and turn into hashtable with process id as key
# IMPORTANT: make sure the key is of type [int]:
$snap1 = Get-CimInstance -ClassName Win32_PerfRawData_PerfProc_Process | Group-Object -Property { [int]$_.IDProcess } -AsHashTable
# wrapping code into scriptblock so you can optionally
# pipe the results to Export-Csv or Export-Excel...
& {
# monitor endlessly:
While ($true)
{
# wait for the monitoring interval:
Start-Sleep -Seconds $seconds
# get a second snapshot:
$snap2 = Get-CimInstance -ClassName Win32_PerfRawData_PerfProc_Process | Group-Object -Property { [int]$_.IDProcess } -AsHashTable
# get a timestamp for the reporting:
$date = Get-Date -Format 'HH:mm:ss'
# process each process id in the snapshot:
foreach($_ in $snap2.Keys)
{
$id = $_
# ignore idle and system:
if ($id -eq 0) { continue }
try
{
# calculate exact time interval in 100ns units:
$time = $snap2[$id].Timestamp_Sys100NS - $snap1[$id].Timestamp_Sys100NS
# get process name:
$name = $snap2[$id].Name
# calculate total cpu percentage per process:
$percent = ($snap2[$id].PercentProcessorTime - $snap1[$id].PercentProcessorTime)/$time*100
# if below threshold, ignore:
if ($percent -lt $minPercentage) { continue }
}
catch
{
# if there was an error, i.e. newly launched process without previous snapshot, ignore:
continue
}
# return cooked data:
[PSCustomObject]@{
Date = $date
ID = $id
Name = $name
Percent = [Math]::Round( ($percent/$cores),0)
PercentPerCore = [Math]::Round( $percent,0)
}
# use second snapshot as first snapshot in next iteration:
$snap1 = $snap2
}
}
}