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 :)










share|improve this question




























    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 :)










    share|improve this question


























      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 :)










      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 6:58









      4c74356b41

      22.4k32049




      22.4k32049










      asked Nov 11 at 4:27









      Asadullah Awan

      52




      52
























          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).






          share|improve this answer



















          • 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 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











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          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

























          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).






          share|improve this answer



















          • 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 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















          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).






          share|improve this answer



















          • 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 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













          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).






          share|improve this answer














          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).







          share|improve this answer














          share|improve this answer



          share|improve this answer








          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 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














          • 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 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








          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


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Full-time equivalent

          さくらももこ

          13 indicted, 8 arrested in Calif. drug cartel investigation