How to set the title of my Console Window

The PowerShell team's blog posted this great script on their blog today.

http://blogs.msdn.com/powershell/archive/2006/07/17/How_to_I_set_the_title_of_my_Console_Window.aspx

If you are not subscribed to the PowerShell Team blog and you are using or thinking about using PowerShell...where have you been.  They are awesome!!

Subscribe now to it...plus don't forget to subscribe to mine.  (I know, shameless plug)

Jeffrey Snover has really posted a lot of great stuff on this blog.

 

Use a WaitKey Function in Windows PowerShell

Got this from TechNet Script Center

Use a WaitKey Function in Windows PowerShell

Submitted By: Greg Lyon

Language: Windows PowerShell

Description: Sample script that adds a WaitKey function to a Windows PowerShell script.

Script Code

function WaitKey ( [string] $strPrompt = "Press any key to continue ... ")
{
    Write-Host
    Write-Host $strPrompt -NoNewline
    [Console]::ReadKey($true) > $null
    Write-Host
}

# Example:
Write-Host "This is a test of WaitKey"
WaitKey "Press any key to exit ... "
WaitKey
Write-Host

PowerShell and Exit Codes

Today on the PowerShell email lists a question was brought up how to find the exit code of a program.

The solution:

$LastExitCode

 

Here is an example I found online:

function CheckExitCode {
param ([string]$failureMessage, [int[]]$successCodes = @(0), $finallyScript=$null)

$res = $successCodes -contains $LastExitCode
if ($res.Length -eq 0) {
write-error "ERROR CODE ${LastExitCode}: $failureMessage"
if ($finallyScript) {
"Executing finally:"
&$finallyScript
}
exit 1
}
}

Use like so:

tf checkin $file /noprompt
CheckExitCode "Checkin of $file" @(0) {tf undo $file /noprompt}

RSS feeds added to myITforum.com Forums!

As Rod pointed out to the email lists...you can now subscribe to a RSS Feed to get all the latest forum posts.

Plug www.myitforum.com/forums/rss/rss.asp into your favorite RSS Feed reader.

 

Change to blog

I made a change to my blog today.


I also added a new skin, Developer, to the list of available blogs for myITforum.com, Inc. bloggers.

 

Have fun!

Exchange Tools that PSS uses

Here is a link to the common tools the Microsoft Exchange PSS folks use.

 

ftp://ftp.microsoft.com/pss/tools/Exchange%20Support%20Tools/

Powershell Remote

http://www.gotdotnet.com/Workspaces/Workspace.aspx?id=ce09cdaf-7da2-4f1c-bed3-f8cb35de5aea

What is PowerShell Remoting
Windows PowerShell® (codename Monad) is next generation of command line interface in Microsoft Windows platform. Powershell does not provide remote access functionality in version 1. It is planned for version 2.

PowerShell Remoting is a light-weighted server-client application which allow you securely connect to remote PowerShell host and run script interactivly.

It contains two components:

Server: A managed windows service component. It will listen at certain TCP port, accept income connection, authenticate client and provide PowerShell hosting environment.

Client: A managed class library. It severs as a proxy between remote sever user interface and local client user interface. It will connect to server, establish a sevure channel, get user input and display results.

Download here!

 

Backup Files Using Windows PowerShell

http://www.microsoft.com/technet/scriptcenter/csc/scripts/backup/backup/cscbk013.mspx

Backup Files Using Windows PowerShell

Submitted By: Greg Lyon

Language: Windows PowerShell

Description: Backs up files using Windows PowerShell.

Script Code

Backup Files Using Windows PowerShell

# BackupFiles.ps1
# Greg Lyon - July 2006

# -----------------------------------------------------

function BackupFolder
{
    param( [object] $objSrcFolder, [object] $objDstFolder)

    $strSrcFolder = $objSrcFolder.Path
    $strDstFolder = $objDstFolder.Path

    $colSrcFiles = $objSrcFolder.Files
    $colDstFiles = $objDstFolder.Files

    foreach ($objSrcFile in $colSrcFiles)
    {
        $strSrcFile = $strSrcFolder + "\" + $objSrcFile.Name
        $strDstFile = $strDstFolder + "\" + $objSrcFile.Name
        if($FSO.FileExists($strDstFile))
        {
            $objDstFile = $FSO.GetFile($strDstFile)
            $dtSrcFile = $objSrcFile.DateLastModified
            $dtDstFile = $objDstFile.DateLastModified
            $iSec = (New-TimeSpan -Start $dtDstFile -End $dtSrcFile).TotalSeconds
            if($iSec -gt 2) # allow 2 seconds difference for CD, network drive etc.
            {
                $FSO.CopyFile($strSrcFile, $strDstFile, $true)
                Write-Host "Copied file $strSrcFile to $strDstFile"
                $script:iCopyCount++
            }
        }
        else
        {
            $FSO.CopyFile($strSrcFile, $strDstFile, $true)
            Write-Host "Copied file $strSrcFile to $strDstFile"
            $script:iCopyCount++
        }
    }

    foreach($objDstFile In $colDstFiles)
    {
        $strDstFile = $objDstFile.Path
        $strSrcFile = $strSrcFolder + "\" + $objDstFile.Name

        if( -not $FSO.FileExists($strSrcFile))
        {
            $FSO.DeleteFile($strDstFile)
            Write-Host "Deleted file $strDstFile"
            $script:iDestDeletedCount++
        }
    }

    DoSubFolders $objSrcFolder $objDstFolder
}

