Skip to content

Instantly share code, notes, and snippets.

@DexterPOSH
Created July 10, 2015 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DexterPOSH/ec704f0405df4a1cb78d to your computer and use it in GitHub Desktop.
Save DexterPOSH/ec704f0405df4a1cb78d to your computer and use it in GitHub Desktop.
sample gist to append to the configurecloudservice.ps1 (or you can add a new ps1) to access custom settings defined for the Cloud Service
TRY {
# search for the Dll
Write-Verbose -Message "Creating credential object"
$Splathashtable = @{
'Path' = "$env:windir\Microsoft.NET\assembly\";
'Filter' = 'Microsoft.WindowsAzure.ServiceRuntime.dll';
'Include' = '*.dll'
}
$dllfile = Get-ChildItem @Splathashtable -Recurse | Select-Object -Last 1 # selecting only one object, in case of multiple results
Write-Verbose -Message "ServiceRuntime dll found"
# add the DLL to the current PowerShell session
Add-Type -Path $dllfile.FullName
Write-Verbose -Message "ServiceRuntime dll added to the current runspace"
# Call the Static method on the class to retrieve the setting value
$Setting = [Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment]::GetConfigurationSettingValue('TestKey')
Write-Verbose -Message "Fetched Username TestKey from the Service Configuration"
# Now use the value as you please
Write-Verbose -Message "Value stored in TestKey is $Setting"
}
CATCH {
throw $_.exception
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment