Public/Enable-UnityFastCache.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
Function Enable-UnityFastCache {

  <#
      .SYNOPSIS
      Enable FAST Cache.
      .DESCRIPTION
      Enable FAST Cache using specified disk group and number of disks and if specified, Enable FAST Cache on all existing pools.
      You need to have an active session with the array.
      .NOTES
      Written by Erwan Quelin under MIT licence - https://github.com/equelin/Unity-Powershell/blob/master/LICENSE
      .LINK
      https://github.com/equelin/Unity-Powershell
      .PARAMETER Session
      Specifies an UnitySession Object.
      .PARAMETER diskgroup
      Specify the disk group ID to include in the FAST Cache.
      .PARAMETER numberOfDisks
      Specify the number of disks to include in the FAST Cache.
      .PARAMETER enableOnAllPools
      Specify whether FAST Cache is enabled on all existing pools.
      .EXAMPLE
      Enable-UnityFastCache -diskgroup 'DG_1' -numberOfDisks 2

      Enable Fast Cache with 2 disk from the disk group 'DG_1'
  #>


    [CmdletBinding(SupportsShouldProcess = $True,ConfirmImpact = 'High')]
  Param (
    #Default Parameters
    [Parameter(Mandatory = $false,HelpMessage = 'EMC Unity Session')]
    $session = ($global:DefaultUnitySession | where-object {$_.IsConnected -eq $true}),

    #FastCache enable parameters
    [Parameter(Mandatory = $true,HelpMessage = 'Disk group ID from which to take disks for FAST cache')]
    [string]$diskgroup,
    [Parameter(Mandatory = $true,HelpMessage = 'Number of disks')]
    [int]$numberOfDisks,
    [Parameter(Mandatory = $false,HelpMessage = 'Enable FAST Cache for all existing pools')]
    [switch]$enableOnAllPools
  )

  Begin {
    Write-Debug -Message "[$($MyInvocation.MyCommand)] Executing function"
  }

  Process {

    Foreach ($sess in $session) {

      Write-Debug -Message "Processing Session: $($sess.Server) with SessionId: $($sess.SessionId)"

      If ($Sess.TestConnection()) {

          # Creation of the body hash
          $body = @{}
          
          #diskgroup
          $body['diskgroup'] = @{}
            $diskgroupParam = @{}
            $diskgroupParam['id'] = $diskgroup
          $body['diskgroup'] = $diskgroupParam

          #numberOfDisks
          $body['numberOfDisks'] = $numberOfDisks

          # enableOnAllPools
          If ($PSBoundParameters.ContainsKey('enableOnAllPools')) {
            $body["enableOnAllPools"] = $true
          }

          #Building the URI
          $URI = 'https://'+$sess.Server+'/api/instances/fastCache/0/action/enable?timeout=0' #run async
          Write-Verbose "URI: $URI"

          #Sending the request
          If ($pscmdlet.ShouldProcess($($Sess.Server),"Enable Fast Cache")) {
            $request = Send-UnityRequest -uri $URI -Session $Sess -Method 'POST' -Body $Body
          }

          If ($request.StatusCode -eq '202') {
            Write-Host "Fast Cache is currently enabling"
          }

      } else {
        Write-Information -MessageData "You are no longer connected to EMC Unity array: $($Sess.Server)"
      }
    }
  }

  End {}
}