powershell

The following powershell command will return make and serial number of a monitor connected to the computer. gwmi WmiMonitorID -Namespace root\wmi | ForEach-Object {($_.UserFriendlyName -ne 0 | foreach {[char]$_}) -join “”; ($_.SerialNumberID -ne 0 | foreach {[char]$_}) -join “”} Reference: WmiMonitorID class – Win32 apps | Microsoft Docs

Read More Get monitor make and serial number command line

Input line: Thu 2017-03-30 00:00:07: user@domain.com (John Doe) checked mail from 127.0.0.1 using IMAP, 0 msgs collected, 21 remaining Powershell script: $rxp = “([a-z0-9!#$%&’*+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&’*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)|(d{1,3}.d{1,3}.d{1,3}.d{1,3})|(POP|IMAP)|(^[A-Z][a-z]+sd{4}-d{2}-d{2}sd{2}:d{2}:d{2})” gc “.*.log” | select-string -pattern $rxp -allmatches | foreach { if ($_.Matches.count -ne 4) { return } [pscustomobject]@{ ‘date’=$_.Matches[0] ’email’=$_.Matches[1] ‘ipaddr’=$_.Matches[2] ‘proto’=$_.Matches[3] } } | export-csv -notype analysis.csv

Read More Powershell logparse regexp to csv

Continuing with learning some Powershell, I cooked this up which will connect to the vCenter server and get all the VM’s and list the name, operating system and power state. foreach ($vm in get-vm) { $os=get-vmguest -vm $vm.name | where-object {$_.osfullname -ne $null} | select osfullname; write-host ($vm.name.tostring() + “,” + $os.osfullname + “,” +…

Read More Get All Virtual Machine Guest OS in Powershell

Clear Powershell’s last 10 commands: clear-history -count 10 -newest After executing that, use get-history to see what’s left… Clear the console buffer by scripting F7+2: [system.reflection.assembly]::loadwithpartialname(“System.Windows.Forms”) [System.Windows.Forms.SendKeys]::Sendwait(‘%{F7 2}’) Try using the Up key to cycle through history — won’t happen.

Read More Clearing Command and Buffer History in Powershell