- <#
- .SYNOPSIS
- This script displays the usage of the Exists and the
- copy methods of System.IP.File
- .DESCRIPTION
- This script sets up two file names, then checks to see if
- the sorucefile exists. if so, it's copied to a new file.
- .NOTES
- File Name : copy-file.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell V2 CTP3
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN Sample posted at:
- http://msdn.microsoft.com/en-us/library/system.io.file.exists.aspx
- .EXAMPLE
- PSH [C:\foo]: .\Copy-File.PS1'
- Source File (c:\foo\Test.txt) copied to (c:\foo\Test2.txt)
- #>
- ##
- # start of script
- ##
- # Setup source and destination files
- $SourceFile = "c:\foo\Test.txt";
- $NewFile = "c:\foo\Test2.txt";
- # Now - check to see if $Sourcefile exists, and if so,
- # copy it to $newfile
- if ([System.IO.File]::Exists($SourceFile)) {
- [System.IO.File]::Copy($SourceFile, $NewFile)
- "Source File ($SourceFile) copied to ($newFile)"
- }
- else {
- "Source file ($Sourcefile) does not exist."
- }
- # End of script
This blog contains PowerShell scripts, more PowerShell scripts and still more PowerShell scripts. Occasionally you may see some organisational posts.
Thursday, 9 July 2009
Copy-File.ps1
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:
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:
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
- <#
- .SYNOPSIS
- This script illustrates the CompareExchange Method
- .DESCRIPTION
- This script creates three values, and calls CompareExchange method,
- and displays the results. The first time, we compare two non-equal values
- so no exchange is done. The second time, the comparison succeeds and the
- value us updated.
- .NOTES
- File Name : Compare-Int32.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell V2 CTP3
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN Sample posted at:
- http://msdn.microsoft.com/en-us/library/801kt583.aspx
- .EXAMPLE
- PSH [C:\foo]: .\Compare-int32.PS1
- Before 1st call:
- 42
- 69
- 104
- After 1st call, before 2nd
- 42
- 69
- 104
- After 2nd call
- 69
- 69
- 104
- #>
- ##
- # Start of Script
- ##
- # Create 3 int32 values
- [int32] $a=42
- [int32] $b=69
- [int32] $c=104
- # Display values before
- "Before 1st call:";$a,$b,$c
- ""
- # Call CompareExchange and print results
- # This call compares $a with $c, so there are not equal
- $result = [System.Threading.Interlocked]::CompareExchange([ref]$a, $b, $c)
- "After 1st call, before 2nd"
- $a,$b,$c
- ""
- # Call CompareExchange and print results
- # This call compares $a with $A, so this call
- # returns $a updated to $b
- $result = [System.Threading.Interlocked]::CompareExchange([ref]$a, $b, $a)
- "After 2nd call"
- $a,$b,$c
Wednesday, 1 July 2009
Compare-Double
- <#
- .SYNOPSIS
- This script illustrates the CompareExchange Method
- .DESCRIPTION
- This script creates three values, and calls CompareExchange method,
- and displays the results. The first time, we compare to non-equal values
- so no exchange is done. The second time, the comparison succeeds and the
- value us updated.
- .NOTES
- File Name : Compare-Double.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell V2 CTP3
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN Sample posted at:
- http://msdn.microsoft.com/en-us/library/cd0811yf.aspx
- .EXAMPLE
- PSH [C:\foo]: .\Compare-Double.PS1
- Before 1st call:
- 42.42
- 69.69
- 104.4
- After 1st call, before 2nd
- 42.42
- 69.69
- 104.4
- After 2nd call
- 69.69
- 69.69
- 104.4
- #>
- ##
- # Start of Script
- ##
- # Create 3 double values
- [double] $a=42.42
- [double] $b=69.69
- [double] $c=104.4
- # Display values before
- "Before 1st call:";$a,$b,$c
- ""
- # Call CompareExchange and print results
- # This call compares $a with $c, so there are not equal
- $result = [system.Threading.Interlocked]::CompareExchange([ref]$a, $b, $c)
- "After 1st call, before 2nd"
- $a,$b,$c
- ""
- # Call CompareExchange and print results
- # This call compares $a with $A, so this call
- # returns $a updated to $b
- $result = [system.Threading.Interlocked]::CompareExchange([ref]$a, $b, $a)
- "After 2nd call"
- $a,$b,$c