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
60
61
62
63
64
65
66
67
68
69
#Requires -Module Az.IotHub
#Requires -PSEdition Core, Desktop
#Requires -Version 5.1

function New-IotHubProperties {
    <#
 .Synopsis
  Create an object to set desired PartitionsCount and RetentionTimeInDays for New-AzIotHub cmdlet.
 
 .Description
  Create an object to set desired PartitionsCount and RetentionTimeInDays for New-AzIotHub cmdlet.
  The object created must be passed to -Properties param of New-AzIotHub command. It is recommended to store it in a variable.
 
 .Parameter PartitionsCount
  The desired partitions number (min 2, MAX 128)
 
 .Parameter RetentionTimeInDays
  The desired RetentionTimeInDays number (min 1, MAX 7)
 
 .Example
   # Create an PSIotHubInputProperties object with 32 Partitions and 2 days of retention.
   New-IotHubProperties -PartitionsCount 32 -RetentionTimeInDays 2
 
 .Example
   # Create an PSIotHubInputProperties object with 8 Partitions and 1 day of retention.
   New-IotHubProperties -Partitions 8
 
 .Example
   # Create an PSIotHubInputProperties object with 32 Partitions and 2 days of retention and store it in a variable.
   $IotHubInputProperties = New-IotHubProperties -Partitions 32 -Retention 2
 
   .Link
   https://github.com/Stereo89/Azereo/tree/master/New-IotHubProperties
    
#>


[OutputType('Microsoft.Azure.Commands.Management.IotHub.Models.PSIotHubInputProperties')]

    Param(
        [Parameter(Mandatory=$True,ValueFromPipeline=$true)]
        [ValidateRange(2,128)]
        [Alias("Partitions")]
        [int16]
        $PartitionCount,
        [Parameter(Mandatory=$false,ValueFromPipeline=$true)]
        [ValidateRange(1,7)]
        [Alias("Retention")]
        [int16]
        $RetentionTimeInDays = 1
        ) 
    Process 
    { 
       $IotHubInputProps = [Microsoft.Azure.Commands.Management.IotHub.Models.PSIotHubInputProperties]::new()
       $EventHubInputProps = [Microsoft.Azure.Commands.Management.IotHub.Models.PSEventHubInputProperties]::new()
       $EventHubInputProps.PartitionCount = $PartitionCount
       $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