Skip to content

Commit f2feb70

Browse files
authored
update stackhci.ps1 (#19948)
1 parent 289ec47 commit f2feb70

File tree

1 file changed

+82
-17
lines changed

1 file changed

+82
-17
lines changed

src/StackHCI/custom/stackhci.ps1

Lines changed: 82 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4887,10 +4887,10 @@ function Install-DeployModule {
48874887
)
48884888

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

48954895
# Download Remote Support Deployment module from storage
48964896
Invoke-DeploymentModuleDownload
@@ -4917,8 +4917,14 @@ function Install-AzStackHCIRemoteSupport{
49174917
[CmdletBinding(SupportsShouldProcess)]
49184918
[OutputType([Boolean])]
49194919
param()
4920-
Install-DeployModule -ModuleName "Microsoft.AzureStack.Deployment.RemoteSupport"
4921-
Microsoft.AzureStack.Deployment.RemoteSupport\Install-RemoteSupport
4920+
4921+
if(Assert-IsObservabilityStackPresent){
4922+
Write-InfoLog("Install-AzStackHCIRemoteSupport is not available.")
4923+
}
4924+
else{
4925+
Install-DeployModule -ModuleName "Microsoft.AzureStack.Deployment.RemoteSupport"
4926+
Microsoft.AzureStack.Deployment.RemoteSupport\Install-RemoteSupport
4927+
}
49224928
}
49234929

49244930
<#
@@ -4937,8 +4943,14 @@ function Remove-AzStackHCIRemoteSupport{
49374943
[CmdletBinding(SupportsShouldProcess)]
49384944
[OutputType([Boolean])]
49394945
param()
4940-
Install-DeployModule -ModuleName "Microsoft.AzureStack.Deployment.RemoteSupport"
4941-
Microsoft.AzureStack.Deployment.RemoteSupport\Remove-RemoteSupport
4946+
4947+
if(Assert-IsObservabilityStackPresent){
4948+
Write-InfoLog("Remove-AzStackHCIRemoteSupport is not available.")
4949+
}
4950+
else{
4951+
Install-DeployModule -ModuleName "Microsoft.AzureStack.Deployment.RemoteSupport"
4952+
Microsoft.AzureStack.Deployment.RemoteSupport\Remove-RemoteSupport
4953+
}
49424954
}
49434955

49444956
<#
@@ -4989,9 +5001,14 @@ function Enable-AzStackHCIRemoteSupport{
49895001
$AgreeToRemoteSupportConsent
49905002
)
49915003

4992-
Install-DeployModule -ModuleName "Microsoft.AzureStack.Deployment.RemoteSupport"
4993-
4994-
Microsoft.AzureStack.Deployment.RemoteSupport\Enable-RemoteSupport -AccessLevel $AccessLevel -ExpireInMinutes $ExpireInMinutes -SasCredential $SasCredential -AgreeToRemoteSupportConsent:$AgreeToRemoteSupportConsent
5004+
if(Assert-IsObservabilityStackPresent){
5005+
Import-Module DiagnosticsInitializer -Verbose -Force
5006+
Enable-RemoteSupport -AccessLevel $AccessLevel -ExpireInMinutes $ExpireInMinutes -SasCredential $SasCredential -AgreeToRemoteSupportConsent:$AgreeToRemoteSupportConsent
5007+
}
5008+
else{
5009+
Install-DeployModule -ModuleName "Microsoft.AzureStack.Deployment.RemoteSupport"
5010+
Microsoft.AzureStack.Deployment.RemoteSupport\Enable-RemoteSupport -AccessLevel $AccessLevel -ExpireInMinutes $ExpireInMinutes -SasCredential $SasCredential -AgreeToRemoteSupportConsent:$AgreeToRemoteSupportConsent
5011+
}
49955012
}
49965013

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

5017-
Microsoft.AzureStack.Deployment.RemoteSupport\Disable-RemoteSupport
5033+
if(Assert-IsObservabilityStackPresent){
5034+
Import-Module DiagnosticsInitializer -Verbose -Force
5035+
Disable-RemoteSupport
5036+
}
5037+
else{
5038+
Install-DeployModule -ModuleName "Microsoft.AzureStack.Deployment.RemoteSupport"
5039+
Microsoft.AzureStack.Deployment.RemoteSupport\Disable-RemoteSupport
5040+
}
50185041
}
50195042

