Module/Administration/New-BCSPasswordStateEntry.ps1
<#
.SYNOPSIS Sets up a new Brightcom Tenant .DESCRIPTION .PARAMETER ListID Specifies PasswordState List ID, default 6 .PARAMETER Tenant Specifies Tenant to use in URL .PARAMETER businessCentralserverInstance Specifies Service Instance to use in URL, default BCNUP .PARAMETER Title Specifies Password Entry Title, Mandatory .PARAMETER UserName Specifies Password Entry UserName, default Admin .PARAMETER PasswordStateURL Specifies the URL to PasswordSate .PARAMETER PasswordStateApiKey Secure string containing your Password State Api Key .NOTES Author: Mathias Stjernfelt Website: http://www.brightcom.se .EXAMPLE New-BCSPasswordStateEntry -ListID 1 -CustomerName "Your Customer Name" -PasswordStateURL "https://passwordstate" -PasswordStateApiKey (Get-BCSSecureString "Your Private API Key") #> function New-BCSPasswordStateEntry { [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingUsernameAndPasswordParams', '')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingPlainTextForPassword', '')] Param ( [Parameter(ValueFromPipelineByPropertyName, Mandatory = $false)] [string]$PasswordStateListID = "6", [Parameter(ValueFromPipelineByPropertyName, Mandatory = $true)] [string]$CustomerName, [Parameter(ValueFromPipelineByPropertyName, Mandatory = $false)] [string]$businessCentralserverInstance = "BCNUP", [Parameter(ValueFromPipelineByPropertyName, Mandatory = $false)] [string]$UserName = "admin", [Parameter(ValueFromPipelineByPropertyName, Mandatory = $true)] [string]$PasswordStateURL, [Parameter(ValueFromPipelineByPropertyName, Mandatory = $true)] [securestring]$PasswordStateApiKey ) begin {} process { $tenant = $CustomerName.replace(' ','') $jsonData = ('"PasswordListID":"{0}","Title":"{1}","UserName":"{2}","GeneratePassword": true,"Url": "https://{3}.brightcom.online/{4}"' -f $PasswordStateListID, $CustomerName, $UserName, $tenant.ToLower(), $businessCentralserverInstance) $jsonData = "{" + $jsonData + "}" $PSapiKey = ConvertFrom-SecureString $PasswordStateApiKey -AsPlainText $PasswordstateUrl = "$PasswordStateURL/api/passwords" $result = Invoke-Restmethod -Method Post -Uri $PasswordstateUrl -ContentType "application/json" -Body $jsonData -Header @{ "APIKey" = "$PSapiKey" } Write-Host "PasswordSate Entry for tenant $CustomerName was succesfully created with password $($result.Password)" $result.Password } end { } } Export-ModuleMember -Function New-BCSPasswordStateEntry |