forked from PowerCLIGoodies/DRSRule
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDRSRuleUtil.psm1
65 lines (59 loc) · 1.64 KB
/
DRSRuleUtil.psm1
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
## functions that are used by the module, but not published for end-user consumption
Function Get-DrsRuleObject
{
<# .Description
Supporting function to get Rule object of given type
#>
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline = $True)]
[ValidateNotNullOrEmpty()]
[PSObject[]]$Object,
[String]$Type
)
Process
{
$Object | where {$_.Type -match $Type}
}
}
function Get-ClusterObjFromClusterParam
{
<# .Description
Function to get cluster object(s) from given PSObject (expecting string, ClusterImpl object, or $null). If $null, then gets all clusters in connected VIServers
.Outputs
ClusterImpl objects
#>
param(
[PSObject[]]$Cluster
)
process {
if($null -eq $Cluster) {Get-Cluster}
else {
$Cluster | Foreach-Object {
if($_ -is [System.String]){
Get-Cluster -Name $_
}
else{$_}
}
}
}
} ## end function
function _Test-TypeOrString
{
<# .Description
Helper function to test if object is either of type String or $Type
.Outputs
Boolean -- $true if objects are all either String or the given $Type; $false otherwise
#>
param(
## Object to test
[parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][PSObject[]]$ObjectToTest,
## Type of object for which to check
[parameter(Mandatory=$true)][Type]$Type
)
process {
## make sure that all values are either a String or a Cluster obj
$arrCheckBoolValues = $ObjectToTest | Foreach-Object {($_ -is [System.String]) -or ($_ -is $Type)}
return (($arrCheckBoolValues -contains $true) -and ($arrCheckBoolValues -notcontains $false))
}
} ## end function