共用方式為


Set-AzResource

修改資源。

語法

ByResourceId (預設值)

Set-AzResource
    -ResourceId <String>
    [-Kind <String>]
    [-Properties <PSObject>]
    [-Plan <Hashtable>]
    [-Sku <Hashtable>]
    [-Tag <Hashtable>]
    [-UsePatchSemantics]
    [-AsJob]
    [-ODataQuery <String>]
    [-Force]
    [-ApiVersion <String>]
    [-Pre]
    [-DefaultProfile <IAzureContextContainer>]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

ByInputObject

Set-AzResource
    -InputObject <PSResource>
    [-Kind <String>]
    [-Properties <PSObject>]
    [-Plan <Hashtable>]
    [-Sku <Hashtable>]
    [-Tag <Hashtable>]
    [-UsePatchSemantics]
    [-AsJob]
    [-ODataQuery <String>]
    [-Force]
    [-ApiVersion <String>]
    [-Pre]
    [-DefaultProfile <IAzureContextContainer>]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

BySubscriptionLevel

Set-AzResource
    -ResourceName <String>
    -ResourceType <String>
    [-Kind <String>]
    [-Properties <PSObject>]
    [-Plan <Hashtable>]
    [-Sku <Hashtable>]
    [-Tag <Hashtable>]
    [-UsePatchSemantics]
    [-AsJob]
    [-ExtensionResourceName <String>]
    [-ExtensionResourceType <String>]
    [-ODataQuery <String>]
    [-ResourceGroupName <String>]
    [-Force]
    [-ApiVersion <String>]
    [-Pre]
    [-DefaultProfile <IAzureContextContainer>]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

ByTenantLevel

Set-AzResource
    -ResourceName <String>
    -ResourceType <String>
    [-Kind <String>]
    [-Properties <PSObject>]
    [-Plan <Hashtable>]
    [-Sku <Hashtable>]
    [-Tag <Hashtable>]
    [-UsePatchSemantics]
    [-AsJob]
    [-ExtensionResourceName <String>]
    [-ExtensionResourceType <String>]
    [-ODataQuery <String>]
    [-TenantLevel]
    [-Force]
    [-ApiVersion <String>]
    [-Pre]
    [-DefaultProfile <IAzureContextContainer>]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

Description

Set-AzResource Cmdlet 會修改現有的 Azure 資源。 指定要依名稱和類型或 ID 修改的資源。

範例

範例 1:修改資源

$Resource = Get-AzResource -ResourceType Microsoft.Web/sites -ResourceGroupName ResourceGroup11 -ResourceName ContosoSite
$Resource.Properties.Enabled = "False"
$Resource | Set-AzResource -Force

第一個命令會使用 Get-AzResource Cmdlet 取得名為 ContosoSite 的資源,然後將它儲存在 $Resource 變數中。 第二個命令會修改 $Resource 的屬性。 最後一個命令會更新資源以符合$Resource。

範例 2:修改指定資源群組中的所有資源

$Resource = Get-AzResource -ResourceGroupName testrg
$Resource | ForEach-Object { $_.Tags.Add("testkey", "testval") }
$Resource | Set-AzResource -Force
Name              : kv-test
ResourceId        : /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/testrg/providers/Microsoft.KeyVault/vaults/kv-test
ResourceName      : kv-test
ResourceType      : Microsoft.KeyVault/vaults
ResourceGroupName : testrg
Location          : westus
SubscriptionId    : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Tags              : {testrgkey, key}
Properties        : @{}

Name              : testresource
ResourceId        : /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/testrg/providers/Providers.Test/statefulResources/testresource
ResourceName      : testresource
ResourceType      : Providers.Test/statefulResources
ResourceGroupName : testrg
Location          : West US 2
SubscriptionId    : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Tags              : {testrgkey, anothertesttag}
Properties        : @{key=value}
Sku               : @{name=A0}

第一個命令會取得 testrg 資源群組中的資源,然後將它們儲存在 $Resource 變數中。

第二個命令會逐一查看資源群組中的每個資源,並新增標籤給它們。

最後一個命令會更新每一個資源。

參數

-ApiVersion

指定要使用的資源提供者 API 版本。 如果您未指定版本,此 Cmdlet 會使用最新的可用版本。

參數屬性

類型:String
預設值:None
支援萬用字元:False
不要顯示:False

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-AsJob

在背景執行 Cmdlet

參數屬性

類型:SwitchParameter
預設值:None
支援萬用字元:False
不要顯示:False

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-Confirm

在執行 Cmdlet 之前,提示您進行確認。

參數屬性

類型:SwitchParameter
預設值:False
支援萬用字元:False
不要顯示:False
別名:參見

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-DefaultProfile

用來與 Azure 通訊的認證、帳戶、租用戶和訂用帳戶

參數屬性

類型:IAzureContextContainer
預設值:None
支援萬用字元:False
不要顯示:False
別名:AzContext, AzureRmContext, AzureCredential

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-ExtensionResourceName

指定資源的延伸資源名稱。 例如,若要指定資料庫,請使用下列格式: 伺服器名稱/資料庫名稱

參數屬性

類型:String
預設值:None
支援萬用字元:False
不要顯示:False

參數集

