Thursday, 6 August 2009

New-Ou.PS1

  1. <# 
  2. .SYNOPSIS 
  3.     This script uses ADSI to add a new OU to a domain. 
  4. .DESCRIPTION 
  5.     This script creates a pointer to the domain, then 
  6.     uses the Create method to create a new OU under 
  7.     the root of the domain. 
  8. .NOTES 
  9.     File Name  : New-Ou.ps1 
  10.     Author     : Thomas Lee - tfl@psp.co.uk 
  11.     Requires   : PowerShell V2 CTP3 
  12. .LINK 
  13.     This script posted to: 
  14.         http://www.pshscripts.blogspot.com 
  15. .EXAMPLE 
  16.     PSH [C:\foo]: .\New-OU.PS1' 
  17.     Created OU: PowerShell 
  18.      
  19.     distinguishedName : {OU=PowerShell,DC=cookham,DC=net} 
  20.     Path              : LDAP://ou=PowerShell,dc=Cookham,dc=Net 
  21. #> 
  22. ## 
  23. # Start of Script 
  24. ## 
  25.  
  26. #Set variables 
  27. $OuName = “PowerShell” 
  28. $Domain = [ADSI]“LDAP://dc=Cookham,dc=Net” 
  29.  
  30. # Create the OU 
  31. $Ou = $Domain.Create(”OrganizationalUnit”, “ou=” + $OuName
  32. $Ou.SetInfo() 
  33.  
  34. # Display results 
  35. "Created OU: {0}" -f $OUName 
  36. $OU 
Technorati Tags: ,,,

Wednesday, 5 August 2009

Get-SpecialFolders.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script lists the special folders enumerated in System.Environment.SpecialFolder 
  4. .DESCRIPTION 
  5.     This script first enumerates the SpecialFolder Enum. for each member, the script 
  6.     then looks up, and displays, the value of that folder. 
  7. .NOTES 
  8.     File Name  : Get-SpecialFolders.ps1 
  9.     Author     : Thomas Lee - tfl@psp.co.uk 
  10.     Requires   : PowerShell V2 CTP3 
  11. .LINK 
  12.     This script posted to: 
  13.         http://www.pshscripts.blogspot.com 
  14.     MSDN Sample posted at: 
  15.         http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx 
  16. .EXAMPLE 
  17.     PSH [C:\foo]: . 'E:\PowerShellScriptLib\System.Environment\Get-SpecialFolders.PS1' 
  18.     Folder Name            Path 
  19.     -----------            ----------------------------------------------- 
  20.     Desktop                C:\Users\tfl\Desktop 
  21.     Programs               C:\Users\tfl\AppData\Roaming\Microsoft\Windows\Start Menu\Programs 
  22.     Personal               C:\Users\tfl\Documents 
  23.     Personal               C:\Users\tfl\Documents 
  24.     Favorites              C:\Users\tfl\NetHood\Favorites 
  25.     Startup                C:\Users\tfl\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup 
  26.     Recent                 C:\Users\tfl\AppData\Roaming\Microsoft\Windows\Recent 
  27.     SendTo                 C:\Users\tfl\AppData\Roaming\Microsoft\Windows\SendTo 
  28.     StartMenu              C:\Users\tfl\AppData\Roaming\Microsoft\Windows\Start Menu 
  29.     MyMusic                C:\Users\tfl\Music 
  30.     DesktopDirectory       C:\Users\tfl\Desktop 
  31.     MyComputer 
  32.     Templates              C:\Users\tfl\AppData\Roaming\Microsoft\Windows\Templates 
  33.     ApplicationData        C:\Users\tfl\AppData\Roaming 
  34.     LocalApplicationData   C:\Users\tfl\AppData\Local 
  35.     InternetCache          C:\Users\tfl\AppData\Local\Microsoft\Windows\Temporary Internet Files 
  36.     Cookies                C:\Users\tfl\AppData\Roaming\Microsoft\Windows\Cookies 
  37.     History                C:\Users\tfl\AppData\Local\Microsoft\Windows\History 
  38.     CommonApplicationData  C:\ProgramData 
  39.     System                 C:\Windows\system32 
  40.     ProgramFiles           C:\Program Files (x86) 
  41.     MyPictures             C:\Users\tfl\Pictures 
  42.     CommonProgramFiles     C:\Program Files (x86)\Common Files 
  43. #> 
  44.  
  45. ## 
  46. # Start of Script 
  47. ## 
  48.  
  49. # Get the list of special folders 
  50. $folders = [system.Enum]::GetValues([System.Environment+SpecialFolder])  
  51.  
  52. # Display these folders 
  53. "Folder Name            Path" 
  54. "-----------            -----------------------------------------------" 
  55. foreach ($folder in $folders) { 
  56. "{0,-22} {1,-15}"  -f $folder,[System.Environment]::GetFolderPath($folder
  57. #End of Script 

Get-Thursday

  1. <# 
  2. .SYNOPSIS 
  3.     This script checks of a particular date in the past was a Thurday. 
  4. .DESCRIPTION 
  5.     This script creates a DateTime object set for 1st May, 2003. The 
  6.     script then check to see if that day is a Thursday then displays
  7.     the day of week for that date (which is a Thursday). This script
  8.     is a copy of the MSDN sample, written in PowerShell.   
  9. .NOTES 
  10.     File Name  : Get-Thursday.ps1 
  11.     Author     : Thomas Lee - tfl@psp.co.uk 
  12.     Requires   : PowerShell V2 CTP3 
  13. .LINK 
  14.     This script posted to: 
  15.         http://pshscripts.blogspot.com/2009/08/get-thursday.html
  16.     MSDN Sample posted at: 
  17.         http://msdn.microsoft.com/en-us/library/system.dayofweek(VS.71).aspx 
  18. .EXAMPLE 
  19.     PSH [C:\foo]: . 'E:\PowerShellScriptLib\System.DateTime\get-thursday.ps1' 
  20.     Is Thursday the day of the week for 5/1/2003?: True 
  21.     The day of the week for 5/1/2003 is Thursday. 
  22. #> 
  23.   
  24. ## 
  25. # Start of script 
  26. ## 
  27.   
  28. # Create a DateTime for the first of May, 2003. 
  29. $dt = New-Object System.DateTime 2003, 5, 1 
  30.   
  31. # Now - is it Thursday? 
  32. "Is Thursday the day of the week for {0:d}?: {1}" -f $dt,($dt.DayOfWeek -eq [system.DayOfWeek]::Thursday) 
  33. "The day of the week for {0:d} is {1}." -f $dt, $dt.DayOfWeek 
  34. # End of Script 

Tuesday, 4 August 2009

Get-DNSAddress.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script uses the System.Net.Networkinginformation.Networknterface class 
  4.     to get all network interface detais and displays the DNS addresses configured. 
  5. .DESCRIPTION 
  6.     This script first gets all the interface objects, then iterates throught them to  
  7.     get the DNS address(es) configured for each one. 
  8. .NOTES 
  9.     File Name  : Get-DNSAddress.ps1 
  10.     Author     : Thomas Lee - tfl@psp.co.uk 
  11.     Requires   : PowerShell V2 CTP3 
  12. .LINK 
  13.     This script posted to: 
  14.     http://www.pshscripts.blogspot.com 
  15.     MSDN Sample posted at: 
  16.     http://msdn.microsoft.com/en-us/library/system.net.networkinformation.ipaddressinformation(VS.85).aspx 
  17. .EXAMPLE 
  18.     PSH [C:\foo]: . 'C:\Users\tfl\AppData\Local\Temp\Untitled11.ps1' 
  19.     NETGEAR FA311v2 PCI Adapter - Virtual Network 
  20.       DNS Servers ............................. : 10.10.1.101 
  21.     Broadcom NetXtreme Gigabit Ethernet 
  22.       DNS Servers ............................. : 10.10.1.101 
  23.     Software Loopback Interface 1 
  24.       DNS Servers ............................. : fec0:0:0:ffff::1%1 
  25.       DNS Servers ............................. : fec0:0:0:ffff::2%1 
  26.       DNS Servers ............................. : fec0:0:0:ffff::3%1 
  27.     isatap.cookham.net 
  28.       DNS Servers ............................. : 10.10.1.101 
  29. #> 
  30.   
  31. ## 
  32. # Start of Script 
  33. ## 
  34.  
  35. # Get set of adapters 
  36. $adapters  = [System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces() 
  37.   
  38. # For each adapter, print out DNS Server Addresses configured 
  39. foreach ($adapter in $adapters) { 
  40.   $AdapterProperties = $Adapter.GetIPProperties() 
  41.   $dnsServers        = $AdapterProperties.DnsAddresses 
  42.   if ($dnsServers.Count -gt 0){ 
  43.     $adapter.Description 
  44.     foreach ($IPAddress in $dnsServers) { 
  45.         "  DNS Servers ............................. : {0}" -f $ipaddress.IPAddressToString 
  46.             } 
  47.     } 
  48. }    
  49. # End of Script 

Monday, 3 August 2009

Get-System.Environment.ps1

  1. <#
  2. .SYNOPSIS
  3. This script demonstrates the use of System.Environment
  4. .DESCRIPTION
  5. This script Uses a variety of the members of System.Environment and is
  6. a re-write of a MSDN Sample Script
  7. .NOTES
  8. File Name : Get-System.Environment
  9. Author : Thomas Lee - tfl@psp.co.uk
  10. Requires : PowerShell V2 CTP3
  11. .LINK
  12. This script posted to:
  13. http://www.pshscripts.blogspot.com
  14. MSDN Sample posted at:
  15. http://msdn.microsoft.com/en-us/library/system.environment.aspx
  16. .EXAMPLE
  17. PSH [C:\foo]: .\Get-System.Environment.ps1' foo1 foo2 foo3
  18. My system drive is C: and my system root is C:\Windows
  19. -- Environment members --
  20. CommandLine : "C:\Users\tfl\Desktop\psp\PowerShellPlus.exe"
  21. GetCommandLineArgs: C:\Users\tfl\Desktop\psp\PowerShellPlus.exe
  22. CurrentDirectory : C:\Users\tfl\Desktop\psp
  23. ExitCode : 0
  24. HasShutdownStarted: False
  25. MachineName : COOKHAM8
  26. NewLine :
  27. first line
  28. second line
  29. third line
  30. OSVersion : Microsoft Windows NT 6.0.6001 Service Pack 1
  31. StackTrace : ' at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
  32. at System.Environment.get_StackTrace()
  33. at getter(Object )
  34. at System.Management.Automation.DotNetAdapter.PropertyGet(PSProperty property)
  35. at System.Management.Automation.Adapter.BasePropertyGet(PSProperty property)
  36. at System.Management.Automation.PSProperty.GetAdaptedValue()
  37. at System.Management.Automation.PSProperty.get_Value()
  38. at System.Management.Automation.PropertyReferenceNode.GetValue(PSObject obj, Object property, ExecutionContext context)
  39. at System.Management.Automation.PropertyReferenceNode.Execute(Array input, Pipe outputPipe, ExecutionContext context)
  40. at System.Management.Automation.ExpressionNode.Execute(Array input, Pipe outputPipe, ExecutionContext context)
  41. at System.Management.Automation.ParseTreeNode.Execute(Array input, Pipe outputPipe, ArrayList& resultList, ExecutionContext context)
  42. at System.Management.Automation.StatementListNode.ExecuteStatement(ParseTreeNode statement, Array input, Pipe outputPipe, ArrayList& resultList, ExecutionContext context)
  43. at System.Management.Automation.StatementListNode.Execute(Array input, Pipe outputPipe, ArrayList& resultList, ExecutionContext context)
  44. at System.Management.Automation.ParseTreeNode.Execute(Array input, Pipe outputPipe, ExecutionContext context)
  45. at System.Management.Automation.ScriptCommandProcessor.ExecuteWithCatch(ParseTreeNode ptn, Array inputToProcess)
  46. at System.Management.Automation.ScriptCommandProcessor.RunClause(ParseTreeNode clause, Object dollarUnderbar, Object inputToProcess)
  47. at System.Management.Automation.ScriptCommandProcessor.Complete()
  48. at System.Management.Automation.CommandProcessorBase.DoComplete()
  49. at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input, Hashtable errorResults, Boolean enumerate)
  50. at System.Management.Automation.PipelineNode.Execute(Array input, Pipe outputPipe, ArrayList& resultList, ExecutionContext context)
  51. at System.Management.Automation.StatementListNode.ExecuteStatement(ParseTreeNode statement, Array input, Pipe outputPipe, ArrayList& resultList, ExecutionContext context)
  52. at System.Management.Automation.StatementListNode.Execute(Array input, Pipe outputPipe, ArrayList& resultList, ExecutionContext context)
  53. at System.Management.Automation.ParseTreeNode.Execute(Array input, Pipe outputPipe, ExecutionContext context)
  54. at System.Management.Automation.ScriptCommandProcessor.ExecuteWithCatch(ParseTreeNode ptn, Array inputToProcess)
  55. at System.Management.Automation.ScriptCommandProcessor.RunClause(ParseTreeNode clause, Object dollarUnderbar, Object inputToProcess)
  56. at System.Management.Automation.ScriptCommandProcessor.Complete()
  57. at System.Management.Automation.CommandProcessorBase.DoComplete()
  58. at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input, Hashtable errorResults, Boolean enumerate)
  59. at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecute(Array input, Hashtable errorResults)
  60. at System.Management.Automation.Runspaces.LocalPipeline.InvokeHelper()
  61. at System.Management.Automation.Runspaces.LocalPipeline.InvokeThreadProc()
  62. at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
  63. at System.Threading.ExecutionContext.runTryCode(Object userData)
  64. at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
  65. at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
  66. at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
  67. at System.Threading.ThreadHelper.ThreadStart()'
  68. SystemDirectory : C:\Windows\system32
  69. TickCount : 98385431
  70. UserDomainName : COOKHAM
  71. UserInteractive : True
  72. UserName : tfl
  73. Version : 2.0.50727.3074
  74. WorkingSet : 49385472
  75. ExpandEnvironmentVariables:
  76. My system drive is C: and my system root is C:\Windows
  77. GetEnvironmentVariable:
  78. My temporary directory is C:\Users\tfl\AppData\Local\Temp.
  79. GetEnvironmentVariables:
  80. Name Value
  81. ---- -----
  82. Path C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\Microsoft SQL Server\90\Tools\b...
  83. TEMP C:\Users\tfl\AppData\Local\Temp
  84. SESSIONNAME Console
  85. PATHEXT .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PSC1
  86. USERDOMAIN COOKHAM
  87. PROCESSOR_ARCHITECTURE x86
  88. ProgramW6432 C:\Program Files
  89. APPDATA C:\Users\tfl\AppData\Roaming
  90. windir C:\Windows
  91. LOCALAPPDATA C:\Users\tfl\AppData\Local
  92. CommonProgramW6432 C:\Program Files\Common Files
  93. TMP C:\Users\tfl\AppData\Local\Temp
  94. USERDNSDOMAIN COOKHAM.NET
  95. USERPROFILE C:\Users\tfl
  96. ProgramFiles C:\Program Files (x86)
  97. CommonProgramFiles(x86) C:\Program Files (x86)\Common Files
  98. FP_NO_HOST_CHECK NO
  99. HOMEPATH \Users\tfl
  100. COMPUTERNAME COOKHAM8
  101. CLASSPATH .;C:\Program Files (x86)\Java\jre6\lib\ext\QTJava.zip
  102. PROCESSOR_ARCHITEW6432 AMD64
  103. ProgramData C:\ProgramData
  104. NUMBER_OF_PROCESSORS 8
  105. PROCESSOR_IDENTIFIER Intel64 Family 6 Model 23 Stepping 6, GenuineIntel
  106. SystemDrive C:
  107. SystemRoot C:\Windows
  108. ComSpec C:\Windows\system32\cmd.exe
  109. LOGONSERVER \\COOKHAM1
  110. ProgramFiles(x86) C:\Program Files (x86)
  111. PSMODULEPATH C:\Users\tfl\Documents\WindowsPowerShell\Modules;C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Modules
  112. CommonProgramFiles C:\Program Files (x86)\Common Files
  113. PROCESSOR_LEVEL 6
  114. PROCESSOR_REVISION 1706
  115. QTJAVA C:\Program Files (x86)\Java\jre6\lib\ext\QTJava.zip
  116. ALLUSERSPROFILE C:\ProgramData
  117. VS90COMNTOOLS C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\
  118. PUBLIC C:\Users\Public
  119. USERNAME tfl
  120. OS Windows_NT
  121. HOMEDRIVE C:
  122. GetFolderPath: C:\Windows\system32
  123. GetLogicalDrives: C:\, D:\, E:\, F:\, G:\, H:\, I:\, J:\, K:\, L:\, Q:\, X:\
  124. .PARAMETER
  125. None, but if any are provided, they are displayed above
  126. #>
  127. ##
  128. # Start of Script
  129. ##
  130. # Setup two variables for later use
  131. [String] $str;
  132. [string] $nl = [System.Environment]::NewLine
  133. # Now display members of the environment class
  134. "-- Environment members --"
  135. # Assume: You Invoke this sample with an arbitrary set of command line arguments.
  136. "CommandLine : {0}" -f [system.environment]::CommandLine
  137. $arguments = [System.Environment]::GetCommandLineArgs()
  138. "GetCommandLineArgs: {0}" -f [system.string]::join(", ", $arguments)
  139. # <-- Keep this information secure! -->
  140. "CurrentDirectory : {0}" -f [System.Environment]::CurrentDirectory
  141. "ExitCode : {0}" -f [System.Environment]::ExitCode
  142. "HasShutdownStarted: {0}" -f [System.Environment]::HasShutdownStarted
  143. # <-- Keep this information secure! -->
  144. "MachineName : {0}" -f [System.Environment]::MachineName
  145. "NewLine : {0} first line{0} second line{0} third line" -f [System.Environment]::NewLine
  146. "OSVersion : {0}" -f [System.Environment]::OSVersion.ToString()
  147. "StackTrace : '{0}'" -f [System.Environment]::StackTrace
  148. # <-- Keep this information secure! -->
  149. "SystemDirectory : {0}" -f [System.Environment]::SystemDirectory
  150. "TickCount : {0}" -f [System.Environment]::TickCount
  151. # <-- Keep this information secure! -->
  152. "UserDomainName : {0}" -f [System.Environment]::UserDomainName
  153. "UserInteractive : {0}" -f [System.Environment]::UserInteractive
  154. # <-- Keep this information secure! -->
  155. "UserName : {0}" -f [System.Environment]::UserName
  156. "Version : {0}" -f [System.Environment]::Version.ToString()
  157. "WorkingSet : {0}" -f [System.Environment]::WorkingSet
  158. # No example for exit(exitCode) because doing so would terminate this example.
  159. # <-- Keep this information secure! -->
  160. $query = "My system drive is %SystemDrive% and my system root is %SystemRoot%";
  161. $str = [System.Environment]::ExpandEnvironmentVariables($query)
  162. "ExpandEnvironmentVariables: {0} {1}" -f $nl,$str
  163. "GetEnvironmentVariable: {0} My temporary directory is {1}." -f $nl,[System.Environment]::GetEnvironmentVariable("TEMP")
  164. ""
  165. "GetEnvironmentVariables: "
  166. [System.Environment]::GetEnvironmentVariables()
  167. "GetFolderPath: {0}" -f [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::System)
  168. [String[]] $drives = [System.Environment]::GetLogicalDrives()
  169. "GetLogicalDrives: {0}" -f [System.String]::Join(", ", $drives)
  170. #End of Script

Sunday, 2 August 2009

Convert-Double.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script is an updated MSDN sample showing converstion to int32, boolean, string 
  4.     and char. The sample is written using PowerShell 
  5. .DESCRIPTION 
  6.     This script 
  7. .NOTES 
  8.     File Name  : convert-double.ps1 
  9.     Author     : Thomas Lee - tfl@psp.co.uk 
  10.     Requires   : PowerShell V2 CTP3 
  11. .LINK 
  12.     This script posted to: 
  13.         http://www.pshscripts.blogspot.com 
  14.     MSDN Sample posted at: 
  15.         http://msdn.microsoft.com/en-us/library/system.convert.aspx 
  16. .EXAMPLE 
  17.     PSH [C:\foo]: .\convert-double.ps1' 
  18.     Converting 23.15 to an int32 = 23 
  19.     Converting 23.15 to an Boolean = True 
  20.     Converting 23.15 to a String = 23.15 
  21.     Converting 1st char of "23.15" to a char = 2 
  22. #> 
  23.  
  24. ## 
  25. # Start of sample 
  26. ## 
  27.   
  28. # Create double to convert 
  29. [system.double] $dNumber = 23.15 
  30.  
  31. # convert to int32 
  32. [int32] $iNumber = [System.Convert]::ToInt32($dNumber
  33. "Converting $dnumber to an int32 = $inumber" 
  34.   
  35. # convert to bool 
  36. [bool] $bNumber = [System.Convert]::ToBoolean($dNumber); 
  37. "Converting $dnumber to an Boolean = $bNumber" 
  38.   
  39. # convert to string 
  40. [string] $strNumber = [System.Convert]::ToString($dNumber
  41. "Converting $dnumber to a String = $strNumber" 
  42.   
  43. # convert a single char in the string to a char 
  44. [char] $chrNumber = [System.Convert]::ToChar($strNumber[0]); 
  45. "Converting 1st char of `"$strnumber`" to a char = $chrNumber" 
  46. # End of script 

Thursday, 9 July 2009

Copy-File.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script displays the usage of the Exists and the 
  4.     copy methods of System.IP.File   
  5. .DESCRIPTION 
  6.     This script sets up two file names, then checks to see if 
  7.     the sorucefile exists. if so, it's copied to a new file. 
  8. .NOTES 
  9.     File Name  : copy-file.ps1 
  10.     Author     : Thomas Lee - tfl@psp.co.uk 
  11.     Requires   : PowerShell V2 CTP3 
  12. .LINK 
  13.     This script posted to: 
  14.         http://www.pshscripts.blogspot.com 
  15.     MSDN Sample posted at: 
  16.         http://msdn.microsoft.com/en-us/library/system.io.file.exists.aspx 
  17. .EXAMPLE 
  18.     PSH [C:\foo]: .\Copy-File.PS1' 
  19.     Source File (c:\foo\Test.txt) copied to (c:\foo\Test2.txt) 
  20. #> 
  21.  
  22. ## 
  23. # start of script 
  24. ## 
  25.  
  26. # Setup source and destination files 
  27. $SourceFile = "c:\foo\Test.txt"
  28. $NewFile    = "c:\foo\Test2.txt"
  29.  
  30. # Now - check to see if $Sourcefile exists, and if so, 
  31. # copy it to $newfile  
  32. if ([System.IO.File]::Exists($SourceFile))  { 
  33.    [System.IO.File]::Copy($SourceFile, $NewFile
  34.    "Source File ($SourceFile) copied to ($newFile)" 
  35. else
  36. "Source file ($Sourcefile) does not exist." 
  37. # End of script 

Monday, 6 July 2009

Happy 1st Birthday To HTTP://PshScripts.Blogspot.Com!!!

I’ve been posting scripts here for just over a year – the first script was posted on July 5th 2008. There have been 127 posts, and the downloadable script library now has 141 scripts.

Here are some monthly stats for the past year:

 

image

The readership of the blog was not great till I started posting in ernest in November. Since then, there’s been a slow rise each month as more folks find the blog. When I first started this blog, the idea was to post just scripts – on the assumption that folks would find them using Google, et al. And that’s pretty much what has happened. Looking at the last 20 blog hits as an example: 3 of the 20 were direct access, with 17 coming from a referral. Of the 17 referrals, 12 came from Google (google.com, google.it, google.co.uk, google.bg, google.pl), 2 from Bing and one each from Hal Rotenbergs blog, Technet and PowerShell.com. It’s also clear that the readership is pretty international:

image

Technorati Tags:

I hope this blog and the scripts posted here have been of use. Please feel free to comment on other scripts you’d like to see here!

Compare-Int32.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script illustrates the CompareExchange Method 
  4. .DESCRIPTION 
  5.     This script creates three values, and calls CompareExchange method, 
  6.     and displays the results. The first time, we compare two non-equal values 
  7.     so no exchange is done. The second time, the comparison succeeds and the 
  8.     value us updated.    
  9. .NOTES 
  10.     File Name  : Compare-Int32.ps1 
  11.     Author     : Thomas Lee - tfl@psp.co.uk 
  12.     Requires   : PowerShell V2 CTP3 
  13. .LINK 
  14.     This script posted to: 
  15.         http://www.pshscripts.blogspot.com 
  16.     MSDN Sample posted at: 
  17.         http://msdn.microsoft.com/en-us/library/801kt583.aspx 
  18. .EXAMPLE 
  19.     PSH [C:\foo]: .\Compare-int32.PS1 
  20.     Before 1st call: 
  21.     42 
  22.     69 
  23.     104 
  24.   
  25.     After 1st call, before 2nd 
  26.     42 
  27.     69 
  28.     104 
  29.   
  30.     After 2nd call 
  31.     69 
  32.     69 
  33.     104 
  34. #> 
  35.  
  36. ## 
  37. # Start of Script 
  38. ## 
  39.  
  40. # Create 3 int32 values 
  41.  
  42. [int32] $a=42 
  43. [int32] $b=69 
  44. [int32] $c=104 
  45.  
  46. # Display values before 
  47. "Before 1st call:";$a,$b,$c 
  48. "" 
  49.  
  50. # Call CompareExchange and print results 
  51. # This call compares $a with $c, so there are not equal 
  52. $result = [System.Threading.Interlocked]::CompareExchange([ref]$a, $b, $c
  53. "After 1st call, before 2nd" 
  54. $a,$b,$c 
  55. "" 
  56.  
  57. # Call CompareExchange and print results 
  58. # This call compares $a with $A, so this call 
  59. # returns $a updated to $b 
  60. $result = [System.Threading.Interlocked]::CompareExchange([ref]$a, $b, $a
  61. "After 2nd call" 
  62. $a,$b,$c 

Wednesday, 1 July 2009

Compare-Double

  1. <# 
  2. .SYNOPSIS 
  3.     This script illustrates the CompareExchange Method 
  4. .DESCRIPTION 
  5.     This script creates three values, and calls CompareExchange method, 
  6.     and displays the results. The first time, we compare to non-equal values 
  7.     so no exchange is done. The second time, the comparison succeeds and the 
  8.     value us updated.    
  9. .NOTES 
  10.     File Name  : Compare-Double.ps1 
  11.     Author     : Thomas Lee - tfl@psp.co.uk 
  12.     Requires   : PowerShell V2 CTP3 
  13. .LINK 
  14.     This script posted to: 
  15.         http://www.pshscripts.blogspot.com 
  16.     MSDN Sample posted at: 
  17.         http://msdn.microsoft.com/en-us/library/cd0811yf.aspx 
  18. .EXAMPLE 
  19.     PSH [C:\foo]: .\Compare-Double.PS1
  20.     Before 1st call: 
  21.     42.42 
  22.     69.69 
  23.     104.4 
  24.   
  25.     After 1st call, before 2nd 
  26.     42.42 
  27.     69.69 
  28.     104.4 
  29.   
  30.     After 2nd call 
  31.     69.69 
  32.     69.69 
  33.     104.4 
  34. #> 
  35.  
  36. ## 
  37. # Start of Script 
  38. ## 
  39.  
  40. # Create 3 double values 
  41.  
  42. [double] $a=42.42 
  43. [double] $b=69.69 
  44. [double] $c=104.4 
  45.  
  46. # Display values before 
  47. "Before 1st call:";$a,$b,$c 
  48. "" 
  49.  
  50. # Call CompareExchange and print results 
  51. # This call compares $a with $c, so there are not equal 
  52. $result = [system.Threading.Interlocked]::CompareExchange([ref]$a, $b, $c
  53. "After 1st call, before 2nd" 
  54. $a,$b,$c 
  55. "" 
  56. # Call CompareExchange and print results 
  57. # This call compares $a with $A, so this call 
  58. # returns $a updated to $b 
  59. $result = [system.Threading.Interlocked]::CompareExchange([ref]$a, $b, $a
  60. "After 2nd call" 
  61. $a,$b,$c