Thursday, March 24, 2022

dbatools: Using default credential for certain functions and parameters

<# assign a credential to variable named $sqlCred #> $sqlCred = Get-Credential someUsername

<# use cred $sqlCred by default when calling functions with specific names( *-Dba* ) and three named parameters:
 
    -SqlCredential
    -SourceSqlCredential
    -DestinationSqlCredential

#>
$PSDefaultParameterValues['*-Dba*:SqlCredential'] = $sqlCred
$PSDefaultParameterValues['*-Dba*:SourceSqlCredential'] = $sqlCred
$PSDefaultParameterValues['*-Dba*:DestinationSqlCredential'] = $sqlCred

#Ideas mostly stolen from https://dbatools.io/defaults/