Skip to content

Commit

Permalink
Update ViOfflineInventory.ps1
Browse files Browse the repository at this point in the history
  • Loading branch information
rschitz committed Oct 4, 2023
1 parent fe027aa commit ad5c106
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion opt/sexigraf/ViOfflineInventory.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

param([Parameter (Mandatory=$true)] [string] $CredStore)

$ScriptVersion = "0.9.81"
$ScriptVersion = "0.9.83"

$ErrorActionPreference = "SilentlyContinue"
$WarningPreference = "SilentlyContinue"
Expand Down Expand Up @@ -361,6 +361,19 @@ if ($ViServersList.count -gt 0) {
}

if ($ViVmsInfos) {

if ($(Get-ChildItem "/mnt/wfs/inventory/ViVmInventory.*.csv")) {
Write-Host "$((Get-Date).ToString("o")) [INFO] Rotating ViVmInventory.*.csv files ..."
$ExtraCsvFiles = Compare-Object $(Get-ChildItem "/mnt/wfs/inventory/ViVmInventory.*.csv") $(Get-ChildItem "/mnt/wfs/inventory/ViVmInventory.*.csv"|Sort-Object LastWriteTime | Select-Object -Last 10) -property Name | ?{$_.SideIndicator -eq "<="}
If ($ExtraCsvFiles) {
try {
Get-ChildItem $ExtraCsvFiles.name | Remove-Item -Force -Confirm:$false
} catch {
AltAndCatchFire "Cannot remove extra csv files"
}
}
}

try {
Write-Host "$((Get-Date).ToString("o")) [INFO] Building Vm Inventory CSV ..."
$ViVmsInfosCsv = $ViVmsInfos|ConvertTo-Csv -NoTypeInformation -ErrorAction Stop
Expand All @@ -385,13 +398,27 @@ if ($ViServersList.count -gt 0) {
# }
Write-Host "$((Get-Date).ToString("o")) [INFO] Writing Vm Inventory file ..."
$ViVmsInfosCsv|Out-File -Path /mnt/wfs/inventory/ViVmInventory.csv -Force -ErrorAction Stop
$ViVmsInfosCsv|Out-File -Path /mnt/wfs/inventory/ViVmInventory.$((Get-Date).ToString("yyyy.MM.dd_hh.mm.ss")).csv -Force -ErrorAction Stop
} catch {
Write-Host "$((Get-Date).ToString("o")) [EROR] VM Inventory issue"
Write-Host "$((Get-Date).ToString("o")) [EROR] $($Error[0])"
}
}

if ($ViEsxsInfos) {

if ($(Get-ChildItem "/mnt/wfs/inventory/ViEsxInventory.*.csv")) {
Write-Host "$((Get-Date).ToString("o")) [INFO] Rotating ViEsxInventory.*.csv files ..."
$ExtraCsvFiles = Compare-Object $(Get-ChildItem "/mnt/wfs/inventory/ViEsxInventory.*.csv") $(Get-ChildItem "/mnt/wfs/inventory/ViEsxInventory.*.csv"|Sort-Object LastWriteTime | Select-Object -Last 10) -property Name | ?{$_.SideIndicator -eq "<="}
If ($ExtraCsvFiles) {
try {
Get-ChildItem $ExtraCsvFiles.name | Remove-Item -Force -Confirm:$false
} catch {
AltAndCatchFire "Cannot remove extra csv files"
}
}
}

try {
Write-Host "$((Get-Date).ToString("o")) [INFO] Building ESX Inventory CSV ..."
$ViEsxsInfosCsv = $ViEsxsInfos|ConvertTo-Csv -NoTypeInformation -ErrorAction Stop
Expand All @@ -416,16 +443,31 @@ if ($ViServersList.count -gt 0) {
# }
Write-Host "$((Get-Date).ToString("o")) [INFO] Writing ESX Inventory file ..."
$ViEsxsInfosCsv|Out-File -Path /mnt/wfs/inventory/ViEsxInventory.csv -Force -ErrorAction Stop
$ViEsxsInfosCsv|Out-File -Path /mnt/wfs/inventory/ViEsxInventory.$((Get-Date).ToString("yyyy.MM.dd_hh.mm.ss")).csv -Force -ErrorAction Stop
} catch {
Write-Host "$((Get-Date).ToString("o")) [EROR] ESX Inventory issue"
Write-Host "$((Get-Date).ToString("o")) [EROR] $($Error[0])"
}
}

if ($ViDatastoresInfos) {

if ($(Get-ChildItem "/mnt/wfs/inventory/ViDsInventory.*.csv")) {
Write-Host "$((Get-Date).ToString("o")) [INFO] Rotating ViDsInventory.*.csv files ..."
$ExtraCsvFiles = Compare-Object $(Get-ChildItem "/mnt/wfs/inventory/ViDsInventory.*.csv") $(Get-ChildItem "/mnt/wfs/inventory/ViDsInventory.*.csv"|Sort-Object LastWriteTime | Select-Object -Last 10) -property Name | ?{$_.SideIndicator -eq "<="}
If ($ExtraCsvFiles) {
try {
Get-ChildItem $ExtraCsvFiles.name | Remove-Item -Force -Confirm:$false
} catch {
AltAndCatchFire "Cannot remove extra csv files"
}
}
}

try {
Write-Host "$((Get-Date).ToString("o")) [INFO] Writing Datastore Inventory files ..."
$ViDatastoresInfos|Export-Csv -NoTypeInformation -Path /mnt/wfs/inventory/ViDsInventory.csv -Force -ErrorAction Stop
$ViDatastoresInfos|Out-File -Path /mnt/wfs/inventory/ViDsInventory.$((Get-Date).ToString("yyyy.MM.dd_hh.mm.ss")).csv -Force -ErrorAction Stop
} catch {
Write-Host "$((Get-Date).ToString("o")) [EROR] Datastore Export-Csv issue"
Write-Host "$((Get-Date).ToString("o")) [EROR] $($Error[0])"
Expand Down

0 comments on commit ad5c106

Please sign in to comment.