Skip to content

Commit

Permalink
Improve connection validation throuth WinRM
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelinux committed Oct 20, 2024
1 parent 6f88614 commit 2f072c1
Show file tree
Hide file tree
Showing 6 changed files with 320 additions and 282 deletions.
6 changes: 3 additions & 3 deletions AsBuiltReport.Veeam.VBR.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'AsBuiltReport.Veeam.VBR.psm1'

# Version number of this module.
ModuleVersion = '0.8.10'
ModuleVersion = '0.8.11'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down Expand Up @@ -63,11 +63,11 @@
}
@{
ModuleName = 'Diagrammer.Core';
ModuleVersion = '0.2.8'
ModuleVersion = '0.2.11'
}
@{
ModuleName = 'Veeam.Diagrammer';
ModuleVersion = '0.6.8'
ModuleVersion = '0.6.11'
}
)

Expand Down
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Increase Diagrammer.Core minimum requirement to v0.2.8
- Increase Veeam.Diagrammer minimum requirement to v0.6.8
- Increase Diagrammer.Core minimum requirement to v0.2.11
- Increase Veeam.Diagrammer minimum requirement to v0.6.11
- Improve connection validation throuth WinRM

### Fixed

- Fix SOBR capacity extent members table
- Fix Unstructured Data section displaying section when no data is available

## [0.8.10] - 2024-09-12

