New-IotHubProperties.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
#Requires -Module AzureRM.IoTHub
<#
 .Synopsis
  Create an object to set desired PartitionsCount and RetentionTimeInDays for New-AzureRmIotHub cmdlet.
 
 .Description
  Create an object to set desired PartitionsCount and RetentionTimeInDays for New-AzureRmIotHub cmdlet.
  The object created must be passed to -Properties param of New-AzureRmIotHub command. It is recommended to store it in a variable.
 
 .Parameter PartitionCount
  The desired partitions number.
 
 .Parameter RetentionTimeInDays
  The desired RetentionTimeInDays number.
 
 .Example
   # Create an PSIotHubInputProperties object with 32 Partitions and 2 days of retention.
   Create-IotHubProperties -PartitionCount 32 -RetentionTimeInDays 2
 
 .Example
   # Create an PSIotHubInputProperties object with 8 Partitions and 1 day of retention.
   Create-IotHubProperties -PartitionCount 8
 
 .Example
   # Create an PSIotHubInputProperties object with 32 Partitions and 2 days of retention and store it in a variable.
   $IotHubInputProperties = Create-IotHubProperties -PartitionCount 32 -RetentionTimeInDays 2
 
#>


function New-IotHubProperties {
    Param(
        [Parameter(Mandatory=$True,ValueFromPipeline=$true)]
        [ValidateRange(2,128)]
        [Int]
        $PartitionCount,
        [Parameter(Mandatory=$false,ValueFromPipeline=$true)]
        [ValidateRange(1,7)]
        [Int]
        $RetentionTimeInDays = 1
        ) 
    Process 
    { 
       $IoTHubInputProps = New-Object -TypeName Microsoft.Azure.Commands.Management.IotHub.Models.PSIotHubInputProperties
       $EventHUbInputProps = [Microsoft.Azure.Commands.Management.IotHub.Models.PSEventHubInputProperties]::new()
       $EventHUbInputProps.PartitionCount = $EventHUbInputProps
       $EventHUbInputProps.RetentionTimeInDays = $RetentionTimeInDays

       $Dictionary = New-Object 'System.Collections.Generic.Dictionary[string,Microsoft.Azure.Commands.Management.IotHub.Models.PSEventHubInputProperties]'

       $Dictionary.Add([string]"events",[Microsoft.Azure.Commands.Management.IotHub.Models.PSEventHubInputProperties]$EventHUbInputProps)

       $IoTHubInputProps.EventHubEndpoints = $dictionary

       return $IoTHubInputProps
   } 

}

Export-ModuleMember -Function New-IotHubProperties