Start using the Help cmdlet in Windows PowerShell

You want to get started with Windows PowerShell?  The answer is at your fingertips.  The truth is, beside all the good books, you got everything you need already included with Windows PowerShell.  Have you use the “Help” cmdlet in PowerShell?  If not, then you are missing some of the most extensive documentation PowerShell have made available since its release.  There’s a LOT of information that can help you get started in understanding and writing PowerShell scripts.

Just type “Help About_*” and press enter:

image_thumb10

As you can see, all this information is available to you.  This will help you understand how to write functions, how to use operators, Aliases, Parameters, Hash Tables, and more.  Don’t be intimidated by all this information.  I recommend you to use “Help” and then you can search on the internet or reading a book for more in depth information.

By the way, this information can be found online under Microsoft TechNet.  Here an example link looking at the Help on “About_Operators”: http://technet.microsoft.com/en-us/library/dd347588.aspx

image_thumb13

So, how many About_* topics can be found under PowerShell V2?  To find out type the following command:

(help about_*).count    (press enter)

image_thumb9

You will find there’s a total of 95 topics.  This is only the “About_*” topics.  So, as you can see,  this information is available at your fingertips.  So, use it and start learning Windows PowerShell.  

Go ahead and try it!!!

Surprise!! SQL Server 2008 R2 has new PowerShell Cmdlets…

Yes!!  I just found out the new version of SQL Server 2008 R2 has new PowerShell Snapin called “MasterDataServicesSnapin” and it will give 7 new cmdlets:

New-MasterDataServicesDatabase – Creates a Master Data Services database.

Get-MasterDataServicesDatabase – Gets information about a Master Data Services database.

Get-MasterDataServicesDatabases – Gets information about Master Data Services databases on a specified instance of SQL Server.

Get-MasterDataServicesDatabaseServerInformation – Gets connection information for a specified instance of SQL Server.

Get-MasterDataServicesIISInformation – Gets information about Internet Information Services (IIS) on the local computer.

Set-MasterDataServicesSystemSetting – Sets the value of a specified system setting in a Master Data Services database.

Get-MasterDataServicesSystemSettings – Gets system settings from a specified Master Data Services database.

Remember! To make these cmdlets available just use the cmdlet to add the pssnapins:

Add-PSSnapIn MasterDataServicesSnapIn

Additional information can be found: http://technet.microsoft.com/en-us/library/ff487033.aspx

#SQLSat 40 – First SQL PowerShell track winners…

#SQLSat40 – I just emails 7 winners who attended our first #SQL Server #PowerShell Track-2 PSP editor, 2 PrimalScript2K9 & 3 PrimalSQL 2K9 were given away.

Congratulation to the winners:

Jeff Cuscutis PrimalSQL 2009
Bill Ehrreich PrimalSQL 2010
Craig Bourque PrimalSQL 2011
Justin Sheldon PrimalScript 2009
Kendra Little PrimalScript 2010
Shajay Das Idera PowerShell Plus
Diosmar Perez Idera PowerShell Plus

Please check your emails!

Thanks for attending SQLSatuday South Florida Event on July 31st 2010.

Max Trinidad

SQLSaturday 40 So.Florida–The first SQL PowerShell Track was a Successful event.

clip_image002

Thanks to the SQLSaturday organizers to allow us create the first official SQL PowerShell Track.  All sessions were full of people and all speakers gave excellent material.  Also, without the participation of all attendees, you all made it possible.

This was a great event. Here’s some pictures:

clip_image004Ron Dameron, full house. clip_image006SAPIEN’s David Corrales, Visual PowerShell 2011. clip_image008Aaron Nelson with Andy Warren.
clip_image010Myself (Max Trinidad) clip_image012Speaker Dinner at Pembroke Pines “Longhorn Restaurant”. clip_image014SQLSaturday closing event.

Also, special “Thanks!!”, both SQLSaturday and PowerShell sponsors who provided some excellent giveaways during our sessions: SAPIEN, QUEST/PowerGui, and IDERA.

SAPIEN BUTTON LOGO 2.5 inch with TEXT® clip_image016 clip_image017

Come and see us again on Saturday, October 16th in Orlando SQLSaturday #49.

Ready, Set, Go SQLSaturday !!! Come to see us…

Yes! The stage is set, and we are ready to give some Awesome presentations.  Please, don’t be a stranger!! Come to both upcoming SQLSaturday events: South Florida (SQLSat40) and Orlando (SQLSat49).   We finally organized a full day of PowerShell.  It’s going to be fun and very informative.

Please, click on the following link for both the registration and to see the full event schedule with all other great tracks at:

On July 31st, South Florida SQLSaturday #40: http://www.sqlsaturday.com/40/schedule.aspx

On October 16th, Orlando SQLSaturday #49: http://www.sqlsaturday.com/49/schedule.aspx

Here’s the PowerShell Tracks for both events:

Start Time SoFla – SQLSaturday #40 – PowerShell Track
8:30 AM Ronald Dameron
  Why SQL Server DBAs should learn PowerShell
9:45 AM Ronald Dameron
  Automate ID Administration w/ PowerShell & SQLPSX
11:00 AM Aaron Nelson
  PowerShell for the Data Professional
1:00 PM David Corrales
  Sneak Preview: SAPIEN’s Visual PowerShell 2011
2:15 PM Maximo Trinidad
  Working with SQL Server – SQLPS
3:30 PM Maximo Trinidad
  Using PowerShell with SQL Server Agent
8:30am Argenis Fernandez
  Multi-Server Management with SQL Server 2008+
Start Time Orlando -SQLSaturday #49 – Powershell Track
9:00 AM Maximo Trinidad
  Working with SQL Server – SQLPS
10:15 AM Aaron Nelson
  The Dirty Dozen: PowerShell Scripts for Busy DBAs
11:30 AM Maximo Trinidad
  Using PowerShell with SQL Server Agent
1:15 PM Ron Dameron
  Why a DBA Should Learn PowerShell (MINI)
1:30 PM Ronald Dameron
  Automate Login Administration & Compliance Reports
2:45 PM Aaron Nelson
  PowerShell 2.0 Beyond the Dirty Dozen
4:00 PM Chad Miller
  ETL with PowerShell

Remember, Registration is free!!

Invoke-SQLCmd minor issue running some SQL Stored-Procedures…

First time I notice something strange with “Invoke-SQLCmd”, I was when executing the system Stored-Procedure “SP_Who2” and got the following error message:

PS C:\Users\Max> $sqlWho = Invoke-Sqlcmd “SP_Who2”
Invoke-Sqlcmd : The pipeline has been stopped.
At line:1 char:24
+ $sqlWho = Invoke-Sqlcmd <<<<  “SP_Who2”
    + CategoryInfo          : InvalidOperation: (:) [Invoke-Sqlcmd], PipelineStoppedException
    + FullyQualifiedErrorId : SqlExectionError,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand

Invoke-Sqlcmd : A column named ‘SPID’ already belongs to this DataTable.
At line:1 char:24
+ $sqlWho = Invoke-Sqlcmd <<<<  “SP_Who2”
    + CategoryInfo          : InvalidOperation: (:) [Invoke-Sqlcmd], DuplicateNameException
    + FullyQualifiedErrorId : SqlServerError,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand

PS C:\Users\Max>

I was trying to create a collection of object with the results from my “SP_Who2” and got the error stating “.. A column named ‘SPID’ already belongs to this DataTable..”.   So, I end up scripting out the SP_Who2, finding there are two columns with the same name ‘SPID’ and PowerShell didn’t like it.  I made the change to rename one of the columns to be SPID2 and save the T-SQL script to my PowerShell script file. 

And, the next time the ran my “Invoke-SQLCmd”, I had no problems and got my results so I could manipulate my .NET objects.

So, this is to make you aware that you will experience this minor issues when executing some of the SQL system stored-procedures.  And, for those who wonder… is this a BUG??  I really don’t think so!!  Because, the issue is in some of the system stored-procedures.  Should I submit this issue to the SQL Team to fix all stored-procedures generating columns with the same name?  This could be a major and unnecessary task.  Anyway, you were served!!

Happy PowerShelling!!

QuickBlog: Build a list of SQL Server without SMO…

Here I’m sharing a piece of PowerShell  code snippet which allow you to create a string array of all your SQL Server with their instances.  This code is a .NET namespace and use the enumerator class “SqlDataSourceEnumerator” to give you all available SQL Server instances in your network.

Just go ahead and give it a try:

$SQLInst = [System.Data.Sql.SqlDataSourceEnumerator]::Instance.GetDataSources() `
| select @{Expression={if(($_.InstanceName).length -gt 0)`
{$_.ServerName+"\"+$_.InstanceName}else{$_.ServerName}}; Name="SQLName"}
[Array] $MyServers
$MyServers = foreach($i in $SQLInst) {$i.SQLname}

Please, notice I’m using the reverse accent character for line continuation so it’s easy to view.  This is a good code snippet, if you need to provide a script solution that may required to get some SQL information from scheduled task on a server that have no SQL engine installed.

Hint: Now, you may have another way to void typing all your server in your PowerShell script.

Also, take a look at this other blog from Thomas LaRock “SQL RockStar” about “Finding Servers on Your Network” – Excellent material – http://thomaslarock.com/2009/12/finding-servers-on-your-network/  (Thanks to Chad Miller! For providing the link)

Here’s another snippet using above Thomas LaRock blog but I use PowerShell to extend the command “sqlcmd /L”:

$s = sqlcmd /L
[array] $Servers = $null
[array] $Servers = foreach($i in $s){if($i.length -gt 0){$i.Trim()}}
$Servers

Happy PowerShelling!!!

🙂

Technorati Tags: ,