Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 通过Azure RM的Cosmos数据库集索引策略_Powershell_Azure Cosmosdb_Azure Rm - Fatal编程技术网

Powershell 通过Azure RM的Cosmos数据库集索引策略

Powershell 通过Azure RM的Cosmos数据库集索引策略,powershell,azure-cosmosdb,azure-rm,Powershell,Azure Cosmosdb,Azure Rm,我正在尝试从Azure RM powershell脚本中将Cosmos DB帐户的索引策略设置为“无”,但运气不佳 $tableProperties = @{ resource=@{ id=$table; indexingPolicy= @{indexingMode="none"; automatic = "false"; includedPaths = "[]"; excludedPaths = "[]" } }; options=@{ Throughput= 500

我正在尝试从Azure RM powershell脚本中将Cosmos DB帐户的索引策略设置为“无”,但运气不佳

  $tableProperties = @{
    resource=@{ id=$table; indexingPolicy= @{indexingMode="none"; automatic = "false"; includedPaths = "[]"; excludedPaths = "[]" }  };
     options=@{ Throughput= 500 }
}

  Set-AzureRmResource -ResourceType $tableResourceType `
        -ApiVersion $apiVersion -ResourceGroupName $resourceGroupName `
        -Name $tableResourceName -PropertyObject $tableProperties -Force 
从Cosmos DB索引策略节点

{
"indexingMode": "consistent",
"automatic": true,
"includedPaths": [
    {
        "path": "/*"
    }
],
"excludedPaths": [
    {
        "path": "/\"_etag\"/?"
    }
]
}

更新: 尝试:


运气不好

对于索引策略,只需将indexingMode设置为“无”。此外,Cosmos中的子资源不支持修补程序,因此对于资源上的任何PUT,您需要包括已设置的任何其他属性,包括所需的partitionKey。见下面的例子

更新:此示例使用AzureRM资源,因为AzureRM已被弃用

$apiVersion="2019-08-01"
$containerResourceType = "Microsoft.DocumentDb/databaseAccounts/sqlDatabases/containers"
$resourceGroupName="myResourceGroup"
$containerName = "mycosmosaccount/myDatabase/myContainer"

$containerGet = Get-AzResource -ResourceType $containerResourceType `
    -ApiVersion $apiVersion -ResourceGroupName $resourceGroupName `
    -Name $containerName | Select-Object -ExpandProperty Properties

$containerProperties = @{
    "resource"=@{
        "id"=$containerGet.resource.id; 
        "partitionKey"=$containerGet.resource.partitionKey;
        "indexingPolicy"=@{"indexingMode"="none"}
    }
}

Set-AzResource -ResourceType $containerResourceType `
    -ApiVersion $apiVersion -ResourceGroupName $resourceGroupName `
    -Name $containerName -PropertyObject $containerProperties -Force 

嗨,马克,谢谢你的回复。我使用的是tableAPI,而不是SQL。我尝试了后来在答案中更新的脚本,但没有成功:(这就是原因,因为表API没有索引策略。索引策略只适用于SQL API。
$apiVersion="2019-08-01"
$containerResourceType = "Microsoft.DocumentDb/databaseAccounts/sqlDatabases/containers"
$resourceGroupName="myResourceGroup"
$containerName = "mycosmosaccount/myDatabase/myContainer"

$containerGet = Get-AzResource -ResourceType $containerResourceType `
    -ApiVersion $apiVersion -ResourceGroupName $resourceGroupName `
    -Name $containerName | Select-Object -ExpandProperty Properties

$containerProperties = @{
    "resource"=@{
        "id"=$containerGet.resource.id; 
        "partitionKey"=$containerGet.resource.partitionKey;
        "indexingPolicy"=@{"indexingMode"="none"}
    }
}

Set-AzResource -ResourceType $containerResourceType `
    -ApiVersion $apiVersion -ResourceGroupName $resourceGroupName `
    -Name $containerName -PropertyObject $containerProperties -Force