Merge pull request #517 from bwuch/master
Added a -Credential parameter to the Connect cmdlet.
This commit is contained in:
@@ -22,13 +22,27 @@ Function Connect-SscServer {
|
|||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS C:\> Connect-SscServer -Server 'salt.example.com' -Username 'bwuchner' -Password 'MyPassword1!' -AuthSource 'LAB Directory'
|
PS C:\> Connect-SscServer -Server 'salt.example.com' -Username 'bwuchner' -Password 'MyPassword1!' -AuthSource 'LAB Directory'
|
||||||
This will use the 'Lab Directory' LDAP authentication source.
|
This will use the 'Lab Directory' LDAP authentication source.
|
||||||
|
.EXAMPLE
|
||||||
|
PS C:\> Connect-SscServer -Server 'salt.example.com'
|
||||||
|
This will prompt for credentials
|
||||||
|
.EXAMPLE
|
||||||
|
$creds = Get-Credential
|
||||||
|
PS C:\> Connect-SscServer -Server 'salt.example.com' -Credential $creds -AuthSource 'LAB Directory'
|
||||||
|
This will connect to the 'LAB Directory' LDAP authentication source using a specified credential.
|
||||||
#>
|
#>
|
||||||
param(
|
param(
|
||||||
[Parameter(Mandatory=$true)][string]$server,
|
[Parameter(Mandatory=$true, Position=0)][string]$server,
|
||||||
[Parameter(Mandatory=$true)][string]$username,
|
[Parameter(Mandatory=$true, ParameterSetName='PlainText', Position=1)][string]$username,
|
||||||
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][string]$password,
|
[Parameter(Mandatory=$true, ParameterSetName='PlainText', Position=2)][ValidateNotNullOrEmpty()][string]$password,
|
||||||
[string]$AuthSource='internal'
|
[Parameter(Mandatory=$false, Position=3)][string]$AuthSource='internal',
|
||||||
|
[Parameter(Mandatory=$false, ParameterSetName='Credential')][PSCredential]$Credential
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if ($PSCmdlet.ParameterSetName -eq 'Credential' -AND $Credential -eq $null) { $Credential = Get-Credential}
|
||||||
|
if ($Credential) {
|
||||||
|
$username = $Credential.GetNetworkCredential().username
|
||||||
|
$password = $Credential.GetNetworkCredential().password
|
||||||
|
}
|
||||||
|
|
||||||
$loginBody = @{'username'=$username; 'password'=$password; 'config_name'=$AuthSource}
|
$loginBody = @{'username'=$username; 'password'=$password; 'config_name'=$AuthSource}
|
||||||
try {
|
try {
|
||||||
@@ -37,7 +51,7 @@ Function Connect-SscServer {
|
|||||||
$webRequest = Invoke-WebRequest -Uri "https://$server/account/login" -WebSession $ws -method POST -body (ConvertTo-Json $loginBody)
|
$webRequest = Invoke-WebRequest -Uri "https://$server/account/login" -WebSession $ws -method POST -body (ConvertTo-Json $loginBody)
|
||||||
$webRequestJson = ConvertFrom-JSON $webRequest.Content
|
$webRequestJson = ConvertFrom-JSON $webRequest.Content
|
||||||
$global:DefaultSscConnection = New-Object psobject -property @{ 'SscWebSession'=$ws; 'Name'=$server; 'ConnectionDetail'=$webRequestJson;
|
$global:DefaultSscConnection = New-Object psobject -property @{ 'SscWebSession'=$ws; 'Name'=$server; 'ConnectionDetail'=$webRequestJson;
|
||||||
'User'=$webRequestJson.attributes.config_driver +'\'+ $username; 'Authenticated'=$webRequestJson.authenticated; PSTypeName='SscConnection' }
|
'User'=$webRequestJson.attributes.config_name +'\'+ $username; 'Authenticated'=$webRequestJson.authenticated; PSTypeName='SscConnection' }
|
||||||
|
|
||||||
# Return the connection object
|
# Return the connection object
|
||||||
$global:DefaultSscConnection
|
$global:DefaultSscConnection
|
||||||
|
|||||||
Reference in New Issue
Block a user