New-AzIotHubSasToken

Generate a SAS token for a target IoT Hub, device or module.

Syntax

New-AzIotHubSasToken
   [-ResourceGroupName] <String>
   [-IotHubName] <String>
   [-DeviceId <String>]
   [-ModuleId <String>]
   [-KeyName <String>]
   [-KeyType <PSKeyType>]
   [-Duration <Int32>]
   [-DefaultProfile <IAzureContextContainer>]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]
New-AzIotHubSasToken
   [-InputObject] <PSIotHub>
   [-DeviceId <String>]
   [-ModuleId <String>]
   [-KeyName <String>]
   [-KeyType <PSKeyType>]
   [-Duration <Int32>]
   [-DefaultProfile <IAzureContextContainer>]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]
New-AzIotHubSasToken
   [-ResourceId] <String>
   [-DeviceId <String>]
   [-ModuleId <String>]
   [-KeyName <String>]
   [-KeyType <PSKeyType>]
   [-Duration <Int32>]
   [-DefaultProfile <IAzureContextContainer>]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]

Description

For device SAS tokens, the policy parameter is used to access the device registry only. Therefore the policy should have read access to the registry. For IoT Hub tokens the policy is part of the SAS.

Examples

Example 1

New-AzIotHubSasToken -ResourceGroupName "myresourcegroup" -IotHubName "myiothub"

Generate an IoT Hub SAS token using the iothubowner policy and primary key.

Example 2

New-AzIotHubSasToken -ResourceGroupName "myresourcegroup" -IotHubName "myiothub" -KeyName "registryRead" -KeyType "secondary"

Generate an IoT Hub SAS token using the registryRead policy and secondary key.

Example 3

New-AzIotHubSasToken -ResourceGroupName "myresourcegroup" -IotHubName "myiothub" -DeviceId "myDevice1"

Generate a device SAS token using the iothubowner policy to access the {iothub_name} device registry.

Example 4

New-AzIotHubSasToken -ResourceGroupName "myresourcegroup" -IotHubName "myiothub" -DeviceId "myDevice1" -ModuleId "myModule1"

Generate a module SAS token using the iothubowner policy to access the {iothub_name} device registry.

Parameters

-Confirm

Prompts you for confirmation before running the cmdlet.

Type:SwitchParameter
Aliases:cf
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-DefaultProfile

The credentials, account, tenant, and subscription used for communication with Azure.

Type:IAzureContextContainer
Aliases:AzContext, AzureRmContext, AzureCredential
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-DeviceId

Target Device Id.

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Duration

Future expiry (in seconds) of the token to be generated. Default is 3600.

Type:Int32
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-InputObject

IotHub object

Type:PSIotHub
Position:0
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-IotHubName

Name of the Iot Hub

Type:String
Position:1
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-KeyName

Access key name.

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-KeyType

Access key type.

Type:PSKeyType
Accepted values:primary, secondary
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-ModuleId

Target Module Id.

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-ResourceGroupName

Name of the Resource Group

Type:String
Position:0
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-ResourceId

IotHub Resource Id

Type:String
Position:0
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Type:SwitchParameter
Aliases:wi
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

Inputs

PSIotHub

String

Outputs

String