- <#
- .SYNOPSIS
- This script displays the Windows Color dialog box, then
- displays the r, g, b values of the colours selected
- .DESCRIPTION
- This script calls windows.forms to show the color dialog. You then
- select a colour, and hit OK. The script then displays the values you selected.
- .NOTES
- File Name : Get-ColourRGB.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://pshscripts.blogspot.com/2010/09/get-colourrgbps1.html
- #>
- # Define worker function
- function Get-ColourRGB {
- param(
- $R = 0, # Red value
- $G = 0, # Green value
- $B = 0 # Blue value
- )
- # Show colour dialog, get colour
- $colorDialog = New-Object Windows.Forms.ColorDialog -Property @{
- FullOpen = $true
- Color = [Drawing.Color]::FromArgb($R,$G,$B)
- }
- if ($colorDialog.ShowDialog() -eq "OK") {
- $R = $colordialog.color.R
- $G = $colordialog.color.G
- $B = $colordialog.color.B
- $R;$G;$B
- }
- }
- # Call the worker function
- $R1,$G1,$B1 = Get-ColourRGB 128 128 128
- # Describe
- " You set:"
- " R to: {0}" -f $R1
- " G to: {0}" -f $G1
- " B to: {0}" -f $B1
This blog contains PowerShell scripts, more PowerShell scripts and still more PowerShell scripts. Occasionally you may see some organisational posts.
Saturday, 18 September 2010
Get-ColourRGB.ps1
Labels:
ColorDialog,
powershell,
PowerShell scripts,
Windows.Forms
Friday, 17 September 2010
Get-ArrayList2.ps1
- <#
- .SYNOPSIS
- This script demonstrates using an ArrayList
- .DESCRIPTION
- This script re-implements an MSDN Sample using
- a System.Collection.ArrayList
- .NOTES
- File Name : Get-Arraylist2.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN sample posted tot:
- http://msdn.microsoft.com/en-us/library/system.collections.arraylist.insert.aspx
- .EXAMPLE
- Left as an exercise for the reader!
- #>
- $myAL = New-Object system.Collections.ArrayList
- $myAL.Insert( 0, "The" )
- $myAL.Insert( 1, "fox" )
- $myAL.Insert( 2, "jumps" )
- $myAL.Insert( 3, "over" )
- $myAL.Insert( 4, "the" )
- $myAL.Insert( 5, "dog" )
- # Create and initializes a new Queue.
- $myQueue = New-Object system.Collections.Queue
- $myQueue.Enqueue( "quick" )
- $myQueue.Enqueue( "brown" )
- # Displays the ArrayList and the Queue.
- "The ArrayList initially contains the following:"
- $myAL
- "The Queue initially contains the following:"
- $myQueue
- # Copy the Queue elements to the ArrayList at index 1.
- $myAL.InsertRange( 1, $myQueue )
- # Displays the ArrayList.
- "After adding the Queue, the ArrayList now contains:"
- $myAL
- # Search for "dog" and add "lazy" before it.
- $myAL.Insert( $myAL.IndexOf( "dog" ), "lazy" )
- # Display the ArrayList.
- "After adding `"lazy`", the ArrayList now contains:"
- $myAL
- # Add "!!!" at the end.
- $myAL.Insert( $myAL.Count, "!!!" )
- # Display the ArrayList.
- "After adding `"!!!`", the ArrayList now contains:"
- $myAL
- # Inserting an element beyond Count throws an exception.
- try {
- $myAL.Insert( $myAL.Count+1, "anystring" )
- }
- catch {
- "Exception: " + $Error[0]
- }
Thursday, 16 September 2010
Get-ArrayList.ps1
- <#
- .SYNOPSIS
- This script demonstrates the use of the Systems.Collections.Arraylist class
- .DESCRIPTION
- This script is a re-write of an MSDN sample script
- .NOTES
- File Name : get-arraylist.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://pshscripts.blogspot.com/2010/09/get-arraylistps1.html
- MSDN sample posted tot:
- http://msdn.microsoft.com/en-us/library/system.collections.arraylist.aspx
- .EXAMPLE
- PSH [C:\foo]: .\Get-ArrayList.ps1
- 0
- 1
- 2
- myAL
- Count : 3
- Capacity : 4
- Fixed Len? : False
- Read only? : False
- Values :
- Hello
- World
- !
- #>
- # Creates and initializes a new ArrayList.
- $myAL = New-Object System.Collections.ArrayList
- # Add three values
- $myAL.Add("Hello")
- $myAL.Add("World")
- $myAL.Add("!")
- # Display the properties and values of the ArrayList.
- "myAL"
- "Count : {0}" -f $myAL.Count
- "Capacity : {0}" -f $myAL.Capacity
- "Fixed Len? : {0}" -f $myAL.IsFixedSize
- "Read only? : {0}" -f $myAL.IsReadOnly
- "Values :"
- $myAL
Thursday, 2 September 2010
Get-UmAlQuraCalendar.ps1
- <#
- .SYNOPSIS
- This script displays details of a UmAlQura Calendar in PowerShell
- .DESCRIPTION
- This script shows the various aspects of this calendar including key properties,
- fields and selected methods.
- .NOTES
- File Name : Get-UmAlQuraCalendar.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN Sample posted at:
- http://msdn.microsoft.com/en-us/library/system.globalization.umalquracalendar.aspx
- .EXAMPLE
- PSH [C:\foo]: .\Get-UmAlQuraCalendar.ps1'
- Um Al Qura Calendar
- Algorithm Type : LunarCalendar
- Eras in Calendar : 1
- Is read only? : False
- Max Supported Date/Time : 5/13/2029 11:59:59 PM
- Min Supported Date/Time : 4/30/1900 12:00:00 AM
- Two Digit Year Max : 1451
- April 3, 2002 of the Gregorian calendar equals the following in the UmAlQura calendar:
- Era: 1
- Year: 1423
- Is Leap Year? False
- Days In Year: 354
- Month: 1
- Months in Year: 12
- Days in Month: 29
- Leap Month: 0
- DayOfYear: 20
- DayOfMonth: 20
- DayOfWeek: Wednesday
- After adding two years and ten months and one day:
- Era: 1
- Year: 1425
- Is Leap Year? True
- Days In Year: 355
- Month: 11
- Months in Year: 12
- Days in Month: 30
- Leap Month: 0
- DayOfYear: 317
- DayOfMonth: 21
- DayOfWeek: Sunday
- #>
- # Helper Function
- Function DisplayValues {
- param ($MyCal, $MyDT )
- " Era: {0}" -f $MyCal.GetEra($MyDT)
- " Year: {0}" -f $MyCal.GetYear($MyDT)
- " Is Leap Year? {0}" -f $MyCal.IsLeapYear($MyCal.GetYear($MyDT))
- " Days In Year: {0}" -f $MyCal.GetDaysInYear($MyCal.GetYear($MyDT))
- " Month: {0}" -f $MyCal.GetMonth($MyDT)
- " Months in Year: {0}" -f $MyCal.GetMonthsInYear($MyCal.GetYear($MyDT))
- " Days in Month: {0}" -f $MyCal.GetDaysInMonth($MyCal.GetYear($MyDT), $MyDT.Month)
- " Leap Month: {0}" -f $MyCal.GetLeapMonth($MyCal.GetYear($MyDT))
- " DayOfYear: {0}" -f $MyCal.GetDayOfYear($MyDT)
- " DayOfMonth: {0}" -f $MyCal.GetDayOfMonth($MyDT)
- " DayOfWeek: {0}" -f $MyCal.GetDayOfWeek($MyDT)
- ""
- }
- # Sets a DateTime to April 3, 2002 of the Gregorian calendar.
- $MyDT = New-Object System.DateTime 2002, 4, 3, (New-Object System.Globalization.GregorianCalendar)
- # Creates an instance of the UmAlQuraCalendar.
- $MyCal = New-Object System.Globalization.UmAlQuraCalendar
- # Display properties of the calendar
- "Um Al Qura Calendar"
- "Algorithm Type : {0}" -f $MyCal.AlgorithmType
- "Eras in Calendar : {0}" -f $MyCal.Eras.count
- "Is read only? : {0}" -f $MyCal.IsReadOnly
- "Max Supported Date/Time : {0}" -f $MyCal.MaxSupportedDateTime
- "Min Supported Date/Time : {0}" -f $MyCal.MinSupportedDateTime
- "Two Digit Year Max : {0}" -f $MyCal.TwoDigitYearMax
- ""
- # Display the values of the DateTime.
- "April 3, 2002 of the Gregorian calendar equals the following in the UmAlQura calendar:"
- DisplayValues $MyCal $MyDT
- # Adds two years and ten months and one Day.
- $MyDT = $MyCal.AddYears( $MyDT, 2 )
- $MyDT = $MyCal.AddMonths($MyDT, 10 )
- $MyDT = $MyCal.AddDays($MyDT, 1 )
- # Display the values of the DateTime.
- "After adding two years and ten months and one day:"
- DisplayValues $MyCal $MyDT
Wednesday, 1 September 2010
Get-PersianCalendar.ps1
- <#
- .SYNOPSIS
- This script displays details of a Persian calendar in PowerShell
- .DESCRIPTION
- This script re-implements an MSDN C# sample.
- .NOTES
- File Name : Get-PersianCalendar.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://pshscripts.blogspot.com/2010/09/get-persiancalendarps1.html
- MSDN Sample posted at:
- http://msdn.microsoft.com/en-us/library/system.globalization.persiancalendar.aspx
- .EXAMPLE
- PSH [C:\foo]: .\Get-PersianCalendar.ps1
- ................. Today ..........................
- Today is:
- Wednesday, 9/1/2010 03:25:17 PM in the Gregorian calendar.
- Wednesday, 6/10/1389 15:25:17 in the Persian calendar.
- ............... Fields ............................
- PersianEra = 1
- ............... Properties ........................
- Eras:
- era = 1
- Gregorian Date Range Supported by the Persian Calendar:
- From 3/21/0622 12:00:00 AM
- To 12/31/9999 11:59:59 PM
- TwoDigitYearMax = 99
- ............ Selected Methods ......................
- GetDayOfYear: day = 165
- GetDaysInMonth: days = 30
- GetDaysInYear: days = 366
- GetLeapMonth: month = 0
- GetMonthsInYear: months = 12
- IsLeapDay: = False
- IsLeapMonth: = False
- IsLeapYear: 1370 is a leap year = True
- ToFourDigitYear:
- If TwoDigitYearMax = 99, ToFourDigitYear(99) = 99
- If TwoDigitYearMax = 2010, ToFourDigitYear(99) = 1999
- #>
- # Get today's date.
- $Jc = new-object system.Globalization.PersianCalendar
- $ThisDate = [System.DateTime]::Now
- # Display the current date using the Gregorian and Persian calendars.
- "Today is:"
- " {0:dddd}, {0} in the Gregorian calendar." -f $ThisDate
- " {0}, {1}/{2}/{3} {4}:{5}:{6} in the Persian calendar." -f $jc.GetDayOfWeek($thisDate),
- $jc.GetMonth($thisDate),
- $jc.GetDayOfMonth($thisDate),
- $jc.GetYear($thisDate),
- $jc.GetHour($thisDate),
- $jc.GetMinute($thisDate),
- $jc.GetSecond($thisDate)
- # Fields
- "............... Fields ............................"
- "PersianEra = {0}" -f [System.Globalization.PersianCalendar]::PersianEra
- # Properties
- "............... Properties ........................"
- "Eras:"
- foreach ($era in $jc.Eras){
- " era = {0}" -f $era
- }
- "Gregorian Date Range Supported by the Persian Calendar:"
- " From {0:G}" -f $jc.MinSupportedDateTime
- " To {0:G}" -f $jc.MaxSupportedDateTime
- "TwoDigitYearMax = {0}" -f $jc.TwoDigitYearMax
- # Methods
- "............ Selected Methods ......................"
- "GetDayOfYear: day = {0}" -f $jc.GetDayOfYear($thisDate)
- "GetDaysInMonth: days = {0}" -f $jc.GetDaysInMonth($thisDate.Year, $thisDate.Month,
- [System.Globalization.PersianCalendar]::PersianEra)
- "GetDaysInYear: days = {0}" -f $jc.GetDaysInYear($thisDate.Year, [System.Globalization.PersianCalendar]::PersianEra)
- "GetLeapMonth: month = {0}" -f $jc.GetLeapMonth($thisDate.Year, [System.Globalization.PersianCalendar]::PersianEra)
- "GetMonthsInYear: months = {0}" -f $jc.GetMonthsInYear($thisDate.Year,[System.Globalization.PersianCalendar]::PersianEra)
- "IsLeapDay: = {0}" -f $jc.IsLeapDay($thisDate.Year, $thisDate.Month, $thisDate.Day,
- [System.Globalization.PersianCalendar]::PersianEra)
- "IsLeapMonth: = {0}" -f $jc.IsLeapMonth($thisDate.Year, $thisDate.Month,
- [System.Globalization.PersianCalendar]::PersianEra)
- "IsLeapYear: 1370 is a leap year = {0}" -f $jc.IsLeapYear(1370, [System.Globalization.PersianCalendar]::PersianEra)
- # Get the 4-digit year for a year whose last two digits are 99. The 4-digit year
- # depends on the current value of the TwoDigitYearMax property.
- "ToFourDigitYear:"
- " If TwoDigitYearMax = {0}, ToFourDigitYear(99) = {1}" -f $jc.TwoDigitYearMax, $jc.ToFourDigitYear(99)
- $jc.TwoDigitYearMax = $thisDate.Year
- " If TwoDigitYearMax = {0}, ToFourDigitYear(99) = {1}" -f $jc.TwoDigitYearMax, $jc.ToFourDigitYear(99)
Tuesday, 31 August 2010
Get-Cultures.ps1
- <#
- .SYNOPSIS
- This script displays information of cultures on a system.
- .DESCRIPTION
- This script reimplements an MSDN script using PowerShell. It first
- gets the cultures then displays them
- .NOTES
- File Name : Get-Cultures.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://pshscripts.blogspot.com/2010/08/get-cultures.html
- MSDN sample posted to:
- http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.getcultures.aspx
- .EXAMPLE
- PSH [C:\foo]: .\Get-Cultures.ps1'
- CULTURE ISO ISO WIN DISPLAYNAME NATIVENAME
- af af afr AFK Afrikaans Afrikaans
- am am amh AMH Amharic Amharic
- ar ar ara ARA Arabic Arabic
- arn arn arn MPD Mapudungun Mapudungun
- as as asm ASM Assamese Assamese
- az az aze AZE Azeri Azeri
- az-Cyrl az aze AZC Azeri (Cyrillic) Azeri (Cyrillic)
- az-Latn az aze AZE Azeri (Latin) Azeri (Latin)
- ... snipped to save space!
- #>
- # Get Cultures
- $Cultures = [System.Globalization.CultureInfo]::GetCultures([System.Globalization.CultureTypes]::NeutralCultures)
- # Display header then details
- "CULTURE ISO ISO WIN DISPLAYNAME NATIVENAME"
- foreach ($Ci in $Cultures)
- {
- "{0,-8} {1,-3} {2,-3} {3,-3} {4,-40}{4,-40}" -f $Ci.Name,
- $Ci.TwoLetterISOLanguageName,
- $Ci.ThreeLetterISOLanguageName,
- $Ci.ThreeLetterWindowsLanguageName,
- $Ci.DisplayName,
- $Ci.NativeName
- }
Sunday, 29 August 2010
Get-Time.ps1
- <#
- .SYNOPSIS
- This script converts time to different time zones.
- .DESCRIPTION
- This script re-implements an MSDN sample using PowerShell
- .NOTES
- File Name : Get-Time.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://pshscripts.blogspot.com/2010/08/get-time.html
- MSDN Sample posted at:
- http://msdn.microsoft.com/en-us/library/system.timezoneinfo.findsystemtimezonebyid.aspx
- .EXAMPLE
- PSH [C:\foo]: .\Get-Time.ps1
- Time in GMT Daylight Time zone: 8/29/2010 11:40:50 AM
- UTC Time: 8/29/2010 10:40:50 AM
- Time in Tokyo Daylight Time zone: 8/29/2010 07:40:50 PM
- UTC Time: 8/29/2010 10:40:50 AM
- #>
- # Get local time
- $thisTime = [system.DateTime]::Now
- if ([System.TimeZoneInfo]::Local.IsDaylightSavingTime($thisTime)) {
- $tzn = [System.TimeZoneInfo]::Local.DaylightName }
- else {
- $tzn = [System.TimeZoneInfo]::Local.StandardName
- }
- # Display local Time
- "Time in {0} zone: {1}" -f $tzn, $thisTime
- " UTC Time: {0}" -f [system.TimeZoneInfo]::ConvertTimeToUtc($thisTime, [TimeZoneInfo]::Local)
- # Get Tokyo Standard Time zone
- $tst = [system.TimeZoneInfo]::FindSystemTimeZoneById("Tokyo Standard Time")
- $tstTime = [system.TimeZoneInfo]::ConvertTime($thisTime, [TimeZoneInfo]::local, $tst)
- $tstzn = if ( [System.TimeZoneInfo]::Local.IsDaylightSavingTime($tstTime)) {
- $tst.DaylightName} else {$tst.StandardName}
- # Display Tokyo Time Zone
- "Time in {0} zone: {1}" -f $tstzn,$tstTime
- " UTC Time: {0}" -f [System.TimeZoneInfo]::ConvertTimeToUtc($tstTime, $tst)
Saturday, 28 August 2010
Get-TimeZoneInfoInfo
- <#
- .SYNOPSIS
- This script displays/Uses TimeZoneInfo properties
- .DESCRIPTION
- This script displays the use of all the TimeZoneInfo Properties.
- .NOTES
- File Name : Get-TimeZoneInfoInfo.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://pshscripts.blogspot.com/2010/08/get-timezoneinfoinfo.html
- MSDN Sample posted at:
- http://msdn.microsoft.com/en-us/library/system.timezoneinfo_properties.aspx
- .EXAMPLE
- PSH [C:\foo]: .Get-TimeZoneInfoInfo.ps1'
- Time Zone: (GMT) Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London
- Time zone is 0 hours 0 minutes later than Coordinated Universal Time.
- Current time is 12:22 PM on 8/28/2010 GMT Daylight Time
- Timezone id : GMT Standard Time
- Supports Daylight Saving : True
- Daylight Saving Zone Name: GMT Daylight Time
- Time Zone: (GMT+04:30) Kabul
- Time zone is 4 hours 30 minutes later than Coordinated Universal Time.
- Current time is 12:22 PM on 8/28/2010 Afghanistan Standard Time
- Timezone id : Afghanistan Standard Time
- Supports Daylight Saving : False
- Daylight Saving Zone Name: Afghanistan Daylight Time
- Time Zone: UTC
- Time zone is 0 hours 0 minutes later than Coordinated Universal Time.
- Current time is 12:22 PM on 8/28/2010 UTC
- Timezone id : UTC
- Supports Daylight Saving : False
- Daylight Saving Zone Name: UTC
- #>
- # Display Information About Time Zones
- # Get current date
- $Datenow = Get-Date
- # Display info re Local Time Zone
- $LocalZone = [System.TimeZoneInfo]::Local
- $t1 = [system.Math]::Abs($LocalZone.BaseUtcOffset.Hours)
- $t2 = [System.Math]::Abs($LocalZone.BaseUtcOffset.Minutes)
- $t3 = if ($LocalZone.BaseUtcOffset -ge [System.Timespan]::Zero) {"later"} else {"earlier"}
- $t4 = if ($LocalZone.IsdaylightSavingTime($datenow)) {$Localzone.DaylightName} else {$Localzone.Standardname}
- "Time Zone: {0}" -f $Localzone.Displayname
- " Time zone is {0} hours {1} minutes {2} than Coordinated Universal Time." -f $t1,$t2, $t3
- " Current time is {0:t} on {0:d} {1}" -f $datenow,$t4
- " Timezone id : {0}" -f $LocalZone.Id
- " Supports Daylight Saving : {0}" -f $LocalZone.SupportsDaylightSavingTime
- " Daylight Saving Zone Name: {0}" -f $Localzone.DaylightName
- ""
- # Get Kabul Time
- $Kt = [system.TimeZoneInfo]::GetSystemTimeZones() | ? {$_.id -match "Afghanistan Standard Time"}
- $tz = $kt.Displayname
- $t1 = [system.Math]::Abs($kt.BaseUtcOffset.Hours)
- $t2 = [System.Math]::Abs($kt.BaseUtcOffset.Minutes)
- $t3 = if ($kt.BaseUtcOffset -ge [System.timespan]::Zero) {"later"} else {"earlier"}
- $t4 = if ($Kt.IsdaylightSavingTime($datenow)) {$Kt.DaylightName} else {$Kt.Standardname}
- # Display information
- "Time Zone: {0}" -f $Kt.Displayname
- " Time zone is {0} hours {1} minutes {2} than Coordinated Universal Time." -f $t1,$t2,$t3
- " Current time is {0:t} on {0:d} {1}" -f $datenow,$t4
- " Timezone id : {0}" -f $Kt.Id
- " Supports Daylight Saving : {0}" -f $Kt.SupportsDaylightSavingTime
- " Daylight Saving Zone Name: {0}" -f $Kt.DaylightName
- ""
- # Display Information regarding UTC
- $UtcZone = [System.TimeZoneInfo]::UTC
- $t1 = [system.Math]::Abs($UtcZone.BaseUtcOffset.Hours)
- $t2 = [System.Math]::Abs($UtcZone.BaseUtcOffset.Minutes)
- $t3 = if ($UtcZone.BaseUtcOffset -ge [System.Timespan]::Zero) {"later"} else {"earlier"}
- $t4 = if ($UtcZone.IsdaylightSavingTime($datenow)) {$Utczone.DaylightName} else {$UtcZone.Standardname}
- # Display information
- "Time Zone: {0}" -f $UtcZone.Displayname
- " Time zone is {0} hours {1} minutes {2} than Coordinated Universal Time." -f $t1,$t2,$t3
- " Current time is {0:t} on {0:d} {1}" -f $Datenow,$t4
- " Timezone id : {0}" -f $UtcZone.Id
- " Supports Daylight Saving : {0}" -f $UtcZone.SupportsDaylightSavingTime
- " Daylight Saving Zone Name: {0}" -f $UtcZone.DaylightName
Labels:
powershell,
PowerShell scripts,
System.TimeZoneInfo
Wednesday, 25 August 2010
Get-NoDstTimeZones
- <#
- .SYNOPSIS
- This script displays those time zones that do NOT support
- daylight savings time.
- .DESCRIPTION
- This script uses .NET to get the time zones defined on a system
- then displays those that do not suport daylight savings time.
- .NOTES
- File Name : Get-NoDstTimeZones.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN Sample posted at:
- http://msdn.microsoft.com/en-us/library/system.timezoneinfo.supportsdaylightsavingtime.aspx
- .EXAMPLE
- PSH [C:\foo]: .\Get-NoDstTimeZones.ps1'
- (UTC) Coordinated Universal Time
- (UTC) Monrovia, Reykjavik
- (UTC+01:00) West Central Africa
- ... {output snipped to save space}
- #>
- # Get Time Zones
- $zones = [System.TimeZoneInfo]::GetSystemTimeZones()
- # For each zone, display name if the zone does not support dst
- foreach($zone in $zones) {
- if (! $zone.SupportsDaylightSavingTime) {$zone.DisplayName}
- }
Labels:
code,
powershell,
Script,
scripts,
System.TimeZoneInfo
Tuesday, 17 August 2010
Get-BrokenHardware.ps1
- <#
- .SYNOPSIS
- This script gets a list of non-working hardware using WMI.
- .DESCRIPTION
- This script re-implements another TechNet Scripting
- Gallery script that was written in VB (see
- http://tinyurl.com/y4hmtbr).
- This script first uses WMI to get system details, then
- gets and displays hardware that has errored.
- .NOTES
- File Name : Get-BrokenHardware.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- This script posted to TechNet Script Gallery at:
- http://gallery.technet.microsoft.com/ScriptCenter/en-us/dbb678f4-b95b-45c3-bc8b-2ae2d052448e
- .EXAMPLE
- PSH [C:\foo]: Get-BrokenHardware.ps1
- Computer Details:
- Manufacturer: Dell Inc.
- Model: Precision WorkStation T7400
- Service Tag: 6Y84C3J
- Hardware that's not working list
- Description: WD My Book Device USB Device
- Device ID: USBSTOR\OTHER&VEN_WD&PROD_MY_BOOK_DEVICE&REV_1010\7&2A4E07C&0&575532513130303732383932&1
- Error ID: 28
- #>
- # Display Computer details
- "Computer Details:"
- $comp = gwmi Win32_ComputerSystem
- "Manufacturer: {0}" -f $comp.Manufacturer
- "Model: {0}" -f $comp.Model
- $computer2 = Get-WmiObject Win32_ComputerSystemProduct
- "Service Tag: {0}" -f $computer2.IdentifyingNumber
- ""
- #Get hardware that is errored
- "Hardware that's not working list"
- $broken = Get-WmiObject Win32_PnPEntity | where {$_.ConfigManagerErrorCode -ne 0}
- #Display broken hardware
- foreach ($obj in $broken){
- "Description: {0}" -f $obj.Description
- "Device ID: {0}" -f $obj.DeviceID
- "Error ID: {0}" -f $obj.ConfigManagerErrorCode
- ""
- }
Technorati Tags: PowerShell,Scripts,WMI,Win32_ComputerSystem,Win32_ComputerSystemProduct,Win32_PnPEntity
Subscribe to:
Posts (Atom)