Standardized parameter names

May 13, 2010 at 8:36 PM

I would like to suggest standardizing the parameter names across the different scripts.  For example, instead of sqlserver, use Server ( or ComputerName depending if you like the MS standard, I prefer Server).  While this would be a huge task, it would make it easier to use the module and easier to incorporate it in an environment.  

It could be made much easier for current users to adopt if aliases for the current parameter names were setup.  

For Example:  If you modified the function Get-SqlServer, the first few lines could look like the following.

function Get-SqlServer
{
    param(
    [Parameter(Position=0, Mandatory=$true)][Alias('sqlserver')][string]$Server,

 

As part of the standardization, I would also suggest using Upper case for the first letter of each word of the parameter name.  I.E. The S in Server or the C and N in ComputerName.  It looks like most of them currently are all lowercase, but a few of them currently have mixed case.

Here are some parameters I've noticed and suggested standardized names.

Proposed: Server or ComputerName ---- Currently Used: sqlserver, jobserver, computername, server, ServerName

Proposed: Database ---- Currently Used: database, databaseName, Databases, dbname

Proposed: Table ---- Currently Used: table, tblname

Proposed: Role ---- Currently Used: role, rolename

Proposed: User ---- Currently Used: user, username

 

Here's a script to get all the parameters and where they are referenced.  Not really a pretty script, but it should get the job done. 

 
$CommandParameters = Get-Module -ListAvailable | ? { $_.path -like '*\SQLPSX\*' } | 
% { $_.ExportedCommands.GetEnumerator() } | 
% { $_.Value } | 
% { $Command = $_.Name; $Mod = $_.Module.Name; $_.Parameters.GetEnumerator() | 
% { $_.Value | Add-Member NoteProperty Module $Mod -PassThru| Add-Member NoteProperty Command $Command -PassThru } } | 
? { 'OutBuffer', 'OutVariable', 'Verbose','Debug', 'ErrorAction', 'ErrorVariable', 'WarningVariable', 'WarningAction', 'WhatIf', 'Confirm', 'Force' -notcontains $_.Name } | 
select @{n='Parameter';e={ $_.Name}}, Module, Command | 
sort Name, Module, Command -Unique | 
Group-Object Parameter | 
select Count, Name, @{n='Commands';e={ $_.Group | % { $_.Module + '\' + $_.Command } | Sort -Unique }} 
$CommandParameters | fl Count, Name, @{l='Commands'; e={ $_.Commands | fl | out-string}}

 

I really like SQLPSX and hope to be able to use it more as it progresses.

Thanks,

Stephen

Coordinator
May 13, 2010 at 9:02 PM

Absolutely -- I'll add param  name standardization as a work item for the next release. Looking at sqlps (Microsoft's SQL Server 2008 host), they use InstanceName and Database name in the invoke-sqlcmd cmdlet. For consistency we may want to adopt the same naming convention.

Thanks for your feedback and let us know if you any other suggestions or would like to contribute as a developer.

Coordinator
May 13, 2010 at 9:03 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.