Skip to content

Commit

Permalink
Support VNext update (#374)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
effingerw authored and knithinc committed Nov 27, 2017
1 parent c46d2e2 commit d4ae15f
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 58 deletions.
64 changes: 47 additions & 17 deletions Support/AzS_PoSh/AzS-PoSh-Environment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand All @@ -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
{
Expand All @@ -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]
{
Expand Down Expand Up @@ -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"
Expand All @@ -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 "
}
104 changes: 65 additions & 39 deletions Support/ERCS_Logs/ERCS_AzureStackLogs.ps1
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -151,7 +151,7 @@ else
# ERCS_AzureStackLogs
#
# VERSION:
# 1.6.0
# 1.6.1
#------------------------------------------------------------------------------

"------------------------------------------------------------------------------ " | Write-Host -ForegroundColor Yellow
Expand All @@ -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
Expand Down Expand Up @@ -268,14 +268,27 @@ 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
$StampTimeZone = $FoundJSONFile.Timezone
$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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1683,4 +1709,4 @@ else
Write-Host "`n Press any key to continue ...`n"
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
exit
}
}
4 changes: 2 additions & 2 deletions Support/ERCS_Logs/ReadMe.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit d4ae15f

Please sign in to comment.