get All resources on azure powershell whose Tags start with (or include) a particular String - Azure...
up vote
0
down vote
favorite
I have almost 20 resources in azure, 4 of them have been given Tags @
{"Office1work"="work"}
{"Office2practice"="Practice"}
{"Office3practice"="Practice"}
{"Office4practice"="Practice"}
Now I want to get the resources whose Tag names start with the keyword "Office".
I know to get a resource by a TagName,for example "hello", I simply use the following command,
get-azureRmResource -TagName "Hello"
How can I use the -Tagname property of get-azurermresource to give me all resources whose tags are starting with the keyword "Office" ?
Or is there any other good method to get all resources whose Tags start with a particular string?
Thanks :)
azure powershell azure-powershell
add a comment |
up vote
0
down vote
favorite
I have almost 20 resources in azure, 4 of them have been given Tags @
{"Office1work"="work"}
{"Office2practice"="Practice"}
{"Office3practice"="Practice"}
{"Office4practice"="Practice"}
Now I want to get the resources whose Tag names start with the keyword "Office".
I know to get a resource by a TagName,for example "hello", I simply use the following command,
get-azureRmResource -TagName "Hello"
How can I use the -Tagname property of get-azurermresource to give me all resources whose tags are starting with the keyword "Office" ?
Or is there any other good method to get all resources whose Tags start with a particular string?
Thanks :)
azure powershell azure-powershell
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have almost 20 resources in azure, 4 of them have been given Tags @
{"Office1work"="work"}
{"Office2practice"="Practice"}
{"Office3practice"="Practice"}
{"Office4practice"="Practice"}
Now I want to get the resources whose Tag names start with the keyword "Office".
I know to get a resource by a TagName,for example "hello", I simply use the following command,
get-azureRmResource -TagName "Hello"
How can I use the -Tagname property of get-azurermresource to give me all resources whose tags are starting with the keyword "Office" ?
Or is there any other good method to get all resources whose Tags start with a particular string?
Thanks :)
azure powershell azure-powershell
I have almost 20 resources in azure, 4 of them have been given Tags @
{"Office1work"="work"}
{"Office2practice"="Practice"}
{"Office3practice"="Practice"}
{"Office4practice"="Practice"}
Now I want to get the resources whose Tag names start with the keyword "Office".
I know to get a resource by a TagName,for example "hello", I simply use the following command,
get-azureRmResource -TagName "Hello"
How can I use the -Tagname property of get-azurermresource to give me all resources whose tags are starting with the keyword "Office" ?
Or is there any other good method to get all resources whose Tags start with a particular string?
Thanks :)
azure powershell azure-powershell
azure powershell azure-powershell
edited Nov 11 at 6:58
4c74356b41
22.4k32049
22.4k32049
asked Nov 11 at 4:27
Asadullah Awan
52
52
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
You can use this code snippet:
$resources = Get-AzureRmResources
$resources.foreach{ if ($PSItem.tags.keys -match '^Office') { $PSItem } }
First you get all the resources in the subscription, then you filter out all the resource whose tags do not match the 'Office' "expression".
as @LotPings points out, it would probably make more sense to filter without saving to a temporary variable:
$resources = Get-AzureRmResources|Where-Object {$_.tags.keys -match "^Office"}
Also, I didnt notice you were asking for a starts with
filter, so you should use ^Office
as a more strict filter (if you need to).
2
Wouldn't$resources = Get-AzureRmResources|Where-Object {$_.tags.keys -match "^Office"}
be more efficient?
– LotPings
Nov 11 at 12:22
1
well, you could use^Office
as a filter, sure, i, honestly, didnt notice he saidstarts with
i thought itscontains
. as for the where filter, yeah, it probably would, but unless you have hundreds of thousands of object it wouldnt really matter (unless you have a reeeeeally crappy pc) @LotPings
– 4c74356b41
Nov 11 at 13:02
Thankyou. It works :)
– Asadullah Awan
Nov 14 at 16:20
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
You can use this code snippet:
$resources = Get-AzureRmResources
$resources.foreach{ if ($PSItem.tags.keys -match '^Office') { $PSItem } }
First you get all the resources in the subscription, then you filter out all the resource whose tags do not match the 'Office' "expression".
as @LotPings points out, it would probably make more sense to filter without saving to a temporary variable:
$resources = Get-AzureRmResources|Where-Object {$_.tags.keys -match "^Office"}
Also, I didnt notice you were asking for a starts with
filter, so you should use ^Office
as a more strict filter (if you need to).
2
Wouldn't$resources = Get-AzureRmResources|Where-Object {$_.tags.keys -match "^Office"}
be more efficient?
– LotPings
Nov 11 at 12:22
1
well, you could use^Office
as a filter, sure, i, honestly, didnt notice he saidstarts with
i thought itscontains
. as for the where filter, yeah, it probably would, but unless you have hundreds of thousands of object it wouldnt really matter (unless you have a reeeeeally crappy pc) @LotPings
– 4c74356b41
Nov 11 at 13:02
Thankyou. It works :)
– Asadullah Awan
Nov 14 at 16:20
add a comment |
up vote
2
down vote
accepted
You can use this code snippet:
$resources = Get-AzureRmResources
$resources.foreach{ if ($PSItem.tags.keys -match '^Office') { $PSItem } }
First you get all the resources in the subscription, then you filter out all the resource whose tags do not match the 'Office' "expression".
as @LotPings points out, it would probably make more sense to filter without saving to a temporary variable:
$resources = Get-AzureRmResources|Where-Object {$_.tags.keys -match "^Office"}
Also, I didnt notice you were asking for a starts with
filter, so you should use ^Office
as a more strict filter (if you need to).
2
Wouldn't$resources = Get-AzureRmResources|Where-Object {$_.tags.keys -match "^Office"}
be more efficient?
– LotPings
Nov 11 at 12:22
1
well, you could use^Office
as a filter, sure, i, honestly, didnt notice he saidstarts with
i thought itscontains
. as for the where filter, yeah, it probably would, but unless you have hundreds of thousands of object it wouldnt really matter (unless you have a reeeeeally crappy pc) @LotPings
– 4c74356b41
Nov 11 at 13:02
Thankyou. It works :)
– Asadullah Awan
Nov 14 at 16:20
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
You can use this code snippet:
$resources = Get-AzureRmResources
$resources.foreach{ if ($PSItem.tags.keys -match '^Office') { $PSItem } }
First you get all the resources in the subscription, then you filter out all the resource whose tags do not match the 'Office' "expression".
as @LotPings points out, it would probably make more sense to filter without saving to a temporary variable:
$resources = Get-AzureRmResources|Where-Object {$_.tags.keys -match "^Office"}
Also, I didnt notice you were asking for a starts with
filter, so you should use ^Office
as a more strict filter (if you need to).
You can use this code snippet:
$resources = Get-AzureRmResources
$resources.foreach{ if ($PSItem.tags.keys -match '^Office') { $PSItem } }
First you get all the resources in the subscription, then you filter out all the resource whose tags do not match the 'Office' "expression".
as @LotPings points out, it would probably make more sense to filter without saving to a temporary variable:
$resources = Get-AzureRmResources|Where-Object {$_.tags.keys -match "^Office"}
Also, I didnt notice you were asking for a starts with
filter, so you should use ^Office
as a more strict filter (if you need to).
edited Nov 11 at 13:08
answered Nov 11 at 6:58
4c74356b41
22.4k32049
22.4k32049
2
Wouldn't$resources = Get-AzureRmResources|Where-Object {$_.tags.keys -match "^Office"}
be more efficient?
– LotPings
Nov 11 at 12:22
1
well, you could use^Office
as a filter, sure, i, honestly, didnt notice he saidstarts with
i thought itscontains
. as for the where filter, yeah, it probably would, but unless you have hundreds of thousands of object it wouldnt really matter (unless you have a reeeeeally crappy pc) @LotPings
– 4c74356b41
Nov 11 at 13:02
Thankyou. It works :)
– Asadullah Awan
Nov 14 at 16:20
add a comment |
2
Wouldn't$resources = Get-AzureRmResources|Where-Object {$_.tags.keys -match "^Office"}
be more efficient?
– LotPings
Nov 11 at 12:22
1
well, you could use^Office
as a filter, sure, i, honestly, didnt notice he saidstarts with
i thought itscontains
. as for the where filter, yeah, it probably would, but unless you have hundreds of thousands of object it wouldnt really matter (unless you have a reeeeeally crappy pc) @LotPings
– 4c74356b41
Nov 11 at 13:02
Thankyou. It works :)
– Asadullah Awan
Nov 14 at 16:20
2
2
Wouldn't
$resources = Get-AzureRmResources|Where-Object {$_.tags.keys -match "^Office"}
be more efficient?– LotPings
Nov 11 at 12:22
Wouldn't
$resources = Get-AzureRmResources|Where-Object {$_.tags.keys -match "^Office"}
be more efficient?– LotPings
Nov 11 at 12:22
1
1
well, you could use
^Office
as a filter, sure, i, honestly, didnt notice he said starts with
i thought its contains
. as for the where filter, yeah, it probably would, but unless you have hundreds of thousands of object it wouldnt really matter (unless you have a reeeeeally crappy pc) @LotPings– 4c74356b41
Nov 11 at 13:02
well, you could use
^Office
as a filter, sure, i, honestly, didnt notice he said starts with
i thought its contains
. as for the where filter, yeah, it probably would, but unless you have hundreds of thousands of object it wouldnt really matter (unless you have a reeeeeally crappy pc) @LotPings– 4c74356b41
Nov 11 at 13:02
Thankyou. It works :)
– Asadullah Awan
Nov 14 at 16:20
Thankyou. It works :)
– Asadullah Awan
Nov 14 at 16:20
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53245840%2fget-all-resources-on-azure-powershell-whose-tags-start-with-or-include-a-parti%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown