From d4ae15fe5f365a6cb43cf7db4e8cbeb55bdf83c6 Mon Sep 17 00:00:00 2001 From: William Effinger Date: Mon, 27 Nov 2017 15:10:59 -0800 Subject: [PATCH] Support VNext update (#374) * Delete ERCS_AzureStackLogs.ps1 * enhance error checking * Delete ERCS_AzureStackLogs.ps1 * .Net UI cleanup * Doc Update * Delete ERCS_AzureStackLogs.ps1 * Logic change check for Module * Delete AzS-PoSh-Environment.ps1 * added logic for logon failures * Delete AzS-PoSh-Environment.ps1 * UI update * Delete ERCS_AzureStackLogs.ps1 * Added CloudDeployment JSON check * Delete AzS-PoSh-Environment.ps1 * Added CloudDeployment JSON check * Delete ERCS_AzureStackLogs.ps1 * adding CloudDeploymentLogs * Update to zip exclusions --- Support/AzS_PoSh/AzS-PoSh-Environment.ps1 | 64 +++++++++---- Support/ERCS_Logs/ERCS_AzureStackLogs.ps1 | 104 ++++++++++++++-------- Support/ERCS_Logs/ReadMe.md | 4 +- 3 files changed, 114 insertions(+), 58 deletions(-) diff --git a/Support/AzS_PoSh/AzS-PoSh-Environment.ps1 b/Support/AzS_PoSh/AzS-PoSh-Environment.ps1 index 032e542d..461ba169 100644 --- a/Support/AzS_PoSh/AzS-PoSh-Environment.ps1 +++ b/Support/AzS_PoSh/AzS-PoSh-Environment.ps1 @@ -112,9 +112,17 @@ $global:Toolspath ="C:\AzureStackTools\AzureStack-Tools-master" #Check for the JSON If ((Test-Path -Path "$($Env:ProgramData)\AzureStackStampInformation.json") -eq $true) { - Write-Host "`n[INFO] Load AzureStackStampInformation.json" -ForegroundColor yellow + Write-Host "`n[INFO] Loaded AzureStackStampInformation.json from ProgramData" -ForegroundColor Yellow $FoundJSONFile = Get-Content -Raw -Path "$($Env:ProgramData)\AzureStackStampInformation.json" | ConvertFrom-Json } + If ((Test-Path -Path "$($Env:ProgramData)\AzureStackStampInformation.json") -eq $false) + { + if ((Test-Path -Path "$($env:SystemDrive)\CloudDeployment\Logs\AzureStackStampInformation.json") -eq $true) + { + Write-Host "`n[INFO] Loaded AzureStackStampInformation.json from CloudDeployment" -ForegroundColor Yellow + $FoundJSONFile = Get-Content -Raw -Path "$($env:SystemDrive)\CloudDeployment\Logs\AzureStackStampInformation.json" | ConvertFrom-Json + } + } #Go Get the JSON file if(!($FoundJSONFile)) @@ -238,32 +246,54 @@ If($envInfo) Try { $TenantId = $envInfo.TenantId - Write-Host "`n[INFO] - Login to Azure RM with AzureStack Stamp Service Admin Account" -ForegroundColor Yellow - Login-AzureRmAccount -Environment "AzureStackAdmin" -TenantId $TenantId + Write-Host "`n[INFO] - Login to Azure RM" -ForegroundColor Yellow + + function Read-InputBoxDialog([string]$Message, [string]$WindowTitle, [string]$DefaultText) + { + Add-Type -AssemblyName Microsoft.VisualBasic + return [Microsoft.VisualBasic.Interaction]::InputBox($Message, $WindowTitle, $DefaultText) + } - $location = Get-AzsLocation - $location = $location.Name + Write-Host "`n[Prompt] for AzureStack Administrator name" -ForegroundColor Yellow - Write-Host "`n[INFO] - Obtaining subscriptions" -ForegroundColor Yellow - [array] $AllSubs = get-AzureRmSubscription + [String]$AzSUser = Read-InputBoxDialog -Message "Please enter AzureStack the Admin you use to log into the Administrative portal: `n`n`tUSER@$($envInfo.IdTenantName)" -WindowTitle "Azure Stack Administrative portal user" -DefaultText "​SOMEUSER@$($envInfo.IdTenantName)" + $cred = Get-Credential -UserName $AzSUser -Message "$($AzSUser) Password" + $AzSLogin = Login-AzureRmAccount -Credential $cred -TenantId $TenantId -Environment "AzureStackAdmin" + $azsadmin = $AzSLogin.Context.Account.Id + if($azsadmin) + { + Write-Host "`t$($azsadmin)" + $location = Get-AzsLocation + $location = $location.Name + + Write-Host "`n[INFO] - Obtaining subscriptions" -ForegroundColor Yellow + [array] $AllSubs = get-AzureRmSubscription + } + Else + { + Write-Host "`n`t`t[Error] Did not login $_" -ForegroundColor Red + Write-Host "`n Press any key to continue ...`n" + $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") + exit + } } catch [System.Exception] { - Write-Host "`n`t`t[Error] Wrong Password: $_" -ForegroundColor Red + Write-Host "`n`t`t[Error] Wrong Username or Password: $_" -ForegroundColor Red Write-Host "`n Press any key to continue ...`n" $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") exit } - If ($AllSubs.count -eq 1) + If (($AllSubs.count -eq 1) -and ($azsadmin)) { Select-AzureRmSubscription -Subscriptionid $AllSubs.id | Out-Null - Write-Host "`tSuccess" -ForegroundColor Green + Write-Host "`tSuccess" -ForegroundColor White } Else { - If ($AllSubs) + If (($AllSubs) -and ($azsadmin)) { - Write-Host "`tSuccess" -ForegroundColor Green + Write-Host "`tSuccess" -ForegroundColor White } Else @@ -283,7 +313,7 @@ If($envInfo) $SelSub = $SelSubName.SubscriptionId Select-AzureRmSubscription -Subscriptionid $SelSub | Out-Null - Write-Host "`tSuccess" -ForegroundColor Green + Write-Host "`tSuccess" -ForegroundColor White } Else { @@ -303,7 +333,7 @@ If ((Test-Path -Path "$($AzSToolsPath)\Support\ERCS_Logs\ERCS_AzureStackLogs.ps1 Write-host "`n[INFO] Copying files to $($LocalPath)" -ForegroundColor Yellow New-Item $LocalPath -Type directory -Force | out-null Copy-Item -Path $AzSToolsPath -Destination $LocalPath -Recurse | out-null - Write-Host "`tSuccess" -ForegroundColor Green + Write-Host "`tTools are installed" -ForegroundColor Green } catch [System.Exception] { @@ -475,9 +505,8 @@ If ((Test-Path -Path "$($Toolspath)\Support\ERCS_Logs\ERCS_AzureStackLogs.ps1") return Get-Module } - - - +if($azsadmin) +{ #show Info made from the script Write-host "`n[INFO] `$EnvInfo variable created" -ForegroundColor Yellow Write-host "`tAvailable command: '`$EnvInfo' to view stamp endpoints`n" @@ -488,3 +517,4 @@ Write-host "`n[INFO] AzureStackAdmin AzureRmEnvironment created" -ForegroundColo Write-host "`tRun 'Get-AzureRmEnvironment -Name AzureStackAdmin' to see environment " Write-host "`n[INFO] AzureStackUser AzureRmEnvironment created" -ForegroundColor Yellow Write-host "`tRun 'Get-AzureRmEnvironment -Name AzureStackUser' to see environment " +} diff --git a/Support/ERCS_Logs/ERCS_AzureStackLogs.ps1 b/Support/ERCS_Logs/ERCS_AzureStackLogs.ps1 index f9949b3c..f6c9bcdd 100644 --- a/Support/ERCS_Logs/ERCS_AzureStackLogs.ps1 +++ b/Support/ERCS_Logs/ERCS_AzureStackLogs.ps1 @@ -1,6 +1,6 @@ <# .SYNOPSIS - Built to be run on the HLH or DVM from an administrative powershell session the script uses seven methods to find the privileged endpoint virtual machines. The script connects to selected privileged endpoint and runs Get-AzureStackLog with supplied parameters. If no parameters are supplied the script will default to prompting user via GUI for needed parameters. + Built to be run on the HLH, DVM, or Jumpbox from an administrative powershell session the script uses seven methods to find the privileged endpoint virtual machines. The script connects to selected privileged endpoint and runs Get-AzureStackLog with supplied parameters. If no parameters are supplied the script will default to prompting user via GUI for needed parameters. .DESCRIPTION The script will use one of the below seven methods; Gather requested logs, Transcript, and AzureStackStampInformation.json. The script will also save AzureStackStampInformation.json in %ProgramData% and in created log folder. AzureStackStampInformation.json in %ProgramData% allows future runs to have ERCS IP information populated at beginning of script. @@ -45,7 +45,7 @@ (Get-TimeZone -Name "US Eastern*").id "Pacific Standard Time" .PARAMETER IncompleteDeployment - Specifies if Azure Stack Deployment is incomplete (Only for use in ASDK or DVM) + Specifies if Azure Stack Deployment is incomplete. Only for use in Azure Stack Development Kit deployment or DVM Yes No .EXAMPLE @@ -151,7 +151,7 @@ else # ERCS_AzureStackLogs # # VERSION: -# 1.6.0 +# 1.6.1 #------------------------------------------------------------------------------ "------------------------------------------------------------------------------ " | Write-Host -ForegroundColor Yellow @@ -171,7 +171,7 @@ else " ERCS_AzureStackLogs.ps1 " | Write-Host -ForegroundColor Yellow "" | Write-Host -ForegroundColor Yellow " VERSION: " | Write-Host -ForegroundColor Yellow -" 1.6.0" | Write-Host -ForegroundColor Yellow +" 1.6.1" | Write-Host -ForegroundColor Yellow "" | Write-Host -ForegroundColor Yellow "------------------------------------------------------------------------------ " | Write-Host -ForegroundColor Yellow "" | Write-Host -ForegroundColor Yellow @@ -268,7 +268,7 @@ If(!($IP)) { If ((Test-Path -Path "$($Env:ProgramData)\AzureStackStampInformation.json") -eq $true) { - Write-Host "`n `t[INFO] Load AzureStackStampInformation.json" -ForegroundColor Green + Write-Host "`n `t[INFO] Loaded AzureStackStampInformation.json from ProgramData" -ForegroundColor Green $FoundJSONFile = Get-Content -Raw -Path "$($Env:ProgramData)\AzureStackStampInformation.json" | ConvertFrom-Json [string]$FoundDomainFQDN = $FoundJSONFile.DomainFQDN [array]$ERCSIPS = $FoundJSONFile.EmergencyConsoleIPAddresses @@ -276,6 +276,19 @@ If(!($IP)) $FoundSelERCSIP = $FoundJSONFile.EmergencyConsoleIPAddresses | Out-GridView -Title "Please Select Emergency Console IP Address" -PassThru $IP = $FoundSelERCSIP } + If ((Test-Path -Path "$($Env:ProgramData)\AzureStackStampInformation.json") -eq $false) + { + if ((Test-Path -Path "$($env:SystemDrive)\CloudDeployment\Logs\AzureStackStampInformation.json") -eq $true) + { + Write-Host "`n `t[INFO] Loaded AzureStackStampInformation.json from CloudDeployment" -ForegroundColor Green + $FoundJSONFile = Get-Content -Raw -Path "$($env:SystemDrive)\CloudDeployment\Logs\AzureStackStampInformation.json" | ConvertFrom-Json + [string]$FoundDomainFQDN = $FoundJSONFile.DomainFQDN + [array]$ERCSIPS = $FoundJSONFile.EmergencyConsoleIPAddresses + $StampTimeZone = $FoundJSONFile.Timezone + $FoundSelERCSIP = $FoundJSONFile.EmergencyConsoleIPAddresses | Out-GridView -Title "Please Select Emergency Console IP Address" -PassThru + $IP = $FoundSelERCSIP + } + } } #Sel AzureStackStampInformation @@ -1324,7 +1337,7 @@ if($IP) # #buttonselect # - $buttonselect.Location = New-Object -TypeName System.Drawing.Point -ArgumentList @(12,258) + $buttonselect.Location = New-Object -TypeName System.Drawing.Point -ArgumentList @(12,262) $buttonselect.Name = 'buttonselect' $buttonselect.Size = New-Object -TypeName System.Drawing.Size -ArgumentList @(121,23) $buttonselect.TabIndex = 1 @@ -1334,7 +1347,7 @@ if($IP) # #buttondefault # - $buttondefault.Location = New-Object -TypeName System.Drawing.Point -ArgumentList @(139,258) + $buttondefault.Location = New-Object -TypeName System.Drawing.Point -ArgumentList @(139,262) $buttondefault.Name = 'buttondefault' $buttondefault.Size = New-Object -TypeName System.Drawing.Size -ArgumentList @(133,23) $buttondefault.TabIndex = 2 @@ -1407,26 +1420,30 @@ if($IP) } If($IncompleteDeployment -eq "Yes") { - cd "$($env:SystemDrive)\CloudDeployment\AzureStackDiagnostics" - - $Folders=@() - $Folders += Get-ChildItem | Where {$_.attributes -eq 'directory'} - - foreach ($Folder in $Folders) + $checkdiag = test-path -Path "$($env:SystemDrive)\CloudDeployment\AzureStackDiagnostics\Microsoft.AzureStack.Diagnostics.DataCollection\Microsoft.AzureStack.Diagnostics.DataCollection.psm1" + if($checkdiag -eq $true) + { + Import-Module "$($env:SystemDrive)\CloudDeployment\AzureStackDiagnostics\Microsoft.AzureStack.Diagnostics.DataCollection\Microsoft.AzureStack.Diagnostics.DataCollection.psm1" -WarningAction SilentlyContinue -ErrorAction SilentlyContinue + $AzSDig = Get-Module -Name Microsoft.AzureStack.Diagnostics.DataCollection + } + if ($AzSDig.Name -eq "Microsoft.AzureStack.Diagnostics.DataCollection") { - if (Get-ChildItem -Name $Folder -include *.psm1) - { - Import-Module $Folder\$(Get-ChildItem -Name $Folder -include *.psm1) -WarningAction SilentlyContinue -ErrorAction SilentlyContinue - } + $incompletedeploymentdate = Get-Date -format MM-dd-hhmm + $incompletedeploymentfoldername = "-IncompleteDeployment_AzureStackLogs" + $incompletedeploymentsharename = $incompletedeploymentdate + $incompletedeploymentfoldername + If (!(Test-Path "$($Env:SystemDrive)\$($incompletedeploymentsharename)")) {$incompletedeploymentfolder = New-Item -Path "$($Env:SystemDrive)\$($incompletedeploymentsharename)" -ItemType directory} + Get-AzureStackLogs -OutputPath $incompletedeploymentfolder.FullName -FilterByRole $FilterByRole -FromDate $FromDate -ToDate $ToDate + } + Else + { + Write-Host "`n[Error] unable to load Microsoft.AzureStack.Diagnostics.DataCollection: $_" -ForegroundColor Red + $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") + exit } - $incompletedeploymentdate = Get-Date -format MM-dd-hhmm - $incompletedeploymentfoldername = "-IncompleteDeployment_AzureStackLogs" - $incompletedeploymentsharename = $incompletedeploymentdate + $incompletedeploymentfoldername - If (!(Test-Path "$($Env:SystemDrive)\$($incompletedeploymentsharename)")) {$incompletedeploymentfolder = New-Item -Path "$($Env:SystemDrive)\$($incompletedeploymentsharename)" -ItemType directory} - Get-AzureStackLogs -OutputPath $incompletedeploymentfolder.FullName -FilterByRole $FilterByRole -FromDate $FromDate -ToDate $ToDate #remotepowershell - Clear-Host $s = New-PSSession -ComputerName $IP -ConfigurationName PrivilegedEndpoint -Credential $mySecureCredentials + Try + { Write-Host "`n `t[INFO] Getting Azure Stack stamp information" -ForegroundColor Green Invoke-Command -Session $s -ScriptBlock {Get-AzureStackStampInformation -WarningAction SilentlyContinue} -OutVariable StampInformation -WarningAction SilentlyContinue | Out-Null Invoke-Command -Session $s -ScriptBlock {Get-VirtualDisk -CimSession S-Cluster} -OutVariable ClusterDiskInformation -WarningAction SilentlyContinue | Out-Null @@ -1437,21 +1454,30 @@ if($IP) Write-Host "`n `t[INFO] Saving AzureStackStampInformation to $($Env:SystemDrive)\$($incompletedeploymentsharename)" -ForegroundColor Green $StampInformation | ConvertTo-Json | Out-File -FilePath "$($Env:SystemDrive)\$($incompletedeploymentsharename)\AzureStackStampInformation.json" -Force $ClusterDiskInformation | Out-File -FilePath "$($Env:SystemDrive)\$($incompletedeploymentsharename)\ClusterVirtualDiskInfo.txt" -Force + } + catch + { + Write-Host "`n[Error] unable to connect to PEP: $_" -ForegroundColor Red + } + #zip files try - { - Write-Host "`n`t[INFO] Compressing gathered files" -ForegroundColor Green - $zipdate = $incompletedeploymentdate - Compress-Archive -Path (Get-ChildItem -Path $Env:SystemDrive\$incompletedeploymentsharename).FullName -CompressionLevel Optimal -DestinationPath "$Env:SystemDrive\$incompletedeploymentsharename\$($zipdate)_AzureStackLogs_archive.zip" -Force - Write-Host "`tFile created: $Env:SystemDrive\$incompletedeploymentsharename\$($zipdate)_AzureStackLogs_archive.zip" -ForegroundColor White - Invoke-Item $incompletedeploymentfolder.FullName - Write-Host "`n `t[INFO] Opening $($incompletedeploymentfolder.FullName)" -ForegroundColor Green - } - catch - { - Write-Host "`n`t`t[WARN] Did not create a archive" -ForegroundColor Yellow - } - Write-Host "`n `tPress any key to continue ...`n" - $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") + { + Write-Host "`n`t[INFO] Compressing gathered files" -ForegroundColor Green + $zipdate = $incompletedeploymentdate + if((Test-Path -Path $Env:SystemDrive\CloudDeployment\Logs) -eq $true) + {Compress-Archive -Path (Get-ChildItem -Path $Env:SystemDrive\CloudDeployment\Logs).FullName -CompressionLevel Optimal -DestinationPath "$Env:SystemDrive\$incompletedeploymentsharename\$($zipdate)_CloudDeploymentLogs_archive.zip" -Force} + if((Test-Path -Path $Env:SystemDrive\MASLogs) -eq $true) + {Compress-Archive -Path (Get-ChildItem -Path $Env:SystemDrive\MASLogs).FullName -CompressionLevel Optimal -DestinationPath "$Env:SystemDrive\$incompletedeploymentsharename\$($zipdate)_MASLogs_archive.zip" -Force} + Compress-Archive -Path (Get-ChildItem -Path $Env:SystemDrive\$incompletedeploymentsharename).FullName -CompressionLevel Optimal -DestinationPath "$Env:SystemDrive\$incompletedeploymentsharename\$($zipdate)_AzureStackLogs_archive.zip" -Force + Write-Host "`tFile created: $Env:SystemDrive\$incompletedeploymentsharename\$($zipdate)_AzureStackLogs_archive.zip" -ForegroundColor White + Invoke-Item $incompletedeploymentfolder.FullName + Write-Host "`n `t[INFO] Opening $($incompletedeploymentfolder.FullName)" -ForegroundColor Green + } + catch + { + Write-Host "`n`t`t[WARN] Did not create a archive" -ForegroundColor Yellow + } + #cleanup exit } #setting remotepowershell options @@ -1642,7 +1668,7 @@ if($IP) { Write-Host "`n`t[INFO] Compressing gathered files" -ForegroundColor Green $zipdate = $date - Compress-Archive -Path (Get-ChildItem -Path $Env:SystemDrive\$sharename).FullName -CompressionLevel Optimal -DestinationPath "$Env:SystemDrive\$sharename\$($zipdate)_AzureStackLogs_archive.zip" -Force + Compress-Archive -Path (Get-ChildItem -Exclude Transcripts_* -Path $Env:SystemDrive\$sharename).FullName -CompressionLevel Optimal -DestinationPath "$Env:SystemDrive\$sharename\$($zipdate)_AzureStackLogs_archive.zip" -Force Write-Host "`tFile created: $Env:SystemDrive\$sharename\$($zipdate)_AzureStackLogs_archive.zip" -ForegroundColor White Invoke-Item $Files.Parent.FullName Write-Host "`n `t[INFO] Opening $($Files.Parent.FullName)" -ForegroundColor Green @@ -1683,4 +1709,4 @@ else Write-Host "`n Press any key to continue ...`n" $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") exit -} \ No newline at end of file +} diff --git a/Support/ERCS_Logs/ReadMe.md b/Support/ERCS_Logs/ReadMe.md index 6bfa4835..e72aeca3 100644 --- a/Support/ERCS_Logs/ReadMe.md +++ b/Support/ERCS_Logs/ReadMe.md @@ -1,8 +1,8 @@ # ​ERCS_AzureStackLogs​.ps1 # -![](https://github.com/effingerw/AzureStack-Tools/blob/vnext/Support/ERCS_Logs/Media/ERCS.gif?raw=true) +![](https://github.com/Azure/AzureStack-Tools/blob/vnext/Support/ERCS_Logs/Media/ERCS.gif?raw=true) - Built to be run on the HLH or DVM from an administrative powershell session the script uses seven methods to find the privileged endpoint virtual machines. The script connects to selected privileged endpoint and runs Get-AzureStackLog with supplied parameters. If no parameters are supplied the script will default to prompting user via GUI for needed parameters. + Built to be run on the HLH, DVM, or Jumpbox from an administrative powershell session the script uses seven methods to find the privileged endpoint virtual machines. The script connects to selected privileged endpoint and runs Get-AzureStackLog with supplied parameters. If no parameters are supplied the script will default to prompting user via GUI for needed parameters. The script will use one of the below seven methods; Gather requested logs, Transcript, and AzureStackStampInformation.json. The script will also save AzureStackStampInformation.json in %ProgramData% and in created log folder. AzureStackStampInformation.json in %ProgramData% allows future runs to have ERCS IP information populated at beginning of script.