Update credential parameter in Connect-NetboxAPI

This commit is contained in:
Ben Claussen 2018-05-21 14:50:36 -04:00
parent 4df43e6d6d
commit cf4f2e3a0f

View file

@ -122,7 +122,7 @@ function VerifyAPIConnectivity {
function Connect-NetboxAPI { function Connect-NetboxAPI {
<# <#
.SYNOPSIS .SYNOPSIS
Connects to the Netbox API and ensures credentials work properly Connects to the Netbox API and ensures Credential work properly
.DESCRIPTION .DESCRIPTION
A detailed description of the Connect-NetboxAPI function. A detailed description of the Connect-NetboxAPI function.
@ -130,13 +130,13 @@ function Connect-NetboxAPI {
.PARAMETER Hostname .PARAMETER Hostname
A description of the Hostname parameter. A description of the Hostname parameter.
.PARAMETER Credentials .PARAMETER Credential
A description of the Credentials parameter. A description of the Credential parameter.
.EXAMPLE .EXAMPLE
PS C:\> Connect-NetboxAPI -Hostname "netbox.domain.com" PS C:\> Connect-NetboxAPI -Hostname "netbox.domain.com"
This will prompt for credentials, then proceed to attempt a connection to Netbox This will prompt for Credential, then proceed to attempt a connection to Netbox
.NOTES .NOTES
Additional information about the function. Additional information about the function.
@ -149,22 +149,22 @@ function Connect-NetboxAPI {
[string]$Hostname, [string]$Hostname,
[Parameter(Mandatory = $false)] [Parameter(Mandatory = $false)]
[pscredential]$Credentials [pscredential]$Credential
) )
if (-not $Credentials) { if (-not $Credential) {
try { try {
$Credentials = Get-NetboxCredential -ErrorAction Stop $Credential = Get-NetboxCredential -ErrorAction Stop
} catch { } catch {
# Credentials are not set... Try to obtain from the user # Credentials are not set... Try to obtain from the user
if (-not ($Credentials = Get-Credential -UserName 'username-not-applicable' -Message "Enter token for Netbox")) { if (-not ($Credential = Get-Credential -UserName 'username-not-applicable' -Message "Enter token for Netbox")) {
throw "Token is necessary to connect to a Netbox API." throw "Token is necessary to connect to a Netbox API."
} }
} }
} }
$null = Set-NetboxHostName -Hostname $Hostname $null = Set-NetboxHostName -Hostname $Hostname
$null = Set-NetboxCredential -Credential $Credentials $null = Set-NetboxCredential -Credential $Credential
try { try {
Write-Verbose "Verifying API connectivity..." Write-Verbose "Verifying API connectivity..."