Azure通知中心增加了#34;注册生存时间"使用rest API和Powershell

时间:2018-01-12 19:06:11

标签: powershell azure azure-notificationhub

仅仅注意到一年多前的#34;注册生存时间"能够从90天增加到永远。我想将实时集线器配置为最大值,但不能在门户中进行编辑,必须编写一些内容才能完成。

我在Powershell中广泛使用了hub rest API,并且有一个PUT API来Update Notification Hub;

https:// {namespace} .servicebus.windows.net / {Notification Hub}?api-version = 2015-01

Haven以前没有使用过这个特定的API,似乎无法弄清楚如何让它在Powershell中运行(已经使用授权令牌排序)。

是否有人准备共享一个Powershell示例,显示正确的参数,特别是请求正文的结构,以便在通知中心上实现RTL更改。?

它只是一个oncer,因为新的集线器是使用默认的无限制RTL创建的。

最值得赞赏的任何帮助。干杯!

1 个答案:

答案 0 :(得分:0)

最后通过一个完整的示例字符串来更新集线器,在这种情况下将“生存时间”更改为365天。希望别人觉得这很有用。请注意,您必须包含集线器中所需的所有参数,否则它们将被吹走。请特别注意更新并保留主键以进行更新和访问,否则您将自己锁定在集线器之外,并且必须手动更新门户中的密钥。

$RegURI = "https://mightyhubs.servicebus.windows.net/bing?api-version=2015-01";
$ContentType = "application/xml;type=entry;charset=utf-8"
Sub routine to create your $Token in here...

$HubUpdateString = @"
<?xml version="1.0" encoding="utf-8"?>
<entry
    xmlns="http://www.w3.org/2005/Atom">
    <content type="application/xml">
    <NotificationHubDescription
        xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
        <RegistrationTtl>P365D</RegistrationTtl>
        <AuthorizationRules>
            <AuthorizationRule i:type="SharedAccessAuthorizationRule">
                <ClaimType>SharedAccessKey</ClaimType>
                <ClaimValue>None</ClaimValue>
                <Rights>
                    <AccessRights>Listen</AccessRights>
                    <AccessRights>Manage</AccessRights>
                    <AccessRights>Send</AccessRights>
                </Rights>
                <KeyName>DefaultFullSharedAccessSignature</KeyName>
     <PrimaryKey>FULLKEY1232F94807DC72465F298CBE5201197CA40</PrimaryKey>
     <SecondaryKey>FULLKEY2232F94807DC72465F298CBE5201197CA40</SecondaryKey>
            </AuthorizationRule>
            <AuthorizationRule i:type="SharedAccessAuthorizationRule">
                <ClaimType>SharedAccessKey</ClaimType>
                <ClaimValue>None</ClaimValue>
                <Rights>
                    <AccessRights>Listen</AccessRights>
                </Rights>
                <KeyName>DefaultListenSharedAccessSignature</KeyName>
   <PrimaryKey>LISTENKEY1232F94807DC72465F298CBE5201197CA40</PrimaryKey>
   <SecondaryKey>LISTENKEY2232F94807DC72465F298CBE5201197CA40</SecondaryKey>
            </AuthorizationRule>
        </AuthorizationRules>
        <GcmCredential>
            <Properties>
                <Property>
                    <Name>googleApiKey</Name>
                    <Value>12345678910</Value>
                </Property>
            </Properties>
        </GcmCredential>
    </NotificationHubDescription>
    </content>
</entry>
"@

$encodedContent = [System.Text.Encoding]::UTF8.GetBytes($HubUpdateString);
$webRequest = [System.Net.WebRequest]::Create($RegURI);

$webRequest.Method = "Put";
$webRequest.ContentType = $ContentType;
$webRequest.ContentLength = $encodedContent.length;

$webRequest.Headers.Add("Authorization","$Token");
$webRequest.Headers.Add("x-ms-version", "2015-01");
$webRequest.Headers.Add("If-Match", “*”);

$requestStream = $webRequest.GetRequestStream();
$requestStream.Write($encodedContent, 0, $encodedContent.length);
$requestStream.Close();