# -----------------------------------------------------

function DoSubFolders
{
    param([object] $objSrcFolder, [object] $objDstFolder)

    $colSrcSubFolders = $objSrcFolder.SubFolders

    foreach($objSrcSubFolder in $colSrcSubFolders)
    {
        $strSrcSubFolder = $objSrcSubFolder.Path
        $strDstSubFolder = $strSrcSubFolder.Replace($strSourceFolder, $strDestinationFolder)
        if( -not $FSO.FolderExists($strDstSubFolder))
        {
            $FSO.CreateFolder($strDstSubFolder)
            Write-Host "Created folder $strDstSubFolder"
        }
        $objDstSubFolder = $FSO.GetFolder($strDstSubFolder)
        BackupFolder $objSrcSubFolder $objDstSubFolder
        DoSubFolders $objSrcSubFolder $objDstSubFolder
    }
}
# -----------------------------------------------------
function WaitKey
{
    param( [String] $strPrompt = "Press any key to continue ... ")
    Write-Host
    Write-Host $strPrompt -NoNewline
    $key = [Console]::ReadKey($true)
    Write-Host
}

# -----------------------------------------------------
# main

$strSourceFolder      = "D:\PS1"
$strDestinationFolder = "E:\Drive_D_Copy\PS1"

$iCopyCount = 0
$iDestDeletedCount = 0

Write-Host
Write-Host "Backing up " -NoNewline -ForegroundColor "White"
Write-Host $strSourceFolder -ForegroundColor "Cyan" -NoNewline
Write-Host " to " -NoNewline -ForegroundColor "White"
Write-Host $strDestinationFolder -ForegroundColor "Cyan"
Write-Host

$FSO = New-Object -COM Scripting.FileSystemObject

if( -not $FSO.FolderExists($strSourceFolder) )
{
    Write-Host "Error: source folder does not exist!" -ForegroundColor "Red"
    Write-Host
    Write-Host "Exiting script"
    WaitKey "Press any key to exit ... "
    exit
}

if( -not $FSO.FolderExists($strDestinationFolder) )
{
    Write-Host "Warning: destination folder does not exist"
    $p = Read-Host "Create folder and continue? "
    Write-Host
    if( $p.Substring(0, 1).ToUpper() -eq "Y" )
    {
        $FSO.CreateFolder($strDestinationFolder)
    }
    else
    {
        Write-Host "Exiting script"
        WaitKey "Press any key to exit ... "
        exit
    }
}

$objSourceFolder = $FSO.GetFolder($strSourceFolder)
$objDestinationFolder = $FSO.GetFolder($strDestinationFolder)

BackupFolder $objSourceFolder $objDestinationFolder

if( ($iCopyCount -eq 0) -and ($iDestDeletedCount -eq 0) )
{
    Write-Host
    Write-Host "Folders are synchronized" -ForegroundColor "magenta"
}
else
{
    Write-Host
    Write-Host $iCopyCount "files copied from source to destination" -ForegroundColor "magenta"
    Write-Host $iDestDeletedCount "orphaned destination files deleted" -ForegroundColor "magenta"
}

WaitKey "Press any key to exit ... "

# -----------------------------------------------------

With Clarence Washington’s scripting site closing...now what?

With Clarence Washington’s scripting site closing where are you going to go for all the scripts?

Well...myITforum.com, Inc. has the answer...

It's the myITforum.com, Inc. Code Repository.

The Code Repository and all the Code Packs have a lot, if not all of the scripts that were on Clarence Washington's scripting site.

The Code Repository has been around for a long time, but it still being used and downloaded everyday! 

So, you want to grab some of those awesome script from Clarence Washington's site...find them in the Code Repository!

 

 

Taking the kids to the zoo

Going back to Louisville to the Zoo tomorrow.


My daughter has been driving me crazy, so tomorrow we are going to the zoo before we are driving crazy from her asking every 5 minutes.  Then we are heading back to the mother-in-laws for our 4th of July celebration.

WOW, the power my kids have over me.

This day, only 8 years ago

is the day my Wife, Martha, and I got married.

 

I can't believe it has been eight years.  I know I have not always been the greatest person in the world, but yet she has endured me through the years.

We have 3 wonderful kids - Nate, Abby, and Cole.

Two Camaros - 1967 adn 1994.  

One cat.

So, needless to say Martha has a lot to tackle each and everyday. 

Not to mention, I'm writing a book and have zero free time...

WOW...once you start reflecting on things, it is amazing how my wife does it!

Anywho...Just wanted everyone to know just how much I love my wife!

 

Happy Anniversary Martha, I love you!

 

Got my MMS DVD today...

Time to see how I sounded during my two presentations.

 

If you are ever in Louisville, KY you need to eat at...

The Red Star Tavern.

It was a really nice place to eat.

Rod and Meg met Martha (my wife) and me there for lunch today.


Afterwards, we HAD to go get ice cream at Cold Stone Creamier...which is just across the street.  They have great ice-cream.

 

 

Rod is realizing just how GREAT Kentucky is...

Two trips in two days...

 

Even though one is for myITforum.com, Inc business...Rod realizing just how great it would be to live in Kentucky.


Rod even talks about building in Kentucky.

 

 

How IT Works-SMS Client-Side Software Installation

More Posts Next page »