373
Comment:
|
2098
|
Deletions are marked like this. | Additions are marked like this. |
Line 2: | Line 2: |
For the uninitiated: || Symbol || Meaning || || % || shortcut for foreach object || || $_ || current object in the pipeline || |
|
Line 5: | Line 11: |
{{{ Get-ADUser -Filter * -SearchBase "dc=home,dc=scotnpatti,dc=com" -ResultPageSize 0 -Prop CN,samaccountname,lastLogonTimestamp | select CN, samaccountname,@{n="lastLogonDate";e={[datetime]::FromFileTime($_.LastLogonTimestamp)}} |
{{{#!highlight powershell Get-ADUser -Filter * -SearchBase "dc=home,dc=scotnpatti,dc=com" -ResultPageSize 0 -Prop CN,samaccountname,lastLogonTimestamp | select CN, samaccountname,@{n="lastLogonDate";e={[datetime]::FromFileTime($_.LastLogonTimestamp)}} |
Line 8: | Line 15: |
== List Memory Installed == {{{#!highlight powershell Get-WmiObject win32_physicalmemory | Format-Table Manufacturer,Banklabel,Configuredclockspeed,Devicelocator,Capacity,Serialnumber -autosize }}} == List object from Registry - namely version of .NET installed == {{{#!highlight powershell gci 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' | sort pschildname -des | foreach-object {$_.name; $_.GetValue("Version");} }}} == Remote commands == {{{#!highlight powershell Invoke-Command -ComputerName eve -ScriptBlock { date } }}} == Replace a string in a file using a regular expression == So I downloaded a bunch of files from "the way back machine" site and I needed to update the hard-coded links to be relative site links. The following little script did it for me. {{{#!highlight powershell $files = ls Level*.html foreach ($item in $files) { (Get-Content -path $item) | % { $_ -Replace '(https://web.archive.org/nebula/level)([0123456789]{2})/', 'Level$2.html' } | Set-Content $item } }}} == Get a list of Virtual Machines that have a DVD attached == I needed this once when I was trying to refresh the Library share. It failed on refresh with an error saying that a DVD was in use and wouldn't refresh until it was no longer in use. The following commands allowed me to identify the machines. {{{#!highlight powershell Get-SCVMMServer -ComputerName Samuel Get-SCVirtualMachine | Get-SCVirtualDVDDrive | Where-Object {$_.Connection -eq "ISOImage"} | Select Name, Connection, ISO }}} |
Here is a list of Power Shell Scripts that are too cool to ignore
For the uninitiated:
Symbol |
Meaning |
% |
shortcut for foreach object |
$_ |
current object in the pipeline |
List of AD accounts and the last time they logged in
List Memory Installed
1 Get-WmiObject win32_physicalmemory | Format-Table Manufacturer,Banklabel,Configuredclockspeed,Devicelocator,Capacity,Serialnumber -autosize
List object from Registry - namely version of .NET installed
1 gci 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' | sort pschildname -des | foreach-object {$_.name; $_.GetValue("Version");}
Remote commands
1 Invoke-Command -ComputerName eve -ScriptBlock { date }
Replace a string in a file using a regular expression
So I downloaded a bunch of files from "the way back machine" site and I needed to update the hard-coded links to be relative site links. The following little script did it for me.
Get a list of Virtual Machines that have a DVD attached
I needed this once when I was trying to refresh the Library share. It failed on refresh with an error saying that a DVD was in use and wouldn't refresh until it was no longer in use. The following commands allowed me to identify the machines.