cloud/modules/secrets.psm1
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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
<#
.SYNOPSIS OSDCloud Cloud Module for functions.osdcloud.com .DESCRIPTION OSDCloud Cloud Module for functions.osdcloud.com .NOTES This module is designed for OOBE .LINK https://raw.githubusercontent.com/OSDeploy/OSD/master/cloud/modules/secrets.psm1 .EXAMPLE Invoke-Expression (Invoke-RestMethod -Uri 'https://raw.githubusercontent.com/OSDeploy/OSD/master/cloud/modules/secrets.psm1') #> #================================================= #region Functions function osdcloud-GetKeyVaultSecretList { [CmdletBinding()] param ( [Parameter(Mandatory=$true, Position=0)] [System.String] # Specifies the name of the key vault to which the secret belongs. This cmdlet constructs the fully qualified domain name (FQDN) of a key vault based on the name that this parameter specifies and your current environment. $VaultName ) osdcloud-InstallModuleAzAccounts osdcloud-InstallModuleAzKeyVault if (!(Get-AzContext -ErrorAction Ignore)) { Connect-AzAccount -DeviceCode } if (Get-AzContext -ErrorAction Ignore) { Get-AzKeyVaultSecret -VaultName "$VaultName" | Select-Object -ExpandProperty Name } else { Write-Error "Authenticate to Azure using 'Connect-AzAccount -DeviceCode'" } } New-Alias -Name 'ListSecrets' -Value 'osdcloud-GetKeyVaultSecretList' -Description 'OSDCloud' -Force function osdcloud-InvokeKeyVaultSecret { [CmdletBinding()] param ( [Parameter(Mandatory=$true, Position=0)] [System.String] # Specifies the name of the key vault to which the secret belongs. This cmdlet constructs the fully qualified domain name (FQDN) of a key vault based on the name that this parameter specifies and your current environment. $VaultName, [Parameter(Mandatory=$true, Position=1)] [System.String] # Specifies the name of the secret to get the content to use as a PSCloudScript $Name ) osdcloud-InstallModuleAzAccounts osdcloud-InstallModuleAzKeyVault if (!(Get-AzContext -ErrorAction Ignore)) { Connect-AzAccount -DeviceCode } if (Get-AzContext -ErrorAction Ignore) { $Result = Get-AzKeyVaultSecret -VaultName "$VaultName" -Name "$Name" -AsPlainText if ($Result) { Invoke-Expression -Command $Result } } else { Write-Error "Authenticate to Azure using 'Connect-AzAccount -DeviceCode'" } } New-Alias -Name 'InvokeSecret' -Value 'osdcloud-InvokeKeyVaultSecret' -Description 'OSDCloud' -Force #endregion #================================================= |