Public/New-NetBoxCredential.ps1
function New-NetBoxCredential { [CmdletBinding()] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'version of [void]')] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Justification = 'Not an issue.')] param ( ) $ServerInput = $host.ui.Prompt('Initial Input', 'Please provide the NetBox server hostname', 'Hostname') $APITokenInput = Get-Credential -UserName 'NetBox API Token' -Message "Username field isn't required." $Credential = New-Object System.Management.Automation.PSCredential ("$($ServerInput.Hostname)", $APITokenInput.Password) if (!(Test-Path $env:APPDATA\PSNetBox)) { $Blackhole = New-Item -Path $env:APPDATA -Name 'PSNetBox' -ItemType Directory } $Credential | Export-Clixml -Path $env:APPDATA\PSNetBox\Server.xml } |