| Richard's profileRichard Siddaway's BlogPhotosBlogLists | Help |
|
Richard Siddaway's BlogOf PowerShell and Other Things
June 08 SuspendedI won't be posting here for a while - until the current issues are sorted out.
Please see http://msmvps.com/blogs/RichardSiddaway/Default.aspx for all your PowerShell posts. Upgrade?Live.com has been upgraded – biggest change seems to be to the SkyDrive and we now get the ability to use Web versions of Office. May or may not be useful. Big downside is that the statistics on the blog have been removed. Can’t see who is accessing or number of hits. BAD MOVE – not happy about that. Live Writer has stopped working as well - VERY VERY BAD MOVE - very unhappy about that June 07 Ranged lettersWhile I was playing around with the range operator I thought of this
Define your start and finish letters. Convert each to a char and then a byte. This gives us the numeric value of the letter (ascii code). We can then use those values in the range operator and create the files as we have already seen. June 06 Using Range operator to generate lettersThe range operator is used to generate a sequential set of numbers 1..10 | foreach {$_} if we try this with letters PS> a..j | foreach {$_} However we can use the range operator to generate letters like this ## upper case ## lower case using the ACSII codes. if we want to create filea.txt – filej.txt we can simply do this 97..106 | foreach {New-Item -Path c:\test -Name "file$([char]$_).txt" -ItemType File} Nice and simple one line of PowerShell. Using the range operatorOne of the events in this years scripting games involved creating a set of files. Many of the entries did something like this
A list of files is created and a foreach is used to call New-Item. A variant on this used a for loop for ($i=0; $i –le 9; $i++){New-Item -Path c:\test -Name $files[$i] -ItemType File}
There is a much easier way
Whenever you have to deal with lists of things that are numerically sequential – try to use the range operator. |
|||||||||||
|
|