-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Anthony Watherston <[email protected]>
- Loading branch information
Showing
52 changed files
with
6,046 additions
and
4,434 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
function Convert-HashtableToFlatPsObject { | ||
param ( | ||
[Parameter(Mandatory = $true)] | ||
$Hashtable | ||
) | ||
$newObject = @() | ||
Remove-Variable valueObject -ErrorAction SilentlyContinue | ||
foreach ($hash in $Hashtable) { | ||
$valueObject = New-Object PSObject | ||
foreach ($hKey in $Hash.Keys) { | ||
if (!($Hash.$hKey -is [string] -or $Hash.$hKey -is [int] -or $Hash.$hKey -is [double] -or $Hash.$hKey -is [decimal] -or $Hash.$hKey -is [datetime] -or $Hash.$hKey -is [char] -or $Hash.$hKey -is [bool])) { | ||
if (!($valueObject)) { | ||
$valueObject = New-Object PSObject -Property @{$hkey = $(ConvertTo-Json -InputObject $Hash.$hKey -depth 100 -Compress) } | ||
} | ||
else { | ||
Add-Member -InputObject $valueObject -MemberType NoteProperty -Name $hKey -Value $(ConvertTo-Json -InputObject $Hash.$hKey -depth 100 -Compress) | ||
} | ||
|
||
} | ||
else { | ||
if (!($valueObject)) { | ||
$valueObject = New-Object PSObject -Property @{$hkey = $hash.$hkey } | ||
} | ||
else { | ||
Add-Member -InputObject $valueObject -MemberType NoteProperty -Name $hKey -Value $Hash.$hKey | ||
} | ||
} | ||
$newObject += $valueObject | ||
Remove-Variable hKey -ErrorAction SilentlyContinue | ||
} | ||
Remove-Variable hash -ErrorAction SilentlyContinue | ||
Remove-Variable valueObject -ErrorAction SilentlyContinue | ||
} | ||
return $newObject | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
function Get-HydrationUserObjectId { | ||
[CmdletBinding()] | ||
param ( | ||
[Parameter(Mandatory = $false)] | ||
[string] | ||
$Output = "./Output" | ||
) | ||
# TODO: Logging | ||
$debugLogContents = & { Connect-AzAccount -Force -Debug -TenantId $(Get-AzContext).Tenant.Id -SubscriptionId $(Get-AzContext).Subscription.Id -AccountId $(Get-AzContext).Account.Id -Confirm:$False } *>&1 | ||
$accountId = "" | ||
$jsonObject = "" | ||
foreach ($line in $debugLogContents) { | ||
if ($line -match ".*wam_telemetry.*") { | ||
if ($debug) { | ||
#TODO: Logging which line is being evaluated | ||
} | ||
if ($matches[0] -match "Value: (.*)") { | ||
if ($debug) { | ||
#TODO: Logging which match is being evaluated | ||
} | ||
#TODO: If null then throw/log error | ||
$jsonObject = ($matches[1] | convertfrom-json -depth 100) | ||
#TODO: If null then throw/log error | ||
$accountId = $jsonObject.account_id | ||
#TODO: If null then throw/log error | ||
if ($debug) { | ||
#TODO: Logging compressed json object | ||
} | ||
break | ||
} | ||
} | ||
#TODO: If null then throw/log error | ||
} | ||
if (-not [string]::IsNullOrEmpty($accountId)) { | ||
#TODO: Logging success value | ||
#TODO: Logging success status | ||
return $accountId | ||
} | ||
else { | ||
if ($debug -and (-not [string]::IsNullOrEmpty($jsonObject))) { | ||
#TODO Add error information that json object was empty | ||
} | ||
throw "Failed to retrieve the account id from the Connect-AzAccount debug log.`nConfirm active connection, and if this is confirmed then run with the -debug flag for additional logging information." | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
function New-HydrationAnswerSet { | ||
[CmdletBinding()] | ||
param ( | ||
[Parameter(Mandatory = $true)] | ||
[string] | ||
$LoopId, | ||
[Parameter(Mandatory = $true)] | ||
[string] | ||
$QuestionsFilePath, | ||
[Parameter(Mandatory = $true)] | ||
[string] | ||
$LogFilePath, | ||
[Parameter(Mandatory = $false)] | ||
[array] | ||
$Notes, # This allows dynamic data to be passed for display in the loop to guide the user in their responses. | ||
[Parameter(Mandatory = $false)] | ||
[Int32] | ||
$TerminalWidth = 80, | ||
[Parameter(Mandatory = $false)] | ||
[switch] | ||
$UseUtc | ||
) | ||
if (!(Test-Path $QuestionsFilePath)) { | ||
Write-Error "Questions file not found at $QuestionsFilePath" | ||
return "Failed, Questions file not found at $QuestionsFilePath...." | ||
} | ||
else { | ||
$fullQuestionsList = Get-Content $QuestionsFilePath | ConvertFrom-Json -Depth 10 -AsHashtable | ||
$questionsList = @{} | ||
foreach ($questionKey in $fullQuestionsList.Keys) { | ||
if ($fullQuestionsList.$questionKey.loopId -eq $LoopId) { | ||
$questionsList.Add($questionKey, $fullQuestionsList.$questionKey) | ||
} | ||
} | ||
} | ||
$responseList = [ordered]@{} | ||
foreach ($question1 in $questionsList.Keys) { | ||
$responseList.Add($questionsList.$question1.outputVariableName, "Skipped") | ||
} | ||
$responseIncrement = 1 | ||
$responseMax = $responseList.Keys.Count | ||
foreach ($questionIncrement in $responseIncrement..$responseMax) { | ||
# Outer loop to set order of questions | ||
foreach ($question in $questionsList.Keys) { | ||
# Clear-Host | ||
if ($questionIncrement -eq $questionsList.$question.questionIncrement) { | ||
$questionData = $questionsList.$question | ||
$blockData = @{ | ||
DisplayText = $questionData.displayText | ||
Location = "Middle" | ||
TextRowCharacterColor = "Blue" | ||
RowCharacterColor = "Yellow" | ||
LargeRowCharacter = "-" | ||
SmallRowCharacter = "-" | ||
TerminalWidth = $TerminalWidth | ||
} | ||
# Display the question as a UI | ||
New-HydrationSeparatorBlock @BlockData | ||
Write-Host "$($questionData.bodyHeader)`n" -ForegroundColor Yellow | ||
Write-Host " $($questionData.bodyText)" | ||
if ($Notes) { | ||
Write-Host "Notes:" -ForegroundColor Yellow | ||
foreach ($note in $Notes) { | ||
Write-Host " - $note" -ForegroundColor Yellow | ||
} | ||
} | ||
if ($questionData.links) { | ||
Write-Host "`nLinks:" -ForegroundColor Yellow | ||
foreach ($link in $questionData.links) { | ||
Write-Host " - $link" | ||
} | ||
if (!($questionData.inputType -eq "optionList")) { | ||
# Evens out the presentation formatting for the blank line left in the optionList section due to format of .Net output | ||
Write-Host "`n" | ||
} | ||
} | ||
# Get the response | ||
do { | ||
if ($questionData.inputType -eq "optionList") { | ||
$questionResponse = New-HydrationMenuResponse -OptionHashtable $questionData.menuOptions -DataRequest $questionData.dataRequest | ||
} | ||
else { | ||
$questionResponse = Read-Host $questionData.dataRequest | ||
} | ||
}until(($questionResponse -or $questionData.allowNull) -or $responseIncrement -eq 5) | ||
|
||
if ($questionResponse) { | ||
$responseList.$($questionData.outputVariableName) = $questionResponse | ||
} | ||
elseif ($questionData.allowNull) { | ||
$responseList.$($questionData.outputVariableName) = "" | ||
} | ||
else { | ||
Write-Error "Responses are required for all questions. Exiting script." | ||
return "Failed, please respond to all questions...." | ||
} | ||
$responseIncrement++ | ||
} | ||
} | ||
} | ||
|
||
return $responseList | ||
} | ||
|
||
# $lid = "optionalCreatePrimaryIntermediateRoot" | ||
# $qfp = ".\StarterKit\HydrationKit\questions.jsonc" | ||
# $lfp = ".\Output\Logs\Install-HydrationEpac.log" | ||
# $n = @("Temporary nonsense") | ||
# New-HydrationAnswerSet -LoopId $lid -QuestionsFilePath $qfp -LogFilePath $lfp -Notes $n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
function New-HydrationContinuePrompt { | ||
[CmdletBinding()] | ||
param ( | ||
[Parameter(Mandatory = $false)] | ||
[switch] | ||
$Interactive, | ||
[Parameter(Mandatory = $false)] | ||
[int] | ||
$SleepTime = 10 | ||
) | ||
Write-Host "`n" | ||
if ($Interactive) { | ||
$message = "Press any key to continue..." | ||
Write-Host $message -ForegroundColor Yellow | ||
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | ||
Remove-Variable x | ||
Remove-Variable message | ||
}` | ||
else { | ||
$message = "Continuing in $($Sleeptime.ToString()) seconds..." | ||
Write-Host $message -ForegroundColor Yellow | ||
Start-Sleep -Seconds $SleepTime | ||
} | ||
Write-Host "`n`n" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
function New-HydrationMenuResponse { | ||
[CmdletBinding()] | ||
param ( | ||
[Parameter(Mandatory = $true)] | ||
[System.Management.Automation.OrderedHashtable] | ||
$OptionHashtable, | ||
[Parameter(Mandatory = $false)] | ||
[string] | ||
$DataRequest = "Please select an option from the list below:" | ||
) | ||
|
||
$choices = @() | ||
foreach ($key in $OptionHashtable.Keys) { | ||
$choices += [System.Management.Automation.Host.ChoiceDescription]::new($( -join ("&", $key)), $OptionHashtable.$key) | ||
} | ||
|
||
$caption = "" | ||
$message = "`n$DataRequest" | ||
$result = $host.ui.PromptForChoice($caption, $message, $choices, 0) | ||
return ($choices[$result].Label | Select-String -Pattern "^&(.+)" -AllMatches).Matches[0].Groups[1].Value | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
function New-HydrationMultipleChoicePrompt { | ||
[CmdletBinding()] | ||
param ( | ||
[Parameter()] | ||
[System.Management.Automation.OrderedHashtable] | ||
$List # = [ordered]@{} | ||
) | ||
# TODO: Move to file, test block | ||
# $List = [ordered]@{ | ||
# "Option1" = @{ | ||
# title = "First Title" | ||
# returnData = "returnValue1" | ||
# description = "This is the first option" | ||
# } | ||
# "Option2" = @{ | ||
# title = "Second Title" | ||
# returnData = "returnValue2" | ||
# description = "This is the second option" | ||
# } | ||
# "Option3" = @{ | ||
# title = "Third Title" | ||
# returnData = "returnValue3" | ||
# description = "This is the third option" | ||
# } | ||
# } | ||
$scriptReturn = $null | ||
# Build the question prompt | ||
$choiceList = [ordered]@{} | ||
$keyString = "" | ||
foreach ($item in $List.keys) { | ||
# Write-Host $item | ||
# $List.$item.title | ||
New-Variable -Name $item -Value $(New-Object System.Management.Automation.Host.ChoiceDescription ` | ||
"`&$($List.$item.title)", | ||
"$($List.$item.description)") | ||
$choiceList.add($item, $(Get-Variable $item -ValueOnly)) | ||
if ($keyString -eq "") { | ||
$keyString = "`$$item" | ||
} | ||
else { | ||
$keyString = -join ($keyString, ", `$", $item) | ||
} | ||
Write-Host "TODO: DEBUG:" | ||
# $questionPrompt = $questionPrompt + "`n$($item.Key): $($item.Value.description)" | ||
} | ||
$multipleChoiceOptions = [System.Management.Automation.Host.ChoiceDescription[]]($choiceList.values) | ||
$multipleChoiceMessage = "The current user does not have the necessary rights to create or read Management Groups. This will prevent much of the guidance provided as part of this deployment tool, as well as leave management group creation to manual operations. For these reasons, continuing is not recommended." | ||
$multipleChoiceTitle = "Consider whether or not you wish to proceed (not recommended)..." | ||
|
||
# Ask the question | ||
$scriptResponse = $host.ui.PromptForChoice($multipleChoiceTitle, $multipleChoiceMessage, $multipleChoiceOptions, 0) | ||
|
||
# Dynamically build the switch cases based on the number of items in $List so that we can evaluate the choice made | ||
$index = 0 | ||
$switchCases = $List.GetEnumerator() | ForEach-Object { | ||
"`"$index`" { `$scriptReturn = `"$($_.Value.returnData)`" }" | ||
$index++ | ||
} | ||
# Removing this as it won't be useful anywhwere else, and we don't want anyone to think otherwise. | ||
Remove-Variable index | ||
# Combine the switch cases into a single script block | ||
# $scriptBlock = [scriptblock]::Create("switch -Regex (`"^" + (1..$foo.Count -join "|") + "`$") { $($switchCases -join "`n") default { `$scriptReturn = 'Not found' } }") | ||
# Corrected what appeared to be a typo, if this errors, go ahead and set it back | ||
Write-Host "TODO: Do a log entry." | ||
$scriptBlock = [scriptblock]::Create("switch (`$scriptResponse) { $($switchCases -join "`n") default { `$scriptReturn = 'Error: Not found' } }") | ||
# Execute the script block to evaluate the response | ||
. $scriptBlock | ||
# Return the result | ||
# TODO: Change line below to log entry | ||
Write-Host "$scriptReturn" | ||
return $scriptReturn | ||
} |
Oops, something went wrong.