- <#
- .SYNOPSIS
- Creates a new Event Log
- .DESCRIPTION
- This script first checks to see if a log called NewPSHLog exists. if not, it creates
- it then exits. if the log exists, the script writes an entry ot the log and then
- displays the log entries. A separate script clears and deletes the log!
- .NOTES
- File Name : New-CustomEventLog.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell V2 CTP3
- .LINK
- Script posted to:
- http://www.pshscripts.blogspot.com
- .EXAMPLE
- First time the script runs:
- PSH [C:\foo]: .\New-CustomEventLog.ps1'
- CreatedEventSource
- Exiting, execute the script a second time to use the source.
- Second time the script runs:
- PSH [C:\foo]: .\New-CustomEventLog.ps1'
- PowerShell Eventlog exists
- Index Time EntryType Source InstanceID Message
- ----- ---- --------- ------ ---------- -------
- 12 Feb 22 16:11 Information NewPshLog 0 Writing to new PowerShell even...
- #>
- ###
- # Start of Script
- ###
- if (![system.diagnostics.eventlog]::SourceExists("NewPSHLog")) {
- # An event log source should not be created and immediately used.
- # There is a latency time to enable the source, it should be created
- # prior to executing the application that uses the source.
- # So let's execute this sample a second time to use the new source.
- [system.diagnostics.EventLog]::CreateEventSource("MySource", "NewPSHLog")
- "CreatedEventSource"
- "Exiting, execute the script a second time to use the source."
- # The source is created. Exit the application to allow it to be registered.
- return
- }
- else {
- "NewPSHLog Eventlog exists"
- }
- # With log created, create an EventLog instance and assign its source.
- $mylog = new-object System.diagnostics.Eventlog
- $myLog.Source = "NewPshLog"
- # Write an informational entry to the event log.
- $myLog.WriteEntry("Writing to new PowerShell event log.")
- # Display log events
- get-eventlog "NewPSHLog"
- # End of Script
This blog contains PowerShell scripts, more PowerShell scripts and still more PowerShell scripts. Occasionally you may see some organisational posts.
Monday, 23 February 2009
New-CustomEventLog.ps1
Sunday, 22 February 2009
Get-MachineConfig
- <#
- .SYNOPSIS
- Displays summary of machine.config
- .DESCRIPTION
- This script is a re-write of an MSDN sample which fetchs the machine.config
- file, prints out file path, and key sections. Also shows how many sections
- exist in the machine.config file. Also fixed errors in original C# code
- and improved the layout of the results a bit.
- .NOTES
- File Name : get-machineconfig.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell V2 CTP3
- .LINK
- Updated Powershell script posted to:
- http://pshscripts.blogspot.com/2009/02/get-machineconfig.html
- MSDN Sample at:
- http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.openmachineconfiguration(VS.80).aspx
- .EXAMPLE
- PSH [C:\foo]: .\get-machinefoncif.ps1
- File path: C:\Windows\Microsoft.NET\Framework\v2.0.50727\Config\machine.config
- Name Allow Definition
- ---- ----------------
- system.data MachineToApplication
- windows MachineToApplication
- system.webServer MachineToApplication
- mscorlib MachineToApplication
- system.data.oledb MachineToApplication
- system.data.oracleclient MachineToApplication
- system.data.sqlclient MachineToApplication
- configProtectedData MachineToApplication
- satelliteassemblies MachineToApplication
- system.data.dataset MachineToApplication
- startup MachineToApplication
- system.data.odbc MachineToApplication
- system.diagnostics MachineToApplication
- runtime MachineToApplication
- system.codedom MachineToApplication
- system.runtime.remoting MachineToApplication
- connectionStrings MachineToApplication
- assemblyBinding MachineToApplication
- appSettings MachineToApplication
- system.windows.forms MachineToApplication
- Total number of sections: 20
- #>
- ###
- # Start of Script
- # Get the machine.config file.
- ####
- # Get config file
- $config = [System.Configuration.ConfigurationManager]::OpenMachineConfiguration()
- #Display machine.config path.
- "";"File path: {0}" -f $config.FilePath; ""
- # Loop to get the sections and display basic information.
- "{0,-25} {1,25}" -f " Name", " Allow Definition"
- "{0,-25} {1,25}" -f " ----", " ----------------"
- $i = 0
- foreach ($section in $config.Sections) {
- "{0,-25} {1,25}" -f $section.SectionInformation.Name,$section.SectionInformation.AllowExeDefinition
- $i++
- }
- # Display total sections
- "Total number of sections: {0}" -f $i
Saturday, 7 February 2009
Disable-NetworkCard.ps1
- <#
- .SYNOPSIS
- Disables active network cards
- .DESCRIPTION
- This script looks at each network card that is currently IP enabled, and
- disables it by releasing the DHCP Lease. To re-enable the network interrace,
- you just run IPCONFIG /RENEW.
- This script is an MSDN Sample, rewritten using PowerShell
- .NOTES
- File Name : Disable-NetworkCard.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell V2 CTP3
- .LINK
- PowerShell script posted to:
- http://pshscripts.blogspot.com/2009/02/disable-networkcardps1.html
- Original MSDN Sample at:
- http://msdn.microsoft.com/en-us/library/aa394595(VS.85).aspx
- .EXAMPLE
- PSH [C:\foo]: .\Disable-NetworkCard.ps1
- Releasing lease on: [00000006] Broadcom NetXtreme Gigabit Ethernet
- Releasing lease on: [00000012] Microsoft Virtual Network switch Adapte
- #>
- ###
- # Starting Script
- ###
- $Computer = "."
- $net = Get-WMIObject -class Win32_NetworkAdapterConfiguration -ComputerName $computer
- $netenabled = $net | where {$_.IPenabled}
- foreach ($NetCard in $netenabled) {
- "Releasing lease on: {0}" -f $netcard.caption
- $netcard.ReleaseDHCPLease()
- }
- # End of Script
Wednesday, 4 February 2009
PowerShellPlus v2.1 Beta
This is sort of exciting - PowerShellPlus v2.1 Beta is live! I’ve used PowerShell Plus for some time and love it. But there are things that I’d like to see, in particular the CTP3 support. Well, now we have that – and I’m downloading it as I write this post. The features in 2.1 that catch my eye are: VBS support, STA MOde, Code Sharing and of course, CTP3 support. I’ll be posting more once I have the code running and have a chance to give it a good test!
Monday, 2 February 2009
Updates on A Grateful Dead PowerShell Script
I really love mixing two of my favourite things: the good old Grateful Deal and PowerShell. I’ve posted a couple of scripts that examine my live show archive. Yesterday, I was able to spend some time updating my Count-GDSHows script. In Count-GDShows2.ps1, I added a couple of features. First I worked out how many shows are recording using the SHN format and how many in FLAC (plus how many are not noted in the folder name). Second, I timed the script, although the timing varies widely thanks to disk caching!
My GD (and my Jerry Garcia) archive is stored on a couple of external USB disks. I have separated Jerry shows from GD shows and have both stored on disks plugged into separate machines. I use the folder name of each show to define the date, type (aud vs sbd) and encoding format. So a show in “gd69-04-22.sbd.clugston.68.sbeok.shnf” is a soundboard encoded in the Shorten format, for a show on April 22 1969. Were you even alive then?
I wonder how many of this blog’s readers collect Grateful Dead shows? I have a standing offer that I’ll repeat: If you want the shows in my collection, send me a big disk and I’ll xcopy!
Sunday, 1 February 2009
Count-GDShows2.ps1
- <#
- .SYNOPSIS
- Counts the Grateful Dead shows in my archives and displays
- details of the collection.
- .DESCRIPTION
- This script looks at my GD archive, and uses folder names to
- determine show type (aud, sbd, etc), and checks to see what
- shows have checked MD5s. The script also times itself.
- This is an update to an earlier script that adds separate
- counts for FLAC and SHN shows.
- .NOTES
- File Name : Count-GDShows2.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell V2 CTP3
- .LINK
- http://pshscripts.blogspot.com/2009/02/count-gdshows2ps1.html
- .EXAMPLE
- PS C:\foo> Count-GDShows2.ps1
- Count.ps1 - v 2.0.2
- +---------------------------+
- ! Dead Show Base : M:\gd !
- +---------------------------+
- Grateful Dead Show Summary
- --------------------------
- Total shows: 1146
- Soundboards: 800
- Auds : 70
- Unknown : 29
- Partial : 9
- SHN : 962
- FLAC : 137
- No coding : 47
- Broken : 4
- MD5's check: 489 (42.67 %)
- It took 0 minutes, 1 seconds
- #>
- ###
- # Start of Archive
- ##
- # Constants:
- # $GDDiskRoot - where to find shows
- # $DeadShowBase - folder at top of gd shows
- $GDDiskRoot = "M:"
- $DeadShowBase = $GDDiskRoot + "\gd"
- # Announce Ourselves
- "Count.ps1 - v 2.0.2"
- "+---------------------------+"
- "! Dead Show Base : $DeadShowBase !"
- "+---------------------------+"
- ""
- # Get start time
- $starttime = Get-Date
- # Count the Dead shows
- $Dir= ls $DeadShowBase | where {$_.psiscontainer}
- $DeadShows=$Dir.count
- if ($DeadSHows -le 0) {"no shows found - check constants"}
- #Create subsets based on names of the folders
- $deadsbds = $dir | where {$_.name -match ".sbd" }
- $deadbrkn = $dir | where {$_.name -match "broken" }
- $deadpart = $dir | where {$_.name -match "partial" }
- $deadauds = $dir | where {$_.name -match ".aud" }
- $deadunkw = $dir | where {$_.name -match ".unk"}
- # workout recording type
- $deadshn = $dir | where {$_.name -match ".shn"}
- $deadflac = $dir | where {$_.name -match ".flac"}
- $deadnocoding = $dir | where {$_.name -notmatch ".shn" -and $_.name -notmatch ".flac"}
- #and see how many have the md5ok's file?
- $DeadMD5Checked=0
- foreach ($d in $dir)
- {
- $sn=$d.fullname + "\md5check_ok"
- $md5ok= ls $sn -ea silentlycontinue
- if ($md5ok )
- {$DeadMD5Checked++}
- }
- # Get finishtime and calc elapsed
- $finishtime=Get-Date
- $executiontime = $finishtime - $starttime
- $min = $executiontime.minutes
- $sec = $executiontime.seconds
- #Display results
- "Grateful Dead Show Summary"
- "--------------------------"
- "Total shows: $deadshows"
- "Soundboards: $($deadsbds.count)"
- "Auds : $($deadauds.count)"
- "Unknown : $($deadunkw.count)"
- "Partial : $($deadpart.count)"
- "SHN : $($deadshn.count)"
- "FLAC : $($deadflac.count)"
- "No coding : $($deadnocoding.count)"
- "Broken : $($deadbrkn.count)"
- $DeadPctChecked=($DeadMD5checked/$DeadShows).tostring("P")
- "MD5's check: $DeadMD5checked ($DeadPctChecked)"
- "It took {0} minutes, {1} second(s)" -f $min,$sec
- ""