Let's say I have the following function:
function Get-DBStatus
{
<# .. removed help section for brevity .. #>
[CmdletBinding()]
[OutputType([System.Object])]
param
(
[Parameter(Mandatory = $true)]
[String]$ServerName,
[Parameter(Mandatory = $true)]
[String]$ServerUser,
[Parameter(Mandatory = $true)]
[String]$ServerPassword,
[Parameter(Mandatory = $true)]
[String]$DatabaseName,
)
try
{
$params = @{ ... } # <<< It's possible to avoid this duplication ?
$dbStatus = Invoke-SqlConnection @params
}
catch
{
Write-Error -Message ('An error has occured while ...')
}
...
I would like to avoid the need to declare @params once my parameters were already declared and set. It's possible to do it with Powershell ?
$PsBoundParameters.Invoke-SqlConnection @PSBoundParameters