BySubscriptionLevel
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:True
來自剩餘引數的值:False
ByTenantLevel
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:True
來自剩餘引數的值:False

-ExtensionResourceType

指定延伸模組資源的資源類型。 例如,如果延伸模組資源是資料庫,請指定下列項目: Microsoft.Sql/Servers/Databases

參數屬性

類型:String
預設值:None
支援萬用字元:False
不要顯示:False

參數集

BySubscriptionLevel
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:True
來自剩餘引數的值:False
ByTenantLevel
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:True
來自剩餘引數的值:False

-Force

強制命令執行,而不要求使用者確認。

參數屬性

類型:SwitchParameter
預設值:None
支援萬用字元:False
不要顯示:False

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-InputObject

要更新之資源的物件表示法。

參數屬性

類型:PSResource
預設值:None
支援萬用字元:False
不要顯示:False

參數集

ByInputObject
Position:Named
必要:True
來自管線的值:True
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-Kind

指定資源的資源種類。

參數屬性

類型:String
預設值:None
支援萬用字元:False
不要顯示:False

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:True
來自剩餘引數的值:False

-ODataQuery

指定開放資料通訊協定 (OData) 樣式篩選。 除了任何其他篩選條件之外,此 Cmdlet 還會將此值附加至要求。

參數屬性

類型:String
預設值:None
支援萬用字元:False
不要顯示:False

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-Plan

將資源計劃內容指定為雜湊表。

參數屬性

類型:Hashtable
預設值:None
支援萬用字元:False
不要顯示:False
別名:規劃物件

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:True
來自剩餘引數的值:False

-Pre

指出此 Cmdlet 在自動決定要使用的版本時,會考慮發行前 API 版本。

參數屬性

類型:SwitchParameter
預設值:None
支援萬用字元:False
不要顯示:False

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-Properties

指定資源的資源內容。

參數屬性

類型:PSObject
預設值:None
支援萬用字元:False
不要顯示:False
別名:屬性物件

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:True
來自剩餘引數的值:False

-ResourceGroupName

指定此 Cmdlet 修改資源的資源群組名稱。

參數屬性

類型:String
預設值:None
支援萬用字元:False
不要顯示:False

參數集

BySubscriptionLevel
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:True
來自剩餘引數的值:False

-ResourceId

指定完整資源識別碼,包括訂用帳戶,如下列範例所示: /subscriptions/訂用帳戶識別碼/providers/Microsoft.Sql/servers/ContosoServer/databases/ContosoDatabase

參數屬性

類型:String
預設值:None
支援萬用字元:False
不要顯示:False
別名:身份識別碼

參數集

ByResourceId
Position:Named
必要:True
來自管線的值:False
來自管線按屬性名稱的值:True
來自剩餘引數的值:False

-ResourceName

指定資源的名稱。 例如,若要指定資料庫,請使用下列格式: ContosoServer/ContosoDatabase

參數屬性

類型:String
預設值:None
支援萬用字元:False
不要顯示:False
別名:名稱

參數集

BySubscriptionLevel
Position:Named
必要:True
來自管線的值:False
來自管線按屬性名稱的值:True
來自剩餘引數的值:False
ByTenantLevel
Position:Named
必要:True
來自管線的值:False
來自管線按屬性名稱的值:True
來自剩餘引數的值:False

-ResourceType

指定資源的類型。 例如,對於資料庫,資源類型如下: Microsoft.Sql/Servers/Databases

參數屬性

類型:String
預設值:None
支援萬用字元:False
不要顯示:False

參數集

BySubscriptionLevel
Position:Named
必要:True
來自管線的值:False
來自管線按屬性名稱的值:True
來自剩餘引數的值:False
ByTenantLevel
Position:Named
必要:True
來自管線的值:False
來自管線按屬性名稱的值:True
來自剩餘引數的值:False

-Sku

將資源的SKU物件指定為雜湊表。

參數屬性

類型:Hashtable
預設值:None
支援萬用字元:False
不要顯示:False
別名:SKU物件

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:True
來自剩餘引數的值:False

-Tag

雜湊表形式的鍵值對。 例如:@{key0=“value0”;key1=$null;key2=“值2”}

參數屬性

類型:Hashtable
預設值:None
支援萬用字元:False
不要顯示:False
別名:Tags

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:True
來自剩餘引數的值:False

-TenantLevel

表示此 Cmdlet 會在租用戶層級運作。

參數屬性

類型:SwitchParameter
預設值:None
支援萬用字元:False
不要顯示:False

參數集

ByTenantLevel
Position:Named
必要:True
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-UsePatchSemantics

表示此 Cmdlet 會使用 HTTP PATCH 來更新物件,而不是 HTTP PUT。

參數屬性

類型:SwitchParameter
預設值:None
支援萬用字元:False
不要顯示:False

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-WhatIf

顯示 Cmdlet 執行時會發生什麼事。 指令未執行。

參數屬性

類型:SwitchParameter
預設值:False
支援萬用字元:False
不要顯示:False
別名:威斯康辛

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

CommonParameters

此 cmdlet 支援常見參數:-Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction 和 -WarningVariable。 如需詳細資訊,請參閱 about_CommonParameters

輸入

PSResource

String

PSObject

Hashtable

輸出

PSObject