-
Notifications
You must be signed in to change notification settings - Fork 3
/
PSWinCreds-library.ps1
55 lines (40 loc) · 2.56 KB
/
PSWinCreds-library.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<#
.Synopsis
Manages using saved Windows Credentials in Powershell.
.Description
Displays a visual representation of a calendar. This function supports multiple months
and lets you highlight specific date ranges or days.
.Parameter credName
The name of the file you will be storing (adds .xml extension automatically).
.Example
# Save credentials to a local file.
New-WinCreds -credName "exampleUser"
.Example
# Retrieve credentials to be used.
$creds = Get-WinCreds -credName "exampleUser"
.Version
1.1 - 4/10/14
.Author
Dan Jellesma
#>
Function Get-WinCreds
{
param([string]$credName)
$path = "C:\$credName.xml"
$import = Import-CLixml $path
$Username = $import.Username
$SecurePassword = $import.Password | ConvertTo-SecureString
$Credential = New-Object System.Management.Automation.PSCredential $Username, $SecurePassword
return $Credential
}
Function New-WinCreds
{
param ([string]$credName = "creds")
$Credential = Get-Credential;
$export = "" | Select-Object Username, Password
$export.Username = $Credential.Username
$export.Password = $Credential.Password | ConvertFrom-SecureString
$path = "C:\$credName.xml"
$export | Export-Clixml $path
Write-Host "Credential Save Complete"
}