- <
- .Synopsis
- Displays the value of the [System.Globalzation.JulianCalendar}::JulianEra field
- .Description
- This script retreives the JulianEra field and displays it, using the .NET class
- System.Globalization.JulianCalendar.
- .NOTES
- File Name : Get-JulianEraField.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell V2 CTP3
- .LINK
- Script Posted to:
- http://www.pshscripts.blogspot.com
- MSDN Sample at:
- http://msdn.microsoft.com/en-us/library/system.globalization.juliancalendar.julianera.aspx
- .Example
- PS C:\foo> .\Get-JulianEraField.ps1
- The JulianEra Field has a value of: 1
-
-
-
-
-
-
-
- $era = [system.Globalization.JulianCalendar]::JulianEra
-
-
- "The JulianEra field has a value of: {0}" -f $era
- <
- .SYNOPSIS
- Demonstrates Decimal arithmetic.
- .DESCRIPTION
- This script Creates two decimals, then multiplys them and displays them.
- .NOTES
- File Name : get-decimal1.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell V2 CTP3
- .LINK
- http://www.pshscripts.blogspot.com
- Posted on msdn:
- http://msdn.microsoft.com/en-us/library/system.decimal.aspx
- .EXAMPLE
- PS c:\foo> .\get-decimal1.ps1
- $d1 is of type: Decimal
- $d2 is of type: Decimal
- $d1 (12.1) multiplied by $d2 (12.2) equals: 146.41
- $d3 is of type: Decimal
-
-
-
-
-
-
-
- [decimal] $d1 = 12.1
- [decimal] $d2 = 12.2
-
-
- $d3 = $d1*$d1
-
-
- "`$d1 is of type: {0}" -f $d1.gettype().name
- "`$d2 is of type: {0}" -f $d2.gettype().name
- "`$d1 ({0}) multiplied by `$d2 ({1}) equals: {2}" -f $d1,$d2,$d3
- "`$d3 is of type: {0}" -f $d3.gettype().name
-
- <
- .SYNOPSIS
- Demonstrates the static properties on System.Environment
- .DESCRIPTION
- This script uses the System.Environment class to retrieve interesting
- information about your system. The fields returned are static fields
- on the System.Environment class.
- .NOTES
- File Name : Get-System.EnvironmentStaticProperties1.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell V2 CTP3
- .LINK
- http://www.pshscripts.blogspot.com
- .EXAMPLE
- PS c:\Foo> .\Get-System.EnvironmentStaticProperties1.ps1
- Static properties in [System.Environment]
- TypeName: System.Environment
-
- Name MemberType Definition
- ---- ---------- ----------
- CommandLine Property static System.String CommandLine {get;}
- CurrentDirectory Property static System.String CurrentDirectory {get;set;}
- ExitCode Property static System.Int32 ExitCode {get;set;}
- HasShutdownStarted Property static System.Boolean HasShutdownStarted {get;}
- MachineName Property static System.String MachineName {get;}
- NewLine Property static System.String NewLine {get;}
- OSVersion Property static System.OperatingSystem OSVersion {get;}
- ProcessorCount Property static System.Int32 ProcessorCount {get;}
- StackTrace Property static System.String StackTrace {get;}
- SystemDirectory Property static System.String SystemDirectory {get;}
- TickCount Property static System.Int32 TickCount {get;}
- UserDomainName Property static System.String UserDomainName {get;}
- UserInteractive Property static System.Boolean UserInteractive {get;}
- UserName Property static System.String UserName {get;}
- Version Property static System.Version Version {get;}
- WorkingSet Property static System.Int64 WorkingSet {get;}
-
- Static Property values for [System.Environment]
- CommandLine: : "C:\Users\tfl\Desktop\psp\PowerShellPlus.exe"
- CurrentDirectory : C:\Users\tfl\Desktop\psp
- ExitCode : 0
- HasShutdownStarted : False
- MchineName :
- NewLine :
-
-
- OSVersion : Microsoft Windows NT 6.0.6001 Service Pack 1
- ProcessorCount : 8
- SystemDirctory : C:\Windows\system32
- TickCount : 261135752
- UserDomainName : COOKHAM
- UserInteractive : True
- UserName : tfl
- Version : 2.0.50727.1434
-
- Stack Trace
- { Snipped - Left as an exercise for the reader...}
-
-
-
-
-
-
-
- "Static properties in [System.Environment]"
- [System.Environment] | Get-Member -Static -MemberType properties
-
-
- "";"Static Property values for [System.Environment]"
- "CommandLine: : {0}" -f [System.Environment]::CommandLine
- "CurrentDirectory : {0}" -f [System.Environment]::CurrentDirectory
- "ExitCode : {0}" -f [System.Environment]::ExitCOde
- "HasShutdownStarted : {0}" -f [System.Environment]::HasShutdownStarted
- "MchineName : {0}" -f [System.Environment]::MachineNam
- "NewLine : {0}" -f [System.Environment]::NewLine
- "OSVersion : {0}" -f [System.Environment]::OSVersion
- "ProcessorCount : {0}" -f [System.Environment]::ProcessorCount
- "SystemDirctory : {0}" -f [System.Environment]::SystemDirectory
- "TickCount : {0}" -f [System.Environment]::TickCount
- "UserDomainName : {0}" -f [System.Environment]::UserDomainName
- "UserInteractive : {0}" -f [System.Environment]::UserInteractive
- "UserName : {0}" -f [System.Environment]::UserName
- "Version : {0}" -f [System.Environment]::Version
- "WorkingSet : {0}" -f [System.Environment]::WorkingSet
-
-
- "";"Stack Trace:"
- [System.Environment]::StackTrace
-
- <
- .SYNOPSIS
- Uses Win32_PNPEntity to return information about non-working devices.
- .DESCRIPTION
- This script calls Get-WmiObject to retrieve plug and play details,
- then formats and displays non-working devices. The script also has to
- work around how WMI returns 0 and 1 object (i.e. no $obj.count).
-
- This is also sample 6 on http://msdn.microsoft.com/en-us/library/aa394587(VS.85).aspx
- recoded with PowerShell.
- .NOTES
- File Name : Get-NonWorkingDevices.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell V2 CTP3
- .LINK
- Script posted to:
- http://www.pshscripts.blogspot.com
- Original MSDN Page
- http://msdn.microsoft.com/en-us/library/aa394587(VS.85).aspx
- .EXAMPLE
- PS C:\foo> Get-NonWorkingDevices.ps1
- No bad devices on Cookham8
- .EXAMPLE
- PS C:\foo> Get-NonWorkingDevices.ps1
- Total Bad devices on Cookham8: 1
- Name : NETGEAR FA311v2 PCI Adapter - Virtual Network
- Class Guid : {4d36e972-e325-11ce-bfc1-08002be10318}
- Description : Microsoft Virtual Network switch Adapter
- Device ID : ROOT\VMS_MP\0001
- Manufacturer :
- PNP Device Id : ROOT\VMS_MP\0001
- Service Name : VMSMP
-
-
-
-
-
-
-
- $BadDevices = Get-WmiObject Win32_PNPEntity | Where {$_.ConfigManagerErrorcode -ne 0}
-
-
- $Hostname = Hostname
- if (!$BadDevices) {
- "No bad devices on {0}" -f $Hostname
- }
- else {
- if (!$BadDevices.Count) {$Count=1} else {$Count=$BadDevices.count}
- "Total Bad devices on {0}: {1}" -f $Hostname, $Count
- foreach ($Device in $BadDevices) {
- "Name : {0}" -f $Device.Name
- "Class Guid : {0}" -f $Device.Classguid
- "Description : {0}" -f $Device.Description
- "Device ID : {0}" -f $Device.Deviceid
- "Manufacturer : {0}" -f $Device.Manufactuer
-
- "PNP Device Id : {0}" -f $Device.PNPDeviceID
- "Service Name : {0}" -f $Device.Service
- ""
- }
- }
- <
- .SYNOPSIS
- Uses .NET formatting strings to format date/time values
- .DESCRIPTION
- Recreates an MSDN sample for displaying Date/TIme Format. See
- links section for pointer to original Sample.
- .NOTES
- File Name : Get-DateTime.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell V2 CTP3
- .EXAMPLE
- PS C:\foo> .\Get-DateTime.ps1
- FORMAT en-gb EXAMPLE
- CHAR VALUE OF ASSOCIATED PROPERTY, if ANY
- d 12/28/2008
- dd/MM/yyyy (ShortDatePattern)
- D 28 December 2008
- dd MMMM yyyy (LongDatePattern)
- f 28 December 2008 16:37
- F 28 December 2008 16:37:00
- dd MMMM yyyy HH:mm:ss (FullDateTimePattern)
- g 28/12/2008 16:37
- G 28/12/2008 16:37:00
- m 28 December
- dd MMMM (MonthDayPattern)
- M 28 December
- dd MMMM (MonthDayPattern)
- o 2008-12-28T16:37:00.4017900+00:00
- r Sun, 28 Dec 2008 16:37:00 GMT
- ddd, dd MMM yyyy HH':'mm':'ss 'GMT' (RFC1123Pattern)
- R Sun, 28 Dec 2008 16:37:00 GMT
- ddd, dd MMM yyyy HH':'mm':'ss 'GMT' (RFC1123Pattern)
- s 2008-12-28T16:37:00
- yyyy'-'MM'-'dd'T'HH':'mm':'ss (SortableDateTimePattern)
- t 16:37
- HH:mm (ShortTimePattern)
- T 16:37:00
- HH:mm:ss (LongTimePattern)
- u 2008-12-28 16:37:00Z
- yyyy'-'MM'-'dd HH':'mm':'ss'Z' (UniversalSortableDateTimePattern)
- U 28 December 2008 16:37:00\n
- y December 2008
- MMMM yyyy (YearMonthPattern)
- Y December 2008
- MMMM yyyy (YearMonthPattern)
- .EXAMPLE
- PS C:\foo> Get-Help Get-DateTime.ps1
- Left as an exercise for the reader!
- .LINK
- Script posted to:
- http://www.pshscripts.blogspot.com
- MSDN Sample Page showing C
- http://msdn.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.aspx
-
-
-
-
-
-
-
- $culture = [system.Globalization.CultureInfo]::CreateSpecificCulture("en-gb")
- $dtfi = $culture.DateTimeFormat
-
-
-
- $dt = get-date
- "FORMAT en-gb EXAMPLE"
- "CHAR VALUE OF ASSOCIATED PROPERTY, IF ANY"
- " d {0} " -f $DT.ToString("d", $DI)
- " {0} {1} " -f $dtfi.ShortDatePattern, "(ShortDatePattern)"
- " D {0} " -f $dt.ToString("D", $DTFI)
- " {0} {1} " -f $dtfi.LongDatePattern, "(LongDatePattern)"
- " f {0} " -f $dt.ToString("f", $DTFI)
- " F {0} " -f $dt.ToString("F", $DTFI)
- " {0} {1} " -f $dtfi.FullDateTimePattern, "(FullDateTimePattern)"
- " g {0} " -f $dt.ToString("g", $DTFI)
- " G {0} " -f $dt.ToString("G", $DTFI)
- " m {0} " -f $dt.ToString("m", $DTFI)
- " {0} {1} " -f $dtfi.MonthDayPattern, "(MonthDayPattern)"
- " M {0} " -f $dt.ToString("M", $DTFI)
- " {0} {1} " -f $dtfi.MonthDayPattern, "(MonthDayPattern)"
- " o {0} " -f $dt.ToString("o", $DTFI)
- " r {0} " -f $dt.ToString("r", $DTFI)
- " {0} {1} " -f $dtfi.RFC1123Pattern, "(RFC1123Pattern)"
- " R {0} " -f $dt.ToString("R", $DTFI)
- " {0} {1} " -f $dtfi.RFC1123Pattern, "(RFC1123Pattern)"
- " s {0} " -f $dt.ToString("s", $DTFI)
- " {0} {1} " -f $dtfi.SortableDateTimePattern, "(SortableDateTimePattern)"
- " t {0} " -f $dt.ToString("t", $DTFI)
- " {0} {1} " -f $dtfi.ShortTimePattern, "(ShortTimePattern)"
- " T {0} " -f $dt.ToString("T", $DTFI)
- " {0} {1} " -f $dtfi.LongTimePattern, "(LongTimePattern)"
- " u {0} " -f $dt.ToString("u", $DTFI)
- " {0} {1} " -f $dtfi.UniversalSortableDateTimePattern, "(UniversalSortableDateTimePattern)"
- " U {0}\n " -f $dt.ToString("U", $DTFI)
- " y {0} " -f $dt.ToString("y", $DTFI)
- " {0} {1} " -f $dtfi.YearMonthPattern, "(YearMonthPattern)"
- " Y {0} " -f $dt.ToString("Y", $DTFI)
- " {0} {1} " -f $dtfi.YearMonthPattern, "(YearMonthPattern)"
-
- <
- .SYNOPSIS
- Shows use of GetCurrentDomain to return information about the domain
- .DESCRIPTION
- Uses system.directoryservices.activedirectory.domain and GetCurrentDomain
- to return domain information of the currently logged on user. Note that this
- domain may be different to the domain of the computer itself.
- .NOTES
- File Name : get-domain.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell V2 CTP3
- .LINK
- http://www.pshscripts.blogspot.com
- .EXAMPLE
- PS c:\foo> .\get-domain.ps1
- You are connected to the cookham.net domain
- Role Holders in this domain:
- PDC Role Holder : Cookham1.cookham.net
- RID Role Holder : Cookham1.cookham.net
- InfraM Role Holder : Cookham1.cookham.net
-
-
-
-
-
-
-
- $domain = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
-
-
- "You are connected to the {0} domain" -f $domain.name
- "Role Holders in this domain:"
- " PDC Role Holder : {0}" -f $domain.PdcRoleOwner
- " RID Role Holder : {0}" -f $domain.RIDRoleOwner
- " InfraM Role Holder : {0}" -f $domain.InfrastructureRoleOwner
-
- <
- .SYNOPSIS
- Gets stock quotes using a web servoice
- .DESCRIPTION
- This function uses the New-WebServiceProxy cmdlet to
- create a web service proxy. Then it calls that proxy
- to get stock information.
- .NOTES
- File Name : get-stockquote.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell V2 CTP3
- .LINK
- Original post:
- http://PoshCode.org/embed/752
- Updated script posted:
- http://www.pshscripts.blogspot.com
- .INPUTTYPE
- String(s) representing stock tickers to find
- .RETURNVALUE
- XML Element, holding stock details
- .EXAMPLE
- Run from PowerShell Prompt:
- Get-StockQuote "MSFT"
- Output - left as an exercise for the reader
- .EXAMPLE
- Run from Pipeline
- "IBM","INTC" | Get-StockQuote
- Output - left as an exercise for the reader
- .PARAMETER TICKER
- A string, or array of strings representing stock tickers
- The function gets stock details for each stock ticker provided
-
-
- function Get-StockQuote {
- param(
- [Parameter(Position=0, Mandatory=$FALSE, ValueFromPipeline=$TRUE)]
- [String] $TICKER="MSFT" )
- process {
- $ticker
- $s = new-webserviceproxy -uri http://www.webservicex.net/stockquote.asmx
- foreach ($symbol in $ticker) {
- $result = [xml]$s.GetQuote($symbol)
- $result.StockQuotes.Stock
- }
- }
- }
-
-
- "Example 1:"
- "=========="
- Get-StockQuote MSFT
- ""
- "Example 2:"
- "=========="
- "IBM","INTC" | Get-StockQuote
- <
- .SYNOPSIS
- Validates an email address using a web service
- .DESCRIPTION
- This script uses the New-WebServiceProxy cmdlet to
- create a web service proxy. Then it calls that proxy
- to Validate an email address.
- .NOTES
- File Name : validate-emailaddress.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell V2 CTP3
- .LINK
- Script posted to:
- http://www.pshscripts.blogspot.com
- .INPUTTYPE
- String(s) representing email address to validate
- .RETURNVALUE
- [Boolean] - whether email address was valid
- .EXAMPLE
- Run from PowerShell Prompt:
- PS C:\foo> .\Validate-EmailAddress "tfl@psp.co.uk”
- True
- .EXAMPLE
- Run from Pipeline:
- PS C:\foo> "tfl@psp.co.uk", "foo@foo.bar" | .\Validate-EmailAddress
- True
- False
- .PARAMETER addr
- A string, or array of strings representing email addresses to check
- #>
-
- param(
- [Parameter(Position=0, Mandatory=$FALSE, ValueFromPipeline=$TRUE)]
- [String] $Addr = "doctordns@gmail.com" )
- process {
- $s = new-webserviceproxy -uri http://www.webservicex.net/validateEmail.asmx
- foreach ($a in $addr) {
- $result = $s.IsValidEmail($a)
- $result
- }
- }