Expand Down
45 changes: 30 additions & 15 deletions Src/Private/Get-AbrVbrBackupProxy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,9 @@ function Get-AbrVbrBackupProxy {
Write-PScriboMessage "Collecting Hardware/Software Inventory Summary."
if ($BackupProxies = Get-VBRViProxy | Where-Object { $_.Host.Type -eq "Windows" } | Sort-Object -Property Name) {
$vSphereVBProxyObj = foreach ($BackupProxy in $BackupProxies) {
if (Test-Connection -ComputerName $BackupProxy.Host.Name -Quiet -Count 2) {
if (Test-WSMan -Credential $Credential -Authentication $Options.PSDefaultAuthentication -ComputerName $BackupProxy.Host.Name -ErrorAction SilentlyContinue) {
try {
Write-PScriboMessage "Collecting Backup Proxy Inventory Summary from $($BackupProxy.Host.Name)."
# $CimSession = New-CimSession $BackupProxy.Host.Name -Credential $Credential -Authentication $Options.PSDefaultAuthentication
$CimSession = try { New-CimSession $BackupProxy.Host.Name -Credential $Credential -Authentication $Options.PSDefaultAuthentication -Name 'HardwareInventory' -ErrorAction Stop } catch { Write-PScriboMessage -IsWarning "VMware Backup Proxies Hardware/Software Section: New-CimSession: Unable to connect to $($BackupProxy.Host.Name): $($_.Exception.MessageId)" }

$PssSession = try { New-PSSession $BackupProxy.Host.Name -Credential $Credential -Authentication $Options.PSDefaultAuthentication -ErrorAction Stop -Name 'VMwareHardwareInventory' } catch {
Expand All @@ -131,7 +130,6 @@ function Get-AbrVbrBackupProxy {
} else { $ErrorMessage = $_.Exception.MessageId }
Write-PScriboMessage -IsWarning "VMware Backup Proxies Hardware/Software Section: New-PSSession: Unable to connect to $($BackupProxy.Host.Name): $ErrorMessage"
}
# $PssSession = New-PSSession $BackupProxy.Host.Name -Credential $Credential -Authentication $Options.PSDefaultAuthentication -ErrorAction SilentlyContinue
if ($PssSession) {
$HW = Invoke-Command -Session $PssSession -ScriptBlock { Get-ComputerInfo }
} else { Write-PScriboMessage -IsWarning "VMware Backup Proxies Hardware/Software Inventory: Unable to connect to $($BackupProxy.Host.Name)" }
Expand Down Expand Up @@ -358,14 +356,23 @@ function Get-AbrVbrBackupProxy {
}
}
}
Remove-PSSession -Session $PssSession
Remove-CimSession $CimSession
if ($PssSession) {
# Remove used PSSession
Write-PScriboMessage "Clearing PowerShell Session $($PssSession.Id)"
Remove-PSSession -Session $PssSession
}

if ($CimSession) {
# Remove used CIMSession
Write-PScriboMessage "Clearing CIM Session $($CimSession.Id)"
Remove-CimSession -CimSession $CimSession
}
}
} catch {
Write-PScriboMessage -IsWarning "VMware Backup Proxies Section: $($_.Exception.Message)"
}
} else {
Write-PScriboMessage -IsWarning "VMware Backup Proxies Section: Failed to Test-Connection on $($BackupProxies.Host.Name), disabling section"
Write-PScriboMessage -IsWarning "VMware Backup Proxies Section: Unable to connect to $($BackupProxies.Host.Name) throuth WinRM, disabling section"
}
}
if ($vSphereVBProxyObj) {
Expand All @@ -388,7 +395,7 @@ function Get-AbrVbrBackupProxy {
Write-PScriboMessage "Collecting Veeam Services Information."
$BackupProxies = Get-VBRViProxy | Where-Object { $_.Host.Type -eq "Windows" } | Sort-Object -Property Name
foreach ($BackupProxy in $BackupProxies) {
if (Test-Connection -ComputerName $BackupProxy.Host.Name -Quiet -Count 2) {
if (Test-WSMan -Credential $Credential -Authentication $Options.PSDefaultAuthentication -ComputerName $BackupProxy.Host.Name -ErrorAction SilentlyContinue) {
try {
# $PssSession = New-PSSession $BackupProxy.Host.Name -Credential $Credential -Authentication $Options.PSDefaultAuthentication -ErrorAction SilentlyContinue
$PssSession = try { New-PSSession $BackupProxy.Host.Name -Credential $Credential -Authentication $Options.PSDefaultAuthentication -ErrorAction Stop -Name 'VMwareBackupProxyService' } catch {
Expand Down Expand Up @@ -437,7 +444,7 @@ function Get-AbrVbrBackupProxy {
Write-PScriboMessage -IsWarning "VMware Backup Proxies $($BackupProxy.Host.Name) Services Status Section: $($_.Exception.Message)"
}
} else {
Write-PScriboMessage -IsWarning "VMware Backup Proxy Service Section: Failed to Test-Connection on $($BackupProxy.Host.Name), disabling section"
Write-PScriboMessage -IsWarning "VMware Backup Proxies Section: Unable to connect to $($BackupProxies.Host.Name) throuth WinRM, disabling section"
}
}
}
Expand Down Expand Up @@ -562,7 +569,7 @@ function Get-AbrVbrBackupProxy {
Write-PScriboMessage "Collecting Hardware/Software Inventory Summary."
if ($BackupProxies = Get-VBRHvProxy | Sort-Object -Property Name) {
$HyperVBProxyObj = foreach ($BackupProxy in $BackupProxies) {
if (Test-Connection -ComputerName $BackupProxy.Host.Name -Quiet -Count 2) {
if (Test-WSMan -Credential $Credential -Authentication $Options.PSDefaultAuthentication -ComputerName $BackupProxy.Host.Name -ErrorAction SilentlyContinue) {
try {
Write-PScriboMessage "Collecting Backup Proxy Inventory Summary from $($BackupProxy.Host.Name)."
# $CimSession = New-CimSession $BackupProxy.Host.Name -Credential $Credential -Authentication $Options.PSDefaultAuthentication
Expand Down Expand Up @@ -804,14 +811,23 @@ function Get-AbrVbrBackupProxy {
}
}
}
Remove-PSSession -Session $PssSession
Remove-CimSession $CimSession
if ($PssSession) {
# Remove used PSSession
Write-PScriboMessage "Clearing PowerShell Session $($PssSession.Id)"
Remove-PSSession -Session $PssSession
}

if ($CimSession) {
# Remove used CIMSession
Write-PScriboMessage "Clearing CIM Session $($CimSession.Id)"
Remove-CimSession -CimSession $CimSession
}
}
} catch {
Write-PScriboMessage -IsWarning "Hyper-V Backup Proxies Hardware & Software Inventory Section: $($_.Exception.Message)"
}
} else {
Write-PScriboMessage -IsWarning "Hyper-V Backup Proxies Section: Failed to Test-Connection on $($BackupProxies.Host.Name), disabling section"
Write-PScriboMessage -IsWarning "Hyper-V Backup Proxies Section: Unable to connect to $($BackupProxies.Host.Name) throuth WinRM, disabling section"
}
}
if ($HyperVBProxyObj) {
Expand All @@ -834,9 +850,8 @@ function Get-AbrVbrBackupProxy {
Write-PScriboMessage "Collecting Veeam Service Information."
$BackupProxies = Get-VBRHvProxy | Sort-Object -Property Name
foreach ($BackupProxy in $BackupProxies) {
if (Test-Connection -ComputerName $BackupProxy.Host.Name -Quiet -Count 2) {
if (Test-WSMan -Credential $Credential -Authentication $Options.PSDefaultAuthentication -ComputerName $BackupProxy.Host.Name -ErrorAction SilentlyContinue) {
try {
# $PssSession = New-PSSession $BackupProxy.Host.Name -Credential $Credential -Authentication $Options.PSDefaultAuthentication -ErrorAction SilentlyContinue
$PssSession = try { New-PSSession $BackupProxy.Host.Name -Credential $Credential -Authentication $Options.PSDefaultAuthentication -ErrorAction Stop -Name 'HyperVBackupProxyService' } catch {
if (-Not $_.Exception.MessageId) {
$ErrorMessage = $_.FullyQualifiedErrorId
Expand Down Expand Up @@ -883,7 +898,7 @@ function Get-AbrVbrBackupProxy {
Write-PScriboMessage -IsWarning "Hyper-V Backup Proxies Services Status - $($BackupProxy.Host.Name.Split(".")[0]) Section: $($_.Exception.Message)"
}
} else {
Write-PScriboMessage -IsWarning "Hyper-V Backup Proxies Services Section: Failed to Test-Connection on $($BackupProxy.Host.Name), disabling section"
Write-PScriboMessage -IsWarning "Hyper-V Backup Proxies Section: Unable to connect to $($BackupProxies.Host.Name) throuth WinRM, disabling section"
}
}
}
Expand Down
Loading

0 comments on commit 2f072c1

Please sign in to comment.