-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGet-PWFromCredFile.ps1
More file actions
57 lines (48 loc) · 2.53 KB
/
Get-PWFromCredFile.ps1
File metadata and controls
57 lines (48 loc) · 2.53 KB
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
<#
========= Get-PWFromCredFile.ps1 =======================================
Name: Get-PWFromCredFile.ps1
Purpose: Open and Read XML file with Secure Password stored.
Converts Text Version of Secure String to Plain Text
# Partner function of Get-PWCreateCredFile.ps1
Author: Dan Stolts - dstoltsµsoft.com - http://ITProGuru.com
Script Home: http://ITProGuru.com/Scripts
Syntax/Execution:
Copy portion of script you want to use and paste into PowerShell (or ISE)
.OR.
$myVar = Get-PWFromCredFile(".\FB_AppSecret.credential")
.OR.
Write-host $(Get-PWFromCredFile ".\FB_AppSecret.credential")
.OR.
# Sample Uses: Read in Cred File to populate app settings array ...
$AppSettings = @{
"FB_AppSecret" = $(Get-PWfromCredFile ".\FB_AppSecret.credential");
"GoogClientSecret" = $(Get-PWfromCredFile ".\GoogClientSecret.credential");
"TwitterSecret" = $(Get-PWfromCredFile ".\TwitterSecret.credential");
}
$AppSettings
# Push settings up to Azure
Set-AzureWebsite -Name $WebSiteName -AppSettings $AppSettings
Disclaimer: Use at your own Risk! See details at http://ITProGuru.com/privacy
Limitations:
* Must Run PowerShell (or ISE)
# Leveraged: https://docs.microsoft.com/en-us/aspnet/identity/overview/features-api/best-practices-for-deploying-passwords-and-other-sensitive-data-to-aspnet-and-azure
================================================================================
#>#
Function Get-PWfromCredFile { Param( [String]$CredFile )
#Debug $CredFile=".\FB_AppSecret.credential"
[xml]$CredFileContent = Get-Content -Path $CredFile
#Username=$CredName captured just to show you how
$CredName = $CredFileContent.Objs.Obj.Props.S.'#text'
$CredPassSecTxt = $CredFileContent.Objs.Obj.Props.SS.'#text'
# $CredPassSecTxt This is the String representation of the Secure Password
# Still need to convert it to SecureString
$SecurePassword = ConvertTo-SecureString $CredPassSecTxt
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecurePassword)
$UnsecurePassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
<# The following is how you could create a credential out of the inforamtion
$UserName="Domain\User"
$Credentials=New-Object System.Management.Automation.PSCredential`
-ArgumentList $CredName, $SecurePassword
#>#Create Credential out of information.
Return $UnsecurePassword
}