Get-AzResource
語法
ByTagNameValueParameterSet (預設值)
Get-AzResource
[-Name <String>]
[-ResourceType <String>]
[-ODataQuery <String>]
[-ResourceGroupName <String>]
[-TagName <String>]
[-TagValue <String>]
[-ExpandProperties]
[-ApiVersion <String>]
[-Pre]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
ByResourceId
Get-AzResource
-ResourceId <String>
[-ODataQuery <String>]
[-ExpandProperties]
[-ApiVersion <String>]
[-Pre]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
ByTagObjectParameterSet
Get-AzResource
-Tag <Hashtable>
[-Name <String>]
[-ResourceType <String>]
[-ODataQuery <String>]
[-ResourceGroupName <String>]
[-ExpandProperties]
[-ApiVersion <String>]
[-Pre]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
Description
Get-AzResource Cmdlet 會取得 Azure 資源。
範例
範例 1:取得目前訂用帳戶中的所有資源
Get-AzResource | Format-Table
Name ResourceGroupName ResourceType Location
---- ----------------- ------------ --------
testVM testRG Microsoft.Compute/virtualMachines westus
disk testRG Microsoft.Compute/disks westus
nic testRG Microsoft.Network/networkInterfaces westus
nsg testRG Microsoft.Network/networkSecurityGroups westus
ip testRG Microsoft.Network/publicIPAddresses westus
vnet testRG Microsoft.Network/virtualNetworks westus
testKV otherRG Microsoft.KeyVault/vaults eastus
storage otherResourceGroup Microsoft.Storage/storageAccounts eastus
testVM2 otherResourceGroup Microsoft.Compute/virtualMachines eastus
此命令會取得目前訂用帳戶中的所有資源。
範例 2:取得資源群組中的所有資源
Get-AzResource -ResourceGroupName testRG | Format-Table
Name ResourceGroupName ResourceType Location
---- ----------------- ------------ --------
testVM testRG Microsoft.Compute/virtualMachines westus
disk testRG Microsoft.Compute/disks westus
nic testRG Microsoft.Network/networkInterfaces westus
nsg testRG Microsoft.Network/networkSecurityGroups westus
ip testRG Microsoft.Network/publicIPAddresses westus
vnet testRG Microsoft.Network/virtualNetworks westus
此指令會取得資源群組 “testRG” 中的所有資源。
範例 3:取得其資源群組符合所提供萬用字元的所有資源
Get-AzResource -ResourceGroupName other* | Format-Table
Name ResourceGroupName ResourceType Location
---- ----------------- ------------ --------
testKV otherRG Microsoft.KeyVault/vaults eastus
storage otherResourceGroup Microsoft.Storage/storageAccounts eastus
testVM2 otherResourceGroup Microsoft.Compute/virtualMachines eastus
此命令取得所有資源,其資源群組與「其他」存在。
範例 4:取得具有指定名稱的所有資源
Get-AzResource -Name testVM | Format-List
Name : testVM
ResourceGroupName : testRG
ResourceType : Microsoft.Compute/virtualMachines
Location : westus
ResourceId : /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/testRG/providers/Microsoft.Compute/virtualMachines/testVM
Tags :
Name Value
====== ========
Dept IT
Year 2002
Status Approved
此命令會取得資源名稱為「testVM」的所有資源。
範例 5:取得名稱符合所提供萬用字元的所有資源
Get-AzResource -Name test* | Format-Table
Name ResourceGroupName ResourceType Location
---- ----------------- ------------ --------
testVM testRG Microsoft.Compute/virtualMachines westus
testKV otherRG Microsoft.KeyVault/vaults eastus
testVM2 otherResourceGroup Microsoft.Compute/virtualMachines eastus
此指令會取得資源名稱以 “test” 開頭的所有資源。
範例 6:取得指定資源類型的所有資源
Get-AzResource -ResourceType Microsoft.Compute/virtualMachines | Format-Table
Name ResourceGroupName ResourceType Location
---- ----------------- ------------ --------
testVM testRG Microsoft.Compute/virtualMachines westus
testVM2 otherResourceGroup Microsoft.Compute/virtualMachines eastus
此命令會取得目前訂用帳戶中屬於虛擬機器的所有資源。
範例 7:依資源識別碼取得資源
Get-AzResource -ResourceId /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/testRG/providers/Microsoft.Compute/virtualMachines/testVM
Name : testVM
ResourceGroupName : testRG
ResourceType : Microsoft.Compute/virtualMachines
Location : westus
ResourceId : /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/testRG/providers/Microsoft.Compute/virtualMachines/testVM
Tags :
Name Value
====== ========
Dept IT
Year 2002
Status Approved
此命令會取得具有所提供資源識別碼的資源,這是資源群組 “testRG” 中名為 “testVM” 的虛擬機器。
範例 8:取得具有展開屬性的資源
Get-AzResource -Name testVM -ResourceGroupName testRG -ExpandProperties
此命令會取得資源群組 “testRG” 中名為 “testVM” 的資源,並展開屬性以包含其他詳細數據,例如 CreatedTime、ChangedTime 和其他資源中繼資料。
參數
-ApiVersion
Get-AzResource Cmdlet 會取得 Azure 資源。
參數屬性
類型: String
預設值: None
支援萬用字元: False
不要顯示: False
參數集
(All)
Position: Named
必要: False
來自管線的值: False
來自管線按屬性名稱的值: False
來自剩餘引數的值: False
-DefaultProfile
用來與 Azure 通訊的認證、帳戶、租用戶和訂用帳戶
參數屬性
參數集
(All)
Position: Named
必要: False
來自管線的值: False
來自管線按屬性名稱的值: False
來自剩餘引數的值: False
-ExpandProperties
指定時,會展開資源的內容。
參數屬性
參數集
(All)
Position: Named
必要: False
來自管線的值: False
來自管線按屬性名稱的值: False
來自剩餘引數的值: False
-Name
要擷取的資源名稱。 此參數支援字串開頭和/或結尾的萬用字元。
參數屬性
類型: String
預設值: None
支援萬用字元: True
不要顯示: False
別名: 資源名稱
參數集
ByTagNameValueParameterSet
Position: Named
必要: False
來自管線的值: False
來自管線按屬性名稱的值: False
來自剩餘引數的值: False
ByTagObjectParameterSet
Position: Named
必要: False
來自管線的值: False
來自管線按屬性名稱的值: False
來自剩餘引數的值: False
-ODataQuery
Get-AzResource Cmdlet 會取得 Azure 資源。
參數屬性
類型: String
預設值: None
支援萬用字元: False
不要顯示: False
參數集
(All)
Position: Named
必要: False
來自管線的值: False
來自管線按屬性名稱的值: False
來自剩餘引數的值: False
-Pre
Get-AzResource Cmdlet 會取得 Azure 資源。
參數屬性
參數集
(All)
Position: Named
必要: False
來自管線的值: False
來自管線按屬性名稱的值: False
來自剩餘引數的值: False
-ResourceGroupName
擷取的資源所屬的資源群組。 此參數支援字串開頭和/或結尾的萬用字元。
參數屬性
類型: String
預設值: None
支援萬用字元: True
不要顯示: False
參數集
ByTagNameValueParameterSet
Position: Named
必要: False
來自管線的值: False
來自管線按屬性名稱的值: False
來自剩餘引數的值: False
ByTagObjectParameterSet
Position: Named
必要: False
來自管線的值: False
來自管線按屬性名稱的值: False
來自剩餘引數的值: False
-ResourceId
指定完整資源識別碼,如下列範例所示 /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/providers/Microsoft.Compute/virtualMachines
參數屬性
類型: String
預設值: None
支援萬用字元: False
不要顯示: False
別名: 身份識別碼
參數集
ByResourceId
Position: Named
必要: True
來自管線的值: False
來自管線按屬性名稱的值: True
來自剩餘引數的值: False
-ResourceType
要擷取之資源的資源類型。 例如,Microsoft.Compute/virtualMachines
參數屬性
類型: String
預設值: None
支援萬用字元: False
不要顯示: False
參數集
ByTagNameValueParameterSet
Position: Named
必要: False
來自管線的值: False
來自管線按屬性名稱的值: False
來自剩餘引數的值: False
ByTagObjectParameterSet
Position: Named
必要: False
來自管線的值: False
來自管線按屬性名稱的值: False
來自剩餘引數的值: False
-Tag
取得具有指定 Azure 標籤的資源。 輸入具有 Name 索引鍵或 Name 和 Value 索引鍵的雜湊表。 不支援萬用字元。「標籤」是可套用至資源和資源群組的名稱值組。 使用標籤來分類您的資源,例如依部門或成本中心,或追蹤有關資源的附註或註解。 若要將標籤新增至資源,請使用 New-AzResource 或 Set-AzResource Cmdlet 的 Tag 參數。 若要建立預先定義的標籤,請使用 New-AzTag Cmdlet。 如需 Windows PowerShell 中雜湊表的說明,請執行 'Get-Help about_Hashtables'。
參數屬性
類型: Hashtable
預設值: None
支援萬用字元: False
不要顯示: False
參數集
ByTagObjectParameterSet
Position: Named
必要: True
來自管線的值: False
來自管線按屬性名稱的值: False
來自剩餘引數的值: False
-TagName
要擷取之資源標籤中的索引鍵。
參數屬性
類型: String
預設值: None
支援萬用字元: False
不要顯示: False
參數集
ByTagNameValueParameterSet
Position: Named
必要: False
來自管線的值: False
來自管線按屬性名稱的值: False
來自剩餘引數的值: False
-TagValue
要擷取之資源標籤中的值。
參數屬性
類型: String
預設值: None
支援萬用字元: False
不要顯示: False
參數集
ByTagNameValueParameterSet
Position: Named
必要: False
來自管線的值: False
來自管線按屬性名稱的值: False
來自剩餘引數的值: False
CommonParameters
此 cmdlet 支援常見參數:-Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction 和 -WarningVariable。 如需詳細資訊,請參閱 about_CommonParameters 。
輸出