Skip to content

Instantly share code, notes, and snippets.

@mczerniawski
Last active February 18, 2019 16:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mczerniawski/3b865a34118b2b48b6d3650baacafa12 to your computer and use it in GitHub Desktop.
Save mczerniawski/3b865a34118b2b48b6d3650baacafa12 to your computer and use it in GitHub Desktop.
function Get-ClusterCSVUsage {
<#
.SYNOPSIS
Retrieves CSV detailed information from Cluster
.DESCRIPTION
Will connect to cluster using Invoke-Command (to allow use of optional Credential Parameter) and retrieve detailed information on any CSV found
.PARAMETER Cluster
Cluster Name or array of Cluster Names
.PARAMETER Credential
Optional PSCredential Parameter
.EXAMPLE
Get-ClusterCSVUsage -Cluster 'SomeCluster' -Credential (Get-Credential) | Format-Table
Will connect to SomeCluster and return CSV detailed information
Name Path FileSystem Size FreeSpace UsedSpace PercentFree MaintenanceMode IsCompressed OwnerNode
---- ---- ---------- ---- --------- --------- ----------- --------------- ------------ ---------
Cluster Virtual Disk (Disk1) C:\ClusterStorage\Disk1 CSVFS 11880 4553 7327 38 False False Node1
Cluster Virtual Disk (Disk2) C:\ClusterStorage\Disk2 CSVFS 11880 3073 8807 26 False False Node2
#>
[CmdletBinding()]
param(
[Parameter(Mandatory, HelpMessage = 'Provide Cluster Name',
ValueFromPipeline, ValueFromPipelineByPropertyName)]
[ValidateNotNullOrEmpty()]
[System.String[]]
$Cluster,
[Parameter(Mandatory = $false, HelpMessage = 'Provide Credentials for Cluster',
ValueFromPipeline, ValueFromPipelineByPropertyName)]
[System.Management.Automation.PSCredential]
$Credential
)
process {
foreach ($ClusterName in $Cluster) {
$connectionParams = @{
ComputerName = $ClusterName
}
if ($PSBoundParameters.ContainsKey('Credential')) {
$connectionParams.Credential = $Credential
Write-Verbose -Message "Processing with provided credentials {$($Credential.UserName)}"
}
else {
Write-Verbose -Message "Processing with default credentials of user {$($env:USERNAME)}"
}
#region CODE
Write-Verbose -Message "Processing $($connectionParams.ComputerName)"
$csvUsage = Invoke-Command @connectionParams -ScriptBlock {
$csvs = Get-ClusterSharedVolume
if ($csvs) {
foreach ($csv in $csvs) {
$csvProperties = $csv | Select-Object -Property Name -ExpandProperty SharedVolumeInfo
[pscustomobject]@{
Name = $csv.Name
Path = $csvProperties.FriendlyVolumeName
FileSystem = $csvProperties.Partition.FileSystem
Size = $csvProperties.Partition.Size / 1gb -as [int]
FreeSpace = $csvProperties.Partition.FreeSpace / 1gb -as [int]
UsedSpace = $csvProperties.Partition.UsedSpace / 1gb -as [int]
PercentFree = $csvProperties.Partition.PercentFree -as [int]
MaintenanceMode = $csvProperties.MaintenanceMode
IsCompressed = $csvProperties.Partition.IsCompressed
OwnerNode = $csv.OwnerNode
State = $csv.State
}
}
}
}
if ($csvUsage) {
$csvUsage| Select-Object * -ExcludeProperty PSComputerName, RunspaceID
}
else {
Write-Verbose -Message "No CSV found on cluster {$ClusterName}"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment