-
-
Save evilensky/73d8775f40b195267b6543afda014f79 to your computer and use it in GitHub Desktop.
Reports StoreOnce Catalyst Stores via RESTapi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Workaround for SelfSigned Cert | |
add-type @" | |
using System.Net; | |
using System.Security.Cryptography.X509Certificates; | |
public class TrustAllCertsPolicy : ICertificatePolicy { | |
public bool CheckValidationResult( | |
ServicePoint srvPoint, X509Certificate certificate, | |
WebRequest request, int certificateProblem) { | |
return true; | |
} | |
} | |
"@ | |
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy | |
# Global definitions | |
$User = "Reporting" | |
$Password = "Passw0rd!" | |
$D2DIPs = @("192.168.1.1","192.168.10.1") | |
# Data Collection | |
$Stores = New-Object System.Collections.ArrayList | |
Write-Output "`n $($D2DIPs.Count) D2D Arrays to Report" | |
foreach ($D2DIP in $D2DIPs) { | |
Write-Output "`n$(Get-Date -Format T) - Starting SID enumaration on Device: $D2DIP..." | |
Write-Output " Calling: https://$D2DIP/storeonceservices/cluster/servicesets/" | |
$SIDs = @{uri = "https://$D2DIP/storeonceservices/cluster/servicesets/"; | |
Method = 'GET'; #(or POST, or whatever) | |
Headers = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($User):$($Password)")); | |
Accept = 'text/xml' | |
} | |
} | |
Write-Output "$(Get-Date -Format T) - Starting Request..." | |
$SIDsResponse = Invoke-RestMethod @SIDs | |
Write-Output "$(Get-Date -Format T) - Finished Request." | |
Write-Output "$(Get-Date -Format T) - Starting Output handling..." | |
$SIDCount = ($SIDsResponse.document.servicesets.serviceset).count | |
if ($SIDCount -eq $null) {$SIDCount = 1} | |
Write-Output "$(Get-Date -Format T) - Finished Output handling." | |
Write-Output "$(Get-Date -Format T) - Finished SID enumaration." | |
Write-Output "`n $SIDCount SIDs found on Device: $D2DIP" | |
for ($x = 1; $x -le $SIDCount; $x++ ){ | |
Write-Output "`n$(Get-Date -Format T) - Starting Store enumaration on SID: $x..." | |
Write-Output " Calling: https://$D2DIP/storeonceservices/cluster/servicesets/$x/services/cat/stores/" | |
$StoreInf = @{uri = "https://$D2DIP/storeonceservices/cluster/servicesets/$x/services/cat/stores/"; | |
Method = 'GET'; #(or POST, or whatever) | |
Headers = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($User):$($Password)")); | |
Accept = 'text/xml' | |
} | |
} | |
Write-Output "$(Get-Date -Format T) - Starting Request..." | |
$StoreInfResponse = Invoke-RestMethod @StoreInf | |
Write-Output "$(Get-Date -Format T) - Finished Request." | |
Write-Output "$(Get-Date -Format T) - Starting Output handling..." | |
$Store = $StoreInfResponse.document.stores.store.properties.name | |
$SSID = $StoreInfResponse.document.stores.store.properties.ssid | |
$SizeTotal = $StoreInfResponse.document.stores.store.properties.userdatastored | |
$SizeOnDisk = $StoreInfResponse.document.stores.store.properties.sizeondisk | |
$DDRate = $StoreInfResponse.document.stores.store.properties.deduperatio | |
$StoresCount = ($Store).count | |
Write-Output "$(Get-Date -Format T) - Finished Output handling." | |
Write-Output "$(Get-Date -Format T) - Finished Store enumaration." | |
Write-Output "`n $StoresCount Stores found on SID: $x" | |
$DDRate = $DDRate | foreach {$i=1} {if ($i++ %2){$_}} | |
for ($i = 0; $i -lt $StoresCount; $i++ ){ | |
$row = New-object PSObject | |
$row | Add-Member -Name StoreName -Value $Store[$i] -Membertype NoteProperty | |
$row | Add-Member -Name Array -Value $D2DIP -Membertype NoteProperty | |
$row | Add-Member -Name SID -Value $SSID[$i] -Membertype NoteProperty | |
$row | Add-Member -Name SizeOnDisk -Value ([math]::Round(($SizeOnDisk[$i]),2)) -Membertype NoteProperty | |
$row | Add-Member -Name SizeTotal -Value ([math]::Round(($SizeTotal[$i]),2)) -Membertype NoteProperty | |
$row | Add-Member -Name DedupeRatio -Value $DDRate[$i] -Membertype NoteProperty | |
$Stores += $row | |
} | |
} | |
} | |
$TotalSizeOnDisk = [math]::Round((($Stores.SizeOnDisk | Measure-Object -Sum).Sum / 1024),2) | |
$TotalSizeTotal = [math]::Round((($Stores.SizeTotal | Measure-Object -Sum).Sum / 1024),2) | |
$AverageDedupeRatio = [math]::Round((($Stores.DedupeRatio | Measure-Object -Average).Average),2) | |
# Data Output | |
Write-Output "`n" | |
$Stores | ft -AutoSize | |
Write-Output "`nTotal Size on Disk: $TotalSizeOnDisk TB - Total Object Size: $TotalSizeTotal TB" | |
Write-Output "`nAverage Dedup Ratio: $AverageDedupeRatio`n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment