Find the Cluster Shared Volume (CSV) with the most available free space

This script uses powershell to query the cluster for all Cluster Shared Volumes (CSV). It then returns the path to the CSV with the most space available. Space is measured as a % rather than GB. I ammended an existing script already available on technet to meet my requirements. T

 
 
 
 
 
5 Star
(2)
1,361 times
Add to favorites
System Center
10/30/2013
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Revised.
    1 Posts | Last post March 18, 2016
    • I still need it so I can only check 2 volumes instead of all of them in csv
      
      
      $objs = @() 
      $cluster = "CEP-HV-STAGING"
       
      #Gets the cluster shared volumes from the cluster and their associated properties 
      $csvs = Get-ClusterSharedVolume -Cluster $cluster  
      foreach ( $csv in $csvs ) 
      { 
         $csvinfos = $csv | select -Property Name -ExpandProperty SharedVolumeInfo 
         foreach ( $csvinfo in $csvinfos ) 
         { 
            $obj = New-Object PSObject -Property @{ 
               Path        = $csvinfo.FriendlyVolumeName 
               PercentFree = $csvinfo.Partition.PercentFree 
            } 
            $objs += $obj 
         } 
      } 
       
      
      $mostfree = $objs |  Sort-Object -property PercentFree -Descending | Select-Object -First 1 | Select -ExpandProperty Path
      $CSV = $mostfree
      $CSV
  • Is there a way I can get it to search through 2 cluster storage volumes instead and find the one with the most amount of free space?
    1 Posts | Last post March 18, 2016
    • This is what I have so far. I've pretty much figured it all out except for the part where I need it to search through two volumes instead of through all of them and find the one with the most amount of free space:
      
      $objs = @() 
      $cluster = "CEP-HV-STAGING"
      
      $volumes = @(
      'vol35',
      'vol36'
      )
       
      #Gets the cluster shared volumes from the cluster and their associated properties 
      $csvs = $volumes | % { Get-ClusterSharedVolume -Cluster $cluster -Name $_ }  
      foreach ( $csv in $csvs ) 
      { 
         $csvinfos = $csv | select -Property Name -ExpandProperty SharedVolumeInfo 
         foreach ( $csvinfo in $csvinfos ) 
         { 
            $obj = New-Object PSObject -Property @{ 
               Path        = $csvinfo.FriendlyVolumeName 
               PercentFree = $csvinfo.Partition.PercentFree 
            } 
            $objs += $obj 
         } 
      } 
       
      
      $mostfree = $objs |  Sort-Object -property PercentFree -Descending | Select-Object -First 1 | Select -ExpandProperty Path
      $CSV = $mostfree
      $CSV
  • with this script
    1 Posts | Last post March 18, 2016
    • # Defined Variables
      $VMMServer = 'c-e-s'
      $VMNetwork = Get-SCVMNetwork -VMMServer $VMMServer -Name "Production"
      $TemplateName = 'S-342-2K12R2'
      $objs = @() 
      $CSV = 'C:\clusterstorage\volume35'
      
      $JobGroup = 'd45cf-55a0'
      $CPUType = Get-SCCPUType -VMMServer $VMMServer | where {$_.Name -eq "3.60 GHz Xeon (2 MB L2 cache)"}
      $VirtualNetworkAdapter = Get-SCVirtualNetworkAdapter -VMMServer $VMMServer -Name $TemplateName -ID "b345507"
      [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null
      $CloneName = [Microsoft.VisualBasic.Interaction]::InputBox("Enter Virtual Machine Clone Name:")
      
      # Create New VirutalSCSIAdapter
      New-SCVirtualScsiAdapter -VMMServer $VMMServer -JobGroup $JobGroup -AdapterID 255 -ShareVirtualScsiAdapter $false -ScsiControllerType DefaultTypeNoType 
      
      # Create New Virtual DVD Drive
      # New-SCVirtualDVDDrive -VMMServer $VMMServer -JobGroup $JobGroup -Bus 0 -LUN 1 
      
      # Create New Virtual Network Adapter
      New-SCVirtualNetworkAdapter `
          -VMMServer $VMMServer `
          -JobGroup $JobGroup `
          -MACAddressType Dynamic `
          -VirtualNetwork "Production" `
          -VLanEnabled $false `
          -Synthetic `
          -EnableVMNetworkOptimization $false `
          -EnableMACAddressSpoofing $false `
          -EnableGuestIPNetworkVirtualizationUpdates $false `
          -IPv4AddressType Dynamic `
          -IPv6AddressType Dynamic `
          -VMNetwork $VMNetwork 
      
      # Create New Hardware Profile
      New-SCHardwareProfile `
          -VMMServer $VMMServer `
          -CPUType $CPUType `
          -Name "Profile7c272341" `
          -Description "Profile used to create a VM/Template" `
          -CPUCount 4 `
          -MemoryMB 8192 `
          -DynamicMemoryEnabled $true `
          -DynamicMemoryMinimumMB 4096 `
          -DynamicMemoryMaximumMB 12288 `
          -DynamicMemoryBufferPercentage 20 `
          -MemoryWeight 5000 `
          -CPUExpectedUtilizationPercent 20 `
          -DiskIops 0 `
          -CPUMaximumPercent 100 `
          -CPUReserve 0 `
          -NumaIsolationRequired $false `
          -NetworkUti
  • I need to integrate this script
    1 Posts | Last post March 18, 2016
    • I have this so far but am not sure how to integrate it so I can run it with SCVMM:
      
      $objs = @() 
      $cluster = "CEP-HV-STAGING" 
       
      #Gets the cluster shared volumes from the cluster and their associated properties 
      $csvs = Get-ClusterSharedVolume -Cluster $cluster  
      foreach ( $csv in $csvs ) 
      { 
         $csvinfos = $csv | select -Property Name -ExpandProperty SharedVolumeInfo 
         foreach ( $csvinfo in $csvinfos ) 
         { 
            $obj = New-Object PSObject -Property @{ 
               Path        = $csvinfo.FriendlyVolumeName 
               PercentFree = $csvinfo.Partition.PercentFree 
            } 
            $objs += $obj 
         } 
      } 
       
      #Selects the CSV with the most free space as a % 
      $mostfree = $objs |  Sort-Object -property PercentFree -Descending | Select-Object -First 1 
      
      $CSV = $mostfree
  • Choose between two different volumes on cluster storage
    1 Posts | Last post March 18, 2016
    • I'm in the process of creating a script for a virtual machine to be created through SCVMM and I need to write a script that will choose between two different volumes on the cluster storage: C:\ClusterStorage\Volume35 and C:\ClusterStorage\Volume36. I don't know how to set this up in the script, however, to choose the one with the most free space between the two. My script looks like this and I was hoping maybe you could help me with the commands that will check the free space available on each of those volumes and choose the one with the most free space so the virtual machine can be created and not go into a paused state once it is started up. The reason for doing this is to automate the process so we don't have to go in and check the volumes each time. More volumes may be added to check in the future but for now it is between the two. Here is the script I wrote so you can see what I am trying to do.
      
      
      # Defined Variables
      $VMMServer = 'cep-sc-01'
      $VMNetwork = Get-SCVMNetwork 
      -VMMServer $VMMServer 
      -Name "Production"
      $TemplateName = 'S-Template'
      $CSV = 'C:\ClusterStorage\Volume35'
      $JobGroup = 'dbfgcf-5sdf0-4dfgcc-a7a7-b8dfga7f'
      $CPUType = Get-SCCPUType -VMMServer $VMMServer | where {$_.Name -eq "3.60 GHz Xeon (2 MB L2 cache)"}
      $VirtualNetworkAdapter = Get-SCVirtualNetworkAdapter -VMMServer $VMMServer -Name $TemplateName -ID "bc2dfsdf7-359f-4f13-asdf1-b58sdf030"
      [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null
      $CloneName = [Microsoft.VisualBasic.Interaction]::InputBox("Enter Virtual Machine Clone Name:")
      
      # Create New VirutalSCSIAdapter
      New-SCVirtualScsiAdapter 
      -VMMServer $VMMServer 
      -JobGroup $JobGroup 
      -AdapterID 255 
      -ShareVirtualScsiAdapter $false 
      -ScsiControllerType DefaultTypeNoType 
      
      # Create New Virtual DVD Drive
      # New-SCVirtualDVDDrive 
      -VMMServer $VMMServer 
      -JobGroup $JobGroup 
      -Bus 0 -LUN 1