Updates from December, 2008 Toggle Comment Threads | Keyboard Shortcuts

  • Chris 7:13 pm on December 31, 2008 Permalink | Reply
    Tags: Microsoft Answers   

    New Microsoft Site in beta “Microsoft Answers.” 

    I just thought I pass this on I ran into this site still in beta looks like called Microsoft Answers where any User (at any level of experience) can find answers for there computer problems. With all the information out there on different subjects about Windows this is just another site to add to your collection .

    Click to go to Site.

    A nice feature I find is RSS feeds that you can add to your reader so you get the latest information . I know your going to say so what all sites have these … well it still s nice to have 🙂

     *** Update this is for Windows Vista looks like … I thought it might be for all editions .. Not !

    Happy New Year !


  • Chris 8:22 pm on December 27, 2008 Permalink | Reply
    Tags: Advanced Functions,   

    Advanced Functions with Powershell –Having some Fun! 

    Hi Folks ,

    Since Powershell V2 CTP3 is out and an important feature called Advanced Functions is a totally new way to create Functions should make your scripts easier . Easier being the key word so far I’m trying to get used to them. In order to learn this new style I decided to go back to an earlier blog I did called Playoff Sunday with powershell. So I decided to do this script over with the new Advanced Function format . I will explain it after I show the script here :

    Outputs random football Score for each team entered on the pipeline
    This script outputs a random score for each football team entered into the pipeline
    .Parameter Team
    PS> "Cowboys","Giants" | .\get-footballscore.ps1 | ft -auto



    NAME: Get-FootballScore.ps1
    AUTHOR: Chris Federico
    LASTEDIT: 12/27/2008


    [Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)]


    #reset all values ;
    $intMaxNumofScores = 0
    $intTypeofScore = 0
    $s = 0
    $FinalScore = 0

    #create random max number of scores from 1-7
    $intMaxNumofScores = get-random -min 1 -max 5

    for ($s = 1;$s -le $intMaxNumofScores;$s++)

    $intTypeofScore = get-random -min 1 -max 3

    switch ($intTypeofScore)
    1 {$intTypeofScore = 7} #Touchdown
    2 {$intTypeofScore = 3} #FieldGoal
    3 {$intTypeofScore = 2} #Safety
    $FinalScore = $FinalScore + $intTypeofScore

    $obj = New-Object PsObject
    $obj | Add-Member NoteProperty Team([string]$Team)
    $obj | Add-Member NoteProperty Score([int]$FinalScore)
    Write-Output $obj

    If you break it up into parts its easier to understand . the First part is what is called the in line help (What is in between the <# and #> tags). Now you can provide your own help for your functions and link them to the common parameters already included in other cmdlets like -erroraction or -verbose …

    So by providing the above inline help I can then use this to get help :

    get-help .\get-footballScore.ps1 -full


    Outputs random football Score

    D:\Development\scripts\powershell\Get-FootballScore.ps1 [-Team] [] [-Verbose] [-Debug] [-ErrorAction []] [-WarningAction [ ce>]] [-ErrorVariable []] [-WarningVariable []] [-OutVariable []] [-OutBuffer []] []

    This script outputs a random score for each football team entered into the pipeline


    Required? true
    Position? 0
    Default value
    Accept pipeline input? true (ByValue)
    Accept wildcard characters?
    This cmdlet supports the common parameters: -Verbose, -Debug,
    -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable,
    -OutBuffer and -OutVariable. For more information, type,
    “get-help about_commonparameters”.




    NAME: Get-FootballScore.ps1
    AUTHOR: Chris Federico
    LASTEDIT: 12/27/2008

    ————————– EXAMPLE 1 ————————–

    PS> “Cowboys”,”Giants” | .\get-footballscore.ps1| ft -auto


    That is some cool Stuff what you can probably do is create a template with the the different parts so you don’t have to create them .

    The next part is to declare your parameters . There are different ways to do this depending on how many parameters your passing into the function [parameter(position=0), what position they are in , what type [string] [int] , If the parameters are being passed in from the pipeline ValueFromPipeline=$true, You can also declare a default parameter I believe this way [cmdletdefaultparameter] (?). This is something I will need to get used too . Some of it was already there but other syntax I need to get used too.

    The rest of the script I’m basically doing a bunch of random numbers . Its based on the # of scores randomly between 1 and 7 times . You can play with this a bit . Its not scientific at all but the maint thing was that I wanted to practice passing in parameters from the pipeline using advanced functions because this is the way powershell is going . There are so many more things new in V2 CTP 3 … Remoting ,Eventing … Creating Jobs against a bunch of Machines is very promising . Its like parallel processing almost .

    Here is an example of a Cowboys vs Giants Score :
    “Gaints”,”Cowboys” |D:\Development\scripts\powershell\Get-FootballScore.ps1 | ft -auto

    Team Score
    —- —–
    Gaints 16
    Cowboys 13

    Subtle but you get the idea ….

    Happy Holidays !

    • Yep 9:06 pm on April 7, 2009 Permalink

      Can you spare me some thoughts for pinging multiple servers in parallel & catching their results in an array

  • Chris 12:55 am on December 24, 2008 Permalink | Reply
    Tags: Powershell CTP3   

    Powershell V2 CTP3 Out ! 

    If you would like to test it out go here .

    A bunch of new features : cmdlets, Ability to create advanced functions . This caught my eye :

    get-hotfix -comp Server01 -cred domain\yourusername

    Having the -cred parameter is optional if your current user name has rights . If your using the -cred it prompts you for the password . How cool is that ?

    When was the last time you used a scripting language that got you hot fixes on a remote machine in one line?


  • Chris 4:23 pm on December 21, 2008 Permalink | Reply
    Tags: Christmas   

    Its Christmas Time ! 

    Check out the The 12 Guido Days Of Christmas . You can support them by purchasing this song on Itunes.

    Happy Holidays!


  • Chris 4:16 pm on December 21, 2008 Permalink | Reply
    Tags: Clustering,   

    Powershell will be built into Clustering Starting R2 

    I was reading Doug Finke’s Blog and he provided a link to what the Clustering team at Microsoft is doing with Windows 2008 R2 out in beta . They have created a bunch of cmdlets for Clustering  … very cool stuff . Cluster.exe will become legacy . This should help Administrators with Automating clustering functions . Check it out and also check out Doug’s blog which is very good also.


  • Chris 11:15 am on December 9, 2008 Permalink | Reply
    Tags: ,   

    VBscript to Powershell Script . 

    I thought it would be cool to convert a vbscript to powershell . I took just a simple vbscript from the Hey Scripting Guys column here . The following is the vbscript:

    Set objFS = CreateObject("Scripting.FileSystemObject")
    Set objRegExp = new RegExp
    objRegExp.Pattern = "((?:(\d{1,2}|[a-fA-F]{1,2}){2})(?::|-*)){6}"
    Set objFile = objFS.OpenTextFile("C:\logs\logfile.txt")
    strFileContents = objFile.ReadAll
    arrLines = Split(strFileContents,vbNewLine)

    For Each strLine in arrLines
    Set colMatches = objRegExp.Execute(strLine)
    For Each strMatch in colMatches
    WScript.Echo strMatch

    This script extracts MAC addresses from a log file . Lets say you had a delimited text file with this info,00-00-00-00-00-00,T

    Here is what I came up with in powershell

    ## Extracting a MAC Address

    $re = [regex]"((?:(\d{1,2}|[a-fa-f]{1,2}){2})(?::|-*)){6}"
    gc ".\log.txt" | % { $matches = $re.Match($_)};$matches.Value

    The toughest part is creating the regex .

    Happy Holidays


Compose new post
Next post/Next comment
Previous post/Previous comment
Show/Hide comments
Go to top
Go to login
Show/Hide help
shift + esc