Initial commit
This commit is contained in:
37
functions/public/New-PSIPAMSession.ps1
Normal file
37
functions/public/New-PSIPAMSession.ps1
Normal file
@@ -0,0 +1,37 @@
|
||||
function New-PSIPAMSession {
|
||||
[CmdletBinding()]
|
||||
param (
|
||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]$URL,
|
||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=1)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]$AppID,
|
||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=2)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[pscredential]$Credentials
|
||||
)
|
||||
$_bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Credentials.Password)
|
||||
$_password = [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($_bstr)
|
||||
$_uri = "$URL/api/$AppID/user"
|
||||
$_auth = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("$($Credentials.UserName):$_password"))
|
||||
$_headers = @{
|
||||
"Accept" = "application/json"
|
||||
"Content-Type" = "application/json"
|
||||
"Authorization" = "Basic $_auth"
|
||||
}
|
||||
|
||||
$_response = Invoke-RestMethod -Method Post -Uri $_uri -Headers $_headers -ErrorAction SilentlyContinue
|
||||
|
||||
if ($_response.success -eq $true) {
|
||||
$script:ipamAuth = $true
|
||||
$script:ipamToken = $_response.data.token
|
||||
$script:ipamAppID = $AppID
|
||||
$script:ipamURL = $URL
|
||||
$script:ipamCredentials = $Credentials
|
||||
$script:ipamExpires = Get-Date $_response.data.expires
|
||||
} else {
|
||||
$_response.error
|
||||
}
|
||||
}
|
||||
Export-ModuleMember -Function New-PSIPAMSession
|
||||
Reference in New Issue
Block a user