- <#
- .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
- }
This blog contains PowerShell scripts, more PowerShell scripts and still more PowerShell scripts. Occasionally you may see some organisational posts.
Tuesday, 31 August 2010
Get-Cultures.ps1
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
Monday, 16 August 2010
Get-Sha1HashFile.ps1
- <#
- .SYNOPSIS
- This script uses the SHA1 Crypto Provider to hash a file
- .DESCRIPTION
- This script uses SHA1 Cryptoprovider to hash a file and print the hash. A second
- hash is created of the same file, but with a space added. The file I picked is a
- large text file I keep in c:\foo for uses like this!
- .NOTES
- File Name : Get-Sha1HashFile.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- Posted to TechEd Sample Gallery at:
- .EXAMPLE
- PSH [C:\foo]: .\Get-Sha1HashFile.ps1
- Hashing : C:\foo\gd.txt
- Results in : 760bb67356560232
- Hashing : C:\foo\gd.txt + space
- Results in : 4f7b4902168bba7d
- #>
- # Create Input Data
- $file = (ls c:\foo\*.txt | sort -descending length)[0] # get largest file
- $filestr = Get-Content $file
- $filebytes1 = [System.Text.UnicodeEncoding]::Unicode.getbytes($files)
- $filebytes2 = [System.Text.UnicodeEncoding]::Unicode.getbytes($files+" ")
- # Create a New SHA1 Crypto Provider
- $sha = New-Object System.Security.Cryptography.SHA1CryptoServiceProvider
- # Now hash that
- $result1 = $sha.ComputeHash($filebytes1)
- "Hashing : {0}" -f $file.FullName
- "Results in : {0}" -f [system.BitConverter]::ToUint64($result1,0).tostring("x")
- $result2 = $sha.ComputeHash($filebytes2)
- "Hashing : {0}" -f " $($file.FullName) + space"
- "Results in : {0}" -f [system.BitConverter]::ToUint64($result2,0).tostring("x")
Friday, 13 August 2010
Get-Sha1Hash.ps1
- <#
- .SYNOPSIS
- This script uses the SHA1 Crypto Provider to hash a string
- .DESCRIPTION
- This script creates 2 strings, and a SHA1 Crypto Provider.
- The script then hashes the strings and displays the results.
- .NOTES
- File Name : Get-Sha1Hash.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.security.cryptography.sha1cryptoserviceprovider.aspx
- Posted to TechEd Sample Gallery at:
- .EXAMPLE
- PSH [C:\foo]: . 'E:\PowerShellScriptLib\System.Security.Crpytography\Get-Sha1Hash.ps1'
- Hashing : This is a string to hash
- Results in : z→???_r♠W??o???]rv??
- Hashing : this is a string to hash
- Results in : ???☺$?Z??♀???????U?'
- #>
- # Create Input Data
- $enc = [system.Text.Encoding]::ASCII
- $string1 = "This is a string to hash"
- $string2 = "this is a string to hash"
- $data1 = $enc.GetBytes($string1)
- $data2 = $enc.GetBytes($string2)
- # Create a New SHA1 Crypto Provider
- $sha = New-Object System.Security.Cryptography.SHA1CryptoServiceProvider
- # Now hash and display results
- $result1 = $sha.ComputeHash($data1)
- "Hashing : {0}" -f $string1
- "Results in : {0}" -f $enc.Getstring($result1)
- ""
- $result2 = $sha.ComputeHash($data2)
- "Hashing : {0}" -f $string2
- "Results in : {0}" -f $enc.Getstring($result2)
Thursday, 12 August 2010
Get-DnsRegisteredServers.ps1
- <#
- .SYNOPSIS
- This script gets the reverse lookup zone from a DNS Server and
- displays all the systems registered
- .DESCRIPTION
- This script first gets the reverse lookup zone from a DNS Server (i.e.
- all the computers that have used the DNS server to register!). The
- script then displays the FQDN, IP Address and Timestamp.
- .NOTES
- File Name : Get-DnsRegisteredServers.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 Scripting Gallery
- http://gallery.technet.microsoft.com/ScriptCenter/en-us/28e8b98e-565b-40be-ba2c-1134341bb555
- .EXAMPLE
- PSH [C:\foo]: .Get-DnsRegisteredNames.ps1
- Computers reverse registered on DNS Server: Cookham1
- 10.10.1.42 superman.cookham.net. 3590550
- 10.10.1.105 batman.cookham.net. 3582112
- 10.10.1.109 jeeves.cookham.net. 3586452
- 10.10.1.111 supergirl.cookham.net. 3590550
- 10.10.1.114 future.cookham.net. 3589209
- 10.10.1.131 bladerunner.cookham.net. 3587817
- 10.10.1.142 wonderwoman.kapoho.net. 3590551
- #>
- $dns = "Cookham1"
- $records = get-wmiobject -class MicrosoftDNS_PTRType -namespace root\MicrosoftDNS -computer $dns
- "Computers reverse registered on DNS Server: $DNS"
- # Loop through and display results
- foreach ($record in $records) {
- # Get owner name and ip address string
- $on = $record.ownerName.split(".")
- $ownerip = $on[3] + "." + $on[2] + "." + $on[1] + "." + $on[0]
- # Display details
- "{0, -15} {1,-40} {2,-10} " -f $ownerip, $record.ptrdomainname, $record.timestamp
- }
Labels:
MicrosoftDNS,
powershell,
PowerShell scripts,
wmi
Wednesday, 11 August 2010
Get-EncryptedAesString.ps1
- <#
- .SYNOPSIS
- This script encrypts then decrypts a string using AES
- .DESCRIPTION
- This script re-implements an MSDN sample that first
- encrypts a string then decrypts it. The crypto is done
- using AES. Running this script multiple times will result
- in differently encrypted quotes since a new key/IV is
- generated each time you run the script.
- .NOTES
- File Name : Get-AesEnctyptedString.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-encryptedaesstringps1.html
- MSDN Sample posted at:
- http://msdn.microsoft.com/en-us/library/09d0kyb3.aspx
- .EXAMPLE
- PSH [C:\foo]: .\Get-AesEncryptedString.ps1
- Quote:
- Things may come to those who wait, but only the things left by those who hustle. -- Abraham Lincoln
- Encrypted Quote:
- zp4gD/Mmu01Msr3V8d94Kvwut4ClaW+f1HyohT+QjpFN5FVNhyLcQIgia4iD2TcsK/SpLcm5cOi1/KM+d9ENeU2Lkn8fOZHpMnklUrABGDoM1BRQDfWNcVbMIOA4IUY
- zLoJ5huHKhnyPA2fobGouW33HOpONI0zR3KS4RdtD3M3QQsqHW2+QOkE4/Ls/5gCSbcTuP2FDkk3J9b+1XgqzJZx0jZIBl+moUcqA33xQdu5bGhwg1E8sk2oEU8AQyy
- XcRrS/h8vTLve8c0Tpj4f2Vg==
- Decrypted Quote:
- Things may come to those who wait, but only the things left by those who hustle. -- Abraham Lincoln
- #>
- # Best Practice!
- Set-StrictMode -version 2
- # Two helper functions
- function EncryptString{
- param( $SymAlg,
- [string] $inString
- )
- $inBlock = [System.Text.UnicodeEncoding]::Unicode.getbytes($instring)
- $xfrm = $symAlg.CreateEncryptor()
- $outBlock = $xfrm.TransformFinalBlock($inBlock, 0, $inBlock.Length);
- return $outBlock;
- }
- function DecryptBytes {
- param ($SymAlg,
- $inBytes
- )
- $xfrm = $symAlg.CreateDecryptor();
- $outBlock = $xfrm.TransformFinalBlock($inBytes, 0, $inBytes.Length)
- return [System.Text.UnicodeEncoding]::Unicode.GetString($outBlock)
- }
- # main script
- $Quote = "Things may come to those who wait, but only the " +
- "things left by those who hustle. -- Abraham Lincoln"
- "Quote:";$Quote;""
- # Generate CSP, Key and IV
- $AesCSP = New-Object System.Security.Cryptography.AesCryptoServiceProvider
- $AesCSP.GenerateKey()
- $AesCSP.GenerateIV()
- # Encrypt quote
- $EncQuote = EncryptString $aesCSP $quote
- "Encrypted Quote:"
- [System.Convert]::ToBase64String($encQuote)
- ""
- # Now Decrypt
- "Decrypted Quote:"
- DecryptBytes $AesCSP $EncQuote
Tuesday, 10 August 2010
Convert-Date.ps1
- <#
- .SYNOPSIS
- This script manipulates a time using TimeZone info methods.
- .DESCRIPTION
- This script re-implements an MSDN sample using PowerShell. The script first
- creates a DateTime object then it converts it to Universal, UTC, Pacific and 'local' time.
- .NOTES
- File Name : Convert-Date.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://pshscripts.blogspot.com/2010/08/convert-dateps1.html
- MSDN Sample posted at:
- http://msdn.microsoft.com/en-us/library/system.timezoneinfo.local.aspx
- .EXAMPLE
- PSH [C:\foo]: . 'E:\PowerShellScriptLib\System.TimeZoneINfo\Convert-date.ps
- Date : 3/21/2006 02:00:00 AM
- Local Time zone: GMT Standard Time
- In Universal time: 3/21/2006 02:00:00 AM
- In UTC : 3/21/2006 02:00:00 AM
- In Local TZ: : 3/21/2006 02:00:00 AM
- In Pacific TZ : 3/21/2006 10:00:00 AM
- #>
- # Create date object
- $date1 = New-Object System.DateTime 2006, 3, 21, 2, 0, 0
- # Display date and local time zone then show that time in other time zones
- "Date : {0}" -f $date1
- "Local Time zone: {0}" -f ([System.TimeZoneInfo]::Local).id
- " In Universal time: {0}" -f $date1.ToUniversalTime()
- " In UTC : {0}" -f [System.TimeZoneInfo]::ConvertTimeToUtc($date1)
- " In Local TZ: : {0}" -f [System.TimeZoneInfo]::ConvertTimeToUtc($date1, ([System.TimeZoneInfo]::Local))
- $tz = [System.TimeZoneInfo]::FindSystemTimeZoneById("Pacific Standard Time");
- " In Pacific TZ : {0}" -f [System.TimeZoneInfo]::ConvertTimeToUtc($date1, $tz)
Labels:
powershell,
PowerShell scripts,
System.TimeZoneInfo
Monday, 9 August 2010
Divide-BigInteger.ps1
- <#
- .SYNOPSIS
- This script divides big integers using .NET Framework.
- .DESCRIPTION
- This script reimplements an MSDN Sample script using powershell. The
- script creates a dividor and an arry of dividends, then performs
- division operations several ways.
- .NOTES
- File Name : Divide-BigInteger.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .NET Framework 4.0 or higher
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN Sample posted at:
- http://msdn.microsoft.com/en-us/library/system.numerics.biginteger.divide.aspx
- .EXAMPLE
- PSH [C:\foo]: . 'C:\Users\tfl\AppData\Local\Temp\Untitled7.ps1'
- Dividend: 680,564,693,277,057,719,623,408,366,969,033,850,880
- Divisor: 85,070,591,730,234,615,847,396,907,784,232,501,249
- Results:
- Using Divide method: 7
- Using Division operator: 7
- Using DivRem method: 7, remainder 85,070,551,165,415,408,691,630,012,479,406,342,137
- Dividend: 90,612,345,123,875,509,091,827,560,007,100,099
- Divisor: 85,070,591,730,234,615,847,396,907,784,232,501,249
- Results:
- Using Divide method: 0
- Using Division operator: 0
- Using DivRem method: 0, remainder 90,612,345,123,875,509,091,827,560,007,100,099
- Dividend: 1
- Divisor: 85,070,591,730,234,615,847,396,907,784,232,501,249
- Results:
- Using Divide method: 0
- Using Division operator: 0
- Using DivRem method: 0, remainder 1
- Dividend: 19,807,040,619,342,712,359,383,728,129
- Divisor: 85,070,591,730,234,615,847,396,907,784,232,501,249
- Results:
- Using Divide method: 0
- Using Division operator: 0
- Using DivRem method: 0, remainder 19,807,040,619,342,712,359,383,728,129
- Dividend: 85,070,591,730,234,615,847,396,907,784,232,501,250
- Divisor: 85,070,591,730,234,615,847,396,907,784,232,501,249
- Results:
- Using Divide method: 1
- Using Division operator: 1
- Using DivRem method: 1, remainder 1
- #>
- # Add namespace
- $r = [system.Reflection.Assembly]::LoadWithPartialName("System.Numerics")
- #Create a big integer divisor and an array of dividends
- $divisor = [system.numerics.BigInteger]::pow([Int64]::MaxValue, 2)
- $dividends = @()
- $dividends += [system.numerics.BigInteger]::Multiply(([system.numerics.BigInteger] [system.Single]::MaxValue), 2)
- $dividends += [system.numerics.BigInteger]::Parse("90612345123875509091827560007100099")
- $dividends += [system.numerics.BigInteger]::One
- $dividends += [system.numerics.BigInteger]::Multiply([Int32]::MaxValue, [Int64]::MaxValue)
- $dividends += $divisor + [system.numerics.BigInteger]::One
- #Divide each dividend by divisor in three different ways
- foreach ($dividend in $dividends) {
- "Dividend: {0:N0}" -f $dividend
- "Divisor: {0:N0}" -f $divisor
- "Results:"
- " Using Divide method: {0:N0}" -f [system.Numerics.BigInteger]::Divide($dividend, $divisor)
- " Using Division operator: {0:N0}" -f ($dividend/$divisor)
- $remainder = [system.Numerics.BigInteger]::Zero
- $quotient = [system.numerics.BigInteger]::DivRem($dividend, $divisor, [ref] $remainder)
- " Using DivRem method: {0:N0}, remainder {1:N0}" -f $quotient, $remainder
- ""
- }
Sunday, 8 August 2010
Get-DriveInfo.ps1
- <#
- .SYNOPSIS
- This script gets and displays basic information about drives on a local system.
- .DESCRIPTION
- This script uses the System.Io.DriveInfo's GetDrives method to get drive
- info which is then displayed. This is a re-implementation of an MSDN
- sample.
- .NOTES
- File Name : Get-DriveInfo.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://pshscripts.blogspot.com/2010/07/get-driveinfops1.html
- MSDN Sample posted at:
- http://msdn.microsoft.com/en-us/library/system.io.driveinfo.aspx
- http://msdn.microsoft.com/en-us/library/system.io.driveinfo.getdrives.aspx
- .EXAMPLE
- PSH [C:\foo]: .\Get-DriveInfo.ps1'
- Drive C:\
- File type: Fixed
- Volume label:
- File system: NTFS
- Available space to current user: 6.75 gb
- Total available space: 6.75 gb
- Total size of drive: 48.828 gb
- Drive D:\
- File type: Fixed
- Volume label:
- File system: FAT32
- Available space to current user: 1.81 gb
- Total available space: 1.81 gb
- Total size of drive: 2.003 gb
- <ETC...>
- #>
- # Get Drive Info
- $allDrives = [system.Io.DriveInfo]::GetDrives()
- # Now display details
- foreach ($d in $allDrives) {
- "Drive {0}" -f $d.Name
- " File type: {0}" -f $d.DriveType
- if ($d.IsReady) {
- " Volume label: {0}" -f $d.VolumeLabel
- " File system: {0}" -f $d.DriveFormat
- $fs = $d.AvailableFreeSpace/1gb
- $tfs = $d.TotalFreeSpace/1gb
- $TS = $d.TotalSize/1gb
- " Available space to current user:{0, 15:n2} gb" -f $fs
- " Total available space: {0, 15:n2} gb" -f $tfs
- " Total size of drive: {0, 15:n3} gb" -f $ts
- }
- }
Labels:
powershell,
PowerShell scripts,
System.Io.DriveInfo
Wednesday, 4 August 2010
Get-MultiplyBigInteger.ps1
- <#
- .SYNOPSIS
- This script re-implements this MSDN Sample of
- multiplying a big integer.
- .DESCRIPTION
- This script first tries and fails to multiple a pair of large integers. The
- script catches the error and then used BigInteger.Multiply to multiply
- the two big itegers.
- .NOTES
- File Name : Get-MultiplyBigInteger.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.numerics.biginteger.multiply.aspx
- .EXAMPLE
- PSH [C:\foo]: .Get-MultiplyBigInteger.ps1
- Too big for long, try biginteger
- 12,193,263,111,263,526,900
- #>
- # Add System.Numerics namespace
- $r=[system.Reflection.Assembly]::LoadWithPartialName("System.Numerics")
- # Two big numbers
- $number1 = 1234567890
- $number2 = 9876543210
- # Try normal [long] then catch error and do biginteger
- try
- {
- [long] $product = $number1 * $number2
- }
- catch
- { "Too big for long, try biginteger"
- $product = New-Object System.Numerics.BigInteger
- $product = [System.Numerics.BigInteger]::Multiply($number1, $number2)
- $product.ToString("N0")
- }
Subscribe to:
Posts (Atom)