50205043
<#
@@ -5049,9 +5072,47 @@ function Get-AzStackHCIRemoteSupportAccess{
50495072
$IncludeExpired
50505073
)
50515074

5052-
Install-DeployModule -ModuleName "Microsoft.AzureStack.Deployment.RemoteSupport"
5075+
if(Assert-IsObservabilityStackPresent){
5076+
Import-Module DiagnosticsInitializer -Verbose -Force
5077+
Get-RemoteSupportAccess -IncludeExpired:$IncludeExpired
5078+
}
5079+
else{
5080+
Install-DeployModule -ModuleName "Microsoft.AzureStack.Deployment.RemoteSupport"
5081+
Microsoft.AzureStack.Deployment.RemoteSupport\Get-RemoteSupportAccess -Cluster:$Cluster -IncludeExpired:$IncludeExpired
5082+
}
5083+
}
5084+
5085+
<#
5086+
.SYNOPSIS
5087+
Gets if Observability Remote Support Service exists.
5088+
.DESCRIPTION
5089+
Gets if Observability Remote Support Service exists to determine module to import.
5090+
.PARAMETER
5091+
.EXAMPLE
5092+
The example below returns whether environment is HCI or not.
5093+
PS C:\> Assert-IsObservabilityStackPresent
5094+
.NOTES
5095+
#>
5096+
function Assert-IsObservabilityStackPresent{
5097+
[OutputType([Boolean])]
5098+
param()
50535099

5054-
Microsoft.AzureStack.Deployment.RemoteSupport\Get-RemoteSupportAccess -Cluster:$Cluster -IncludeExpired:$IncludeExpired
5100+
try{
5101+
$obsService = Get-Service -Name "*Observability RemoteSupportAgent*" -ErrorAction SilentlyContinue
5102+
$deviceType = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\AzureStack" -ErrorAction SilentlyContinue).DeviceType
5103+
if($obsService -or $deviceType -eq "AzureEdge"){
5104+
Write-InfoLog("AzureStack device type is AzureEdge.")
5105+
return $true
5106+
}
5107+
else{
5108+
Write-InfoLog("AzureStack device type is not AzureEdge.")
5109+
return $false
5110+
}
5111+
}
5112+
catch{
5113+
Write-Error "Failed while getting Observability Remote Support service."
5114+
return $false
5115+
}
50555116
}
50565117

50575118
<#
@@ -5079,7 +5140,6 @@ function Get-AzStackHCIRemoteSupportAccess{
50795140
PS C:\> Get-AzStackHCIRemoteSupportSessionHistory
50805141
50815142
.NOTES
5082-
50835143
#>
50845144
function Get-AzStackHCIRemoteSupportSessionHistory{
50855145
[OutputType([Boolean])]
@@ -5097,9 +5157,14 @@ function Get-AzStackHCIRemoteSupportSessionHistory{
50975157
$FromDate = (Get-Date).AddDays(-7)
50985158
)
50995159

5100-
Install-DeployModule -ModuleName "Microsoft.AzureStack.Deployment.RemoteSupport"
5101-
5102-
Microsoft.AzureStack.Deployment.RemoteSupport\Get-RemoteSupportSessionHistory -SessionId $SessionId -FromDate $FromDate -IncludeSessionTranscript:$IncludeSessionTranscript
5160+
if(Assert-IsObservabilityStackPresent){
5161+
Import-Module DiagnosticsInitializer -Verbose -Force
5162+
Get-RemoteSupportSessionHistory -SessionId $SessionId -FromDate $FromDate -IncludeSessionTranscript:$IncludeSessionTranscript
5163+
}
5164+
else{
5165+
Install-DeployModule -ModuleName "Microsoft.AzureStack.Deployment.RemoteSupport"
5166+
Microsoft.AzureStack.Deployment.RemoteSupport\Get-RemoteSupportSessionHistory -SessionId $SessionId -FromDate $FromDate -IncludeSessionTranscript:$IncludeSessionTranscript
5167+
}
51035168
}
51045169

51055170
# Export-ModuleMember -Function Register-AzStackHCI

0 commit comments

Comments
 (0)