PowerShell Scripting Disclaimer:
This script is provided "as is" for the purpose of illustrating how product tasks may be performed in conjunction with PowerShell. Support shall not be liable for any direct, indirect, incidental, consequential, or other damage alleged in connection with the furnishing or use of this script or of the principles it demonstrates. See PowerShell Scripting Support for more information.
A Powershell script to address the issue has been prepared. The script takes into consideration that the repository size is in bytes and uses two functions to do the appropriate transformations into units of measure which are more palatable, taking into account the size of the repository.
The Script requires PowerShell 3.0 or later.
It can be run directly on the core -- in which case it does not require any parameters or from an independent workstation, in which case port 8006 needs to be open, the name core making the subject of inquiry needs to be resolvable (IP addresses are OK as well). In this case, the script takes as parameters the name of the core ( -corename) and prompts for credentials if the -credentials parameter is specified.
The script is fully documented. The information can be retrieved by running:
PS c:\scripts> get-help .\Repositories.ps1 -full
The commented Script is shown below between horizontal lines and attached to the KB.
#---------------------------------------------------------------
.Synopsis
Gets Repository Information
.Parameter corename
default '$env:computername'
.Parameter credentials
default credentials are local user's.
.Example
PS C:\scripts>.\Repositories.ps1 -corename 10.23.20.156 -credential
.Example
PS C:\scripts>.\Repositories.ps1
#>
#parameters to be use if the script is run from a local workstation. No need to use any parameters if it is run from the core.
param ($corename=$env:computername,[switch]$credential)
### FUNCTIONS ###########################
#function to convert bytes into the appropriate units of measure
function private:convert-bytes {
param($x)
if ($x/1TB -lt 1){
if ($x/1GB -lt 1){
if ($x/1MB -lt 1){
if ($x/1KB -lt 1){
{return [pscustomobject]@{value=($x);UM="B"}}
}
else {return [pscustomobject]@{value=($x/1KB);UM="KB"}}
}
else {return [pscustomobject]@{value=($x/1MB);UM="MB"}}
}
else {return [pscustomobject]@{value=($x/1GB);UM="GB"}}
}
else {return [pscustomobject]@{value=($x/1TB);UM="TB"}}
}
##############################
#functions to simplify showing the results of conversion
function finish-convert {
param ($y)
return "{0:N2}$($y.um)" -f $y.value
}
##############################
#enter credentials if the -credentials parameter is present
if($credential.IsPresent){$cred = get-credential -Message "$($corename) credentials:"}
#Create title, clear screen, show title & underline it
$title= "Repository Information for Core $corename"
$titlecount = $title.length
cls;
Write-Host "$($title)`r`n$('-'*$titlecount)`r`n" -ForegroundColor Green
#get into repositories...
try{ #manage errors
#Create the object to retrieve the Repositories information
$url = "https://$($corename):8006/apprecovery/api/core/reposManagement/repositories"
$wc = New-Object System.Net.WebClient
#Use credentials if entered
if($cred){$wc.Credentials = $cred}else{$wc.usedefaultcredentials=$true}
#Retrieve the Repository information
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }
[xml]$repoinfo = $wc.DownloadString($url)
$repoobject = $repoinfo.repositories.repository | sort-object -Property repositoryname -Descending
#process repositories data
[array]$repositories=$null
foreach($reposingle in $repoobject){
$size=finish-convert -y (convert-bytes -x $reposingle.size)
$free=finish-convert -y (convert-bytes -x $reposingle.free);
$percentfree="{0:N2}%" -f (100*([long]($reposingle.free))/([long]($reposingle.size)))
$compression="{0:N2}%" -f (100*($reposingle.stats.compressionratio))
$dedupe="{0:N2}%" -f (([long]($reposingle.stats.dedupehits))/([long]($reposingle.stats.dedupehits) + [long]($reposingle.stats.dedupemisses) + 1)*100)
$repoline = [pscustomobject]@{Name=$reposingle.repositoryname;Size=$size;Free=$free;PercentFree=$percentfree;Compression=$compression;Deduplication=$dedupe}
$repositories+=$repoline
}
#Prepare data to be shown
$repositories = $repositories | sort-object -property Name | select-object -Property @{n="Repository Name";e={$_.name}},@{n="Repository Size";e={$_.size}},@{n="Free Space";e={$_.free}},@{n="Free Space `%";e={$_.percentfree}},@{n="Compression Rate";e={$_.compression}},@{n="Deduplication Rate";e={$_.deduplication}}
#Show Result
$repositories
} catch {Write-Host "Retrieving repository information from $corename failed" -f Red;$repositoryInformation="unavailable";$repositories=$null;$repoobject=$null}
#-----------------------------------------------------------------
#---------------------------------------------------------------