Differences between revisions 5 and 7 (spanning 2 versions)
Revision 5 as of 2018-12-28 04:54:44
Size: 1234
Editor: scot
Comment:
Revision 7 as of 2018-12-28 05:12:15
Size: 1580
Editor: scot
Comment:
Deletions are marked like this. Additions are marked like this.
Line 11: Line 11:
{{{ {{{#!highlight powershell
Line 17: Line 17:
{{{ {{{#!highlight powershell
Line 24: Line 24:
{{{ {{{#!highlight powershell
Line 30: Line 30:
{{{ {{{#!highlight powershell
Line 36: Line 36:
{{{
$file = "Level13.html"
$fixed = (Get-Content -path $file) | % { $_ -Replace '(https://web.archive.org/nebula/level)([0123456789]{2})/', 'Level$2.html' }
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
}

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

   1 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

   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.

   1 $files = ls Level*.html
   2 foreach ($item in $files) {
   3     (Get-Content -path $item) | % { $_ -Replace '(https://web.archive.org/nebula/level)([0123456789]{2})/', 'Level$2.html' } | Set-Content $item
   4 } 

WindowsAdministration/PowerShellScripts (last edited 2024-08-30 00:21:07 by scot)