Skip to content

[StackHCI] Check device type for Remote Support cmdlets between HCIv2 and AzureEdge #19948

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 82 additions & 17 deletions src/StackHCI/custom/stackhci.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4887,10 +4887,10 @@ function Install-DeployModule {
)

if(Get-Module | Where-Object { $_.Name -eq $ModuleName }){
Write-Host "$ModuleName is loaded already ..."
Write-InfoLog("$ModuleName is loaded already ...")
}
else{
Write-Host "$ModuleName is not loaded, downloading ..."
Write-InfoLog("$ModuleName is not loaded, downloading ...")

# Download Remote Support Deployment module from storage
Invoke-DeploymentModuleDownload
Expand All @@ -4917,8 +4917,14 @@ function Install-AzStackHCIRemoteSupport{
[CmdletBinding(SupportsShouldProcess)]
[OutputType([Boolean])]
param()
Install-DeployModule -ModuleName "Microsoft.AzureStack.Deployment.RemoteSupport"
Microsoft.AzureStack.Deployment.RemoteSupport\Install-RemoteSupport

if(Assert-IsObservabilityStackPresent){
Write-InfoLog("Install-AzStackHCIRemoteSupport is not available.")
}
else{
Install-DeployModule -ModuleName "Microsoft.AzureStack.Deployment.RemoteSupport"
Microsoft.AzureStack.Deployment.RemoteSupport\Install-RemoteSupport
}
}

<#
Expand All @@ -4937,8 +4943,14 @@ function Remove-AzStackHCIRemoteSupport{
[CmdletBinding(SupportsShouldProcess)]
[OutputType([Boolean])]
param()
Install-DeployModule -ModuleName "Microsoft.AzureStack.Deployment.RemoteSupport"
Microsoft.AzureStack.Deployment.RemoteSupport\Remove-RemoteSupport

if(Assert-IsObservabilityStackPresent){
Write-InfoLog("Remove-AzStackHCIRemoteSupport is not available.")
}
else{
Install-DeployModule -ModuleName "Microsoft.AzureStack.Deployment.RemoteSupport"
Microsoft.AzureStack.Deployment.RemoteSupport\Remove-RemoteSupport
}
}

<#
Expand Down Expand Up @@ -4989,9 +5001,14 @@ function Enable-AzStackHCIRemoteSupport{
$AgreeToRemoteSupportConsent
)

Install-DeployModule -ModuleName "Microsoft.AzureStack.Deployment.RemoteSupport"

Microsoft.AzureStack.Deployment.RemoteSupport\Enable-RemoteSupport -AccessLevel $AccessLevel -ExpireInMinutes $ExpireInMinutes -SasCredential $SasCredential -AgreeToRemoteSupportConsent:$AgreeToRemoteSupportConsent
if(Assert-IsObservabilityStackPresent){
Import-Module DiagnosticsInitializer -Verbose -Force
Enable-RemoteSupport -AccessLevel $AccessLevel -ExpireInMinutes $ExpireInMinutes -SasCredential $SasCredential -AgreeToRemoteSupportConsent:$AgreeToRemoteSupportConsent
}
else{
Install-DeployModule -ModuleName "Microsoft.AzureStack.Deployment.RemoteSupport"
Microsoft.AzureStack.Deployment.RemoteSupport\Enable-RemoteSupport -AccessLevel $AccessLevel -ExpireInMinutes $ExpireInMinutes -SasCredential $SasCredential -AgreeToRemoteSupportConsent:$AgreeToRemoteSupportConsent
}
}

<#
Expand All @@ -5012,9 +5029,15 @@ function Disable-AzStackHCIRemoteSupport{
[CmdletBinding(SupportsShouldProcess)]
[OutputType([Boolean])]
param()
Install-DeployModule -ModuleName "Microsoft.AzureStack.Deployment.RemoteSupport"

Microsoft.AzureStack.Deployment.RemoteSupport\Disable-RemoteSupport
if(Assert-IsObservabilityStackPresent){
Import-Module DiagnosticsInitializer -Verbose -Force
Disable-RemoteSupport
}
else{
Install-DeployModule -ModuleName "Microsoft.AzureStack.Deployment.RemoteSupport"
Microsoft.AzureStack.Deployment.RemoteSupport\Disable-RemoteSupport
}
}

<#
Expand Down Expand Up @@ -5049,9 +5072,47 @@ function Get-AzStackHCIRemoteSupportAccess{
$IncludeExpired
)

Install-DeployModule -ModuleName "Microsoft.AzureStack.Deployment.RemoteSupport"
if(Assert-IsObservabilityStackPresent){
Import-Module DiagnosticsInitializer -Verbose -Force
Get-RemoteSupportAccess -IncludeExpired:$IncludeExpired
}
else{
Install-DeployModule -ModuleName "Microsoft.AzureStack.Deployment.RemoteSupport"
Microsoft.AzureStack.Deployment.RemoteSupport\Get-RemoteSupportAccess -Cluster:$Cluster -IncludeExpired:$IncludeExpired
}
}

<#
.SYNOPSIS
Gets if Observability Remote Support Service exists.
.DESCRIPTION
Gets if Observability Remote Support Service exists to determine module to import.
.PARAMETER
.EXAMPLE
The example below returns whether environment is HCI or not.
PS C:\> Assert-IsObservabilityStackPresent
.NOTES
#>
function Assert-IsObservabilityStackPresent{
[OutputType([Boolean])]
param()

Microsoft.AzureStack.Deployment.RemoteSupport\Get-RemoteSupportAccess -Cluster:$Cluster -IncludeExpired:$IncludeExpired
try{
$obsService = Get-Service -Name "*Observability RemoteSupportAgent*" -ErrorAction SilentlyContinue
$deviceType = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\AzureStack" -ErrorAction SilentlyContinue).DeviceType
if($obsService -or $deviceType -eq "AzureEdge"){
Write-InfoLog("AzureStack device type is AzureEdge.")
return $true
}
else{
Write-InfoLog("AzureStack device type is not AzureEdge.")
return $false
}
}
catch{
Write-Error "Failed while getting Observability Remote Support service."
return $false
}
}

<#
Expand Down Expand Up @@ -5079,7 +5140,6 @@ function Get-AzStackHCIRemoteSupportAccess{
PS C:\> Get-AzStackHCIRemoteSupportSessionHistory

.NOTES

#>
function Get-AzStackHCIRemoteSupportSessionHistory{
[OutputType([Boolean])]
Expand All @@ -5097,9 +5157,14 @@ function Get-AzStackHCIRemoteSupportSessionHistory{
$FromDate = (Get-Date).AddDays(-7)
)

Install-DeployModule -ModuleName "Microsoft.AzureStack.Deployment.RemoteSupport"

Microsoft.AzureStack.Deployment.RemoteSupport\Get-RemoteSupportSessionHistory -SessionId $SessionId -FromDate $FromDate -IncludeSessionTranscript:$IncludeSessionTranscript
if(Assert-IsObservabilityStackPresent){
Import-Module DiagnosticsInitializer -Verbose -Force
Get-RemoteSupportSessionHistory -SessionId $SessionId -FromDate $FromDate -IncludeSessionTranscript:$IncludeSessionTranscript
}
else{
Install-DeployModule -ModuleName "Microsoft.AzureStack.Deployment.RemoteSupport"
Microsoft.AzureStack.Deployment.RemoteSupport\Get-RemoteSupportSessionHistory -SessionId $SessionId -FromDate $FromDate -IncludeSessionTranscript:$IncludeSessionTranscript
}
}

# Export-ModuleMember -Function Register-AzStackHCI
Expand Down