This web site uses Kentico CMS, the content management system for ASP.NET developers.

Community > Blogs > Max-PIT> SQL-Server and PowerShell > November 2008 > Two Tips you can use in SQLPS.exe
 

Two Tips you can use in SQLPS.exe

There's two things I found myself when starting to work with SQL Server 2008 SQLPS shell:

1. Drill-through the SQL Server path gets longer, longer, longer...
 SQLPS long Path

2. How can I find the list of all Cmdlets? Get-Command by itself doesn't give list.
No Get-Command results

Well, don't hesitate, there's a few things you can do to overcome these small limitations.

The answer for #1. I wrote the simple script that will change the prompt but there's a caveat.  Beside, building the script, you need to include it in the SQLPS *startup, or you can copy paste the code.
 

Changing PS prompt

################################################
## chg_Prompt.ps1
## Author: Max Trinidad, 05/03/2008
################################################

function prompt
{
    "PS ["+$host.UI.RawUI.CursorPosition.Y+"] > "
}


Result:
New SQLPS prompt

*note: To get more information on customizing the SQLPS, take a look at "Michiel's Wories Blog" were you'll find a section on SQLPS startup script.

Then, answer #2.  I wrote another script that will loop through A-Z and do a Get-Command to list all possible Cmdlets starting with a letter of the alphabet.
 

Building you SQLPS list of cmdlets

#########################################################
## SQLps_CmdletListing.ps1                             ##
## Author: Max Trinidad, 11/03/2008                    ##
##-----------------------------------------------------##
## Comment: PS script to list all cmdlets in SQLPs.exe ##
#########################################################

$pathOut = 'C:\temp\SQLPS_cmdLets.txt'
[string] $a = "abcdefghijklmnopqrstuwvxyz"
[string] $x
[int] $c

#--If the file already exist then delete
$FileSystem = new-object -com "Scripting.FileSystemObject";
if ($FileSystem.FileExists($pathOut)) {
 $FileSystem.DeleteFile($pathOut) ; };

for ($c = 0; $c -lt ($a).length; $c ++ ) {
 $x = $a[$c] + '*';
 try {
   get-command $x -commandtype cmdlet | Select commandType, Name | Out-file $pathOut -append;
  }
 Catch {
   Write-Host -Foreground red "****< $x - not found >****";
   "****< $x - not found >****" | Out-file  $pathOut -append;
  }
 }
ii 'C:\Temp\SQLPS_cmdlets.txt' 
gc 'C:\Temp\SQLPS_cmdlets.txt' | more

 


Result:


(This PS Script will return results to the screen and build a *.txt file.)

Feel free to make changes and make it your own code.  At least, this is a starting point.

I hope you'll find these scripts useful.
Thanks,
Max Trinidad
FLPSUG

Posted: 11/3/2008 7:35:59 PM by Global Administrator | with 0 comments


Comments There are no comments on this post.

Title

In this blog section I will provide some valid samples currently use at my workplace.  I'll be covering SQL Server version: 2000, 2005, and 2008.  Also, I will post some information on SQLPS.exe.

Take a look at the three part series on:
1. Connecting to SQL Server
2. Executing a SQL Command (using "Delete from...")
3. Read/Display Data from SQL Server

l be posting more thing in the near future such as using SMO and doing some SQL admin operations.  

 

Syndication

RSS
This web site uses Kentico CMS, the content management system for ASP.NET developers.