As you all may know, MS added an entire new command and scripting language, PowerShell, as part of the base OS starting with Windows-7. Although it has been available with XP as a downloadable component, it has really been made into, what you call, a first-class citizen with Windows-7 – it’s included with OS and exposes 236 CmdLets that cover a vast gamut of functions, from querying services to running remote jobs.
I have been playing with PowerShell for sometime now and I have come to the conclusion that, it’s a powerful tool in an S3D Admins toolkit. The scripting language is simple to start-with and is targeted at admins rather than developers; although you can create real complex scripts with it.
Here’s a simple (because of the syntax) but useful example, that queries for services on different servers that start with the name “MSSQL*”:
As you can see, in one-line, you are able to run a command, Get-Service, against multiple remote machines, and have the output returned in a nicely formatted table, sized to fit the console window. I think this pretty much conveys the power and depth of the PS language and supporting environment. Hopefully this should pique your interest in knowing more about PowerShell and seeing how it may best fit in your work environment. I won’t go over much on the language & it’s syntax, since MS sites have loads of information on it.
What I will go over now, are the CmdLets, that have been added to SCA (V5.3), which I think will surely benefit 3D Admins. I’ll go over in detail, how to use the CmdLets, including configuration and options.
Step 1 – Find your PowerShell Modules Path
The SCA CmdLets are included as a PowerShell module, that need to be installed in your PS module-search-path. The easiest was to find this is, to query for the Env:/PSModulePath variable as shown in the bitmap below:
So you would create a folder called, SCACommands, underneath one of your module search paths and copy the downloaded files into that folder, as shown below:
Step 2 – Confirm Module Availability
The next step is to make sure that the module is available to be loaded. You can do that by running the command, Get-Module -ListAvailable, and it should list SCACommands, as one of the modules:
Step 3 – Import SCACommands & List Functions
The next step would be to load SCACommands module using, Import-Module SCACommands. You can then check the functions exposed by the module, by running, Get-Command -Module SCACommands. If everything goes well, you should see the output below:
Step 4 – Using Get-SCAServers
This CmdLet allows you to quickly list all the servers registered with SCA. The name coln is important here, since that is what Get-SCADbServerInfo and Get-SCAPerfCounters CmdLets, require as an input. The Get-SCAComputerInfo requires a hostname instead, so that you don’t have to register all machines in SCA.
Step 5- Using Get-SCAComputerInfo
This CmdLet lets you easily gather hardware and OS specs from a machine including logged on users. It requires a hostname as input and the machine does not have to be registered with SCA.
You can use a command line like, $comp = Get-SCAComputerInfo localhost , to store the information in a local variable, called $comp. You can then output useful information like hard-disk specs, video-card info, etc. as shown above. To query more than a single machine, use pipeline input as in, ‘machine1’, ‘machine2’ | GetSCAComputerInfo
Step 6 – Using GetSCADbServerInfo
This CmdLet allows you to gather information about a database server that includes version info., memory usage, connected-users, oracle patch info, etc. It accepts pipeline input, so you can query multiple machines if required. Again it’s best to store the output in a local variable so that you can view properties that are collections, like ConnectedUsers. If you need to only view users, you can use the switch, -OnlyUsers, and that will cause the command to only emit user logged on to the database server.
Step 7 – Get-SCAPerfCounters
Important OS performance counters can be viewed using this CmdLet. It also accepts an optional switch parameter, -GetDetailed, that when specified, get information on expensive queries for MSSQL and Hit Ratios for Oracle.
I hope that these CmdLets will be a useful addition to a 3DAdmins toolkit. Best would to download and play with these, and as always, let me know if they would like me to go in more detail on their usage. In the next series, I’ll go over CmdLet for monitoring 3d Symbols, comparing shares and checking catalog state. Till then, happy scripting!