Differences between revisions 4 and 5
Revision 4 as of 2018-11-01 18:13:28
Size: 866
Editor: scot
Comment:
Revision 5 as of 2018-12-28 04:54:44
Size: 1234
Editor: scot
Comment:
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 27: Line 33:

== Replace a string in a file using a regular expression ==

{{{
$file = "Level13.html"
$fixed = (Get-Content -path $file) | % { $_ -Replace '(https://web.archive.org/nebula/level)([0123456789]{2})/', 'Level$2.html' }
}}}

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

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)}} 

List Memory Installed

Get-WmiObject win32_physicalmemory | Format-Table Manufacturer,Banklabel,Configuredclockspeed,Devicelocator,Capacity,Serialnumber -autosize

List object from Registry - namely version of .NET installed

gci 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' | sort pschildname -des | foreach-object {$_.name; $_.GetValue("Version");}

Remote commands

Invoke-Command -ComputerName eve -ScriptBlock { date }

Replace a string in a file using a regular expression

$file = "Level13.html"
$fixed = (Get-Content -path $file) | % { $_ -Replace '(https://web.archive.org/nebula/level)([0123456789]{2})/', 'Level$2.html' } 

WindowsAdministration/PowerShellScripts (last edited 2024-02-06 23:03:14 by scot)