-
Notifications
You must be signed in to change notification settings - Fork 0
/
Export-CredentialToClixml.ps1
31 lines (29 loc) · 1.03 KB
/
Export-CredentialToClixml.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
class GuiCredentialFieldException : Exception {
[string] $additionalData
GuiCredentialFieldException($Message, $additionalData) : base($Message) {
$this.additionalData = $additionalData
}
}
function Do-Main {
Param
(
[Parameter(Mandatory=$true, Position=0)]
[ValidatePattern('^*.xml')]
[string] $path_to_file,
[Parameter(Mandatory=$true, Position=1)]
[string] $prompt_message,
[Parameter(Mandatory=$true, Position=2)]
[AllowEmptyString()]
[string] $user_name,
[Parameter(Mandatory=$false)]
[System.Management.Automation.PSCredential] $Credentials
)
$Credentials = Get-Credential -Message $prompt_message -UserName $user_name
if ($Credentials) {
$Credentials = $Credentials
} else {
# TODO: change second argument of Exception
throw [GuiCredentialFieldException]::new("Gui credentials doesn't entered correctly.", "")
}
Export-Clixml -Path $path_to_file -InputObject $Credentials
}