forked from Skatterbrainz/psIntune
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExport-PsIntuneCredential.ps1
36 lines (36 loc) · 1018 Bytes
/
Export-PsIntuneCredential.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<#
.SYNOPSIS
Save PS Credential object to encoded XML file
.DESCRIPTION
Save PS Credential object to encoded XML file
.PARAMETER OutputFile
Path to XML file
.PARAMETER Credential
Optional PS crecential object. If not provided, GUI prompt is provided
.EXAMPLE
Export-PsIntuneCredential -OutputPath ".\cred_contoso_azure.xml"
.EXAMPLE
Export-PsIntuneCredential -OutputPath ".\cred_contoso_azure.xml" -Credential $mycred
.LINK
https://github.com/Skatterbrainz/psintune/blob/master/docs/Export-PsIntuneCredential.md
#>
function Export-PsIntuneCredential {
[CmdletBinding()]
param (
[parameter(Mandatory)][ValidateNotNullOrEmpty()][string] $OutputFile,
[parameter()][pscredential] $Credential
)
try {
if ($null -eq $Credential) {
$Credential = Get-Credential
}
if ($null -ne $Credential) {
Write-Verbose "saving credentials to $OutputFile"
$Credential | Export-Clixml $OutputFile -Force
Write-Host "credentials saved to: $OutputFile"
}
}
catch {
Write-Error $_.Exception.Message
}
}