{"id":657,"date":"2023-05-26T08:56:00","date_gmt":"2023-05-26T08:56:00","guid":{"rendered":"http:\/\/draith.com\/?p=657"},"modified":"2024-02-13T03:12:40","modified_gmt":"2024-02-13T03:12:40","slug":"azure-inventory-management-with-powershell","status":"publish","type":"post","link":"https:\/\/draith.com\/?p=657","title":{"rendered":"Azure Inventory Management with PowerShell"},"content":{"rendered":"\n<p>Listen &#8211; creating resources in Azure with PowerShell is easy &#8211; but actually knows what you have deployed is something else.  Let&#8217;s dive into the steps to harness the power of PowerShell for a streamlined Azure inventory process.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Prerequisites<\/h4>\n\n\n\n<p>Before we embark on this journey, ensure you have:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>An Azure account with necessary access permissions.<\/li>\n\n\n\n<li>PowerShell and the Azure PowerShell module ready on your machine.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">Configuring PowerShell for Azure<\/h4>\n\n\n\n<p><strong>Connecting to Azure<\/strong> is the first step. Open your PowerShell window and enter these commands.  This should let you set your context from the Gridview.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;powershell&quot;,&quot;mime&quot;:&quot;application\/x-powershell&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;PowerShell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;powershell&quot;}\"># Connect to Azure with interactive login\nConnect-AzAccount\n\n# List subscriptions and select one interactively\nGet-AzSubscription | Out-GridView -PassThru | Set-AzContext\n\n<\/pre><\/div>\n\n\n\n<p>Lets go ahead and start to look at your resources:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;powershell&quot;,&quot;mime&quot;:&quot;application\/x-powershell&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;PowerShell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;powershell&quot;}\"># List all resources and export to CSV\nGet-AzResource | Select-Object ResourceType, Name, Location | Export-Csv -Path .\/AllResources.csv -NoTypeInformation\n\n# VM Inventory: List VMs and export their details\nGet-AzVM | Select-Object Name, Location, HardwareProfile.VmSize | Export-Csv -Path .\/VMInventory.csv -NoTypeInformation\n\n# Storage Accounts: List accounts and export their details\nGet-AzStorageAccount | Select-Object StorageAccountName, Location, SkuName | Export-Csv -Path .\/StorageAccounts.csv -NoTypeInformation\n\n# Network Resources: List VNets and export their details\nGet-AzVirtualNetwork | Select-Object Name, Location, AddressSpace | Export-Csv -Path .\/VNetInventory.csv -NoTypeInformation\n<\/pre><\/div>\n\n\n\n<p>In the scripts above, each command not only fetches the necessary details but also exports them to a CSV file for easy access and reporting.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Advanced Techniques<\/h4>\n\n\n\n<p>Organizing and managing your resources effectively can further be achieved by using tags.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;powershell&quot;,&quot;mime&quot;:&quot;application\/x-powershell&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;PowerShell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;powershell&quot;}\"># Organizing resources with Tags: Filter by tag and export\nGet-AzResource -Tag @{ Department=&quot;Finance&quot;} | Select-Object Name, ResourceType | Export-Csv -Path .\/FinanceResources.csv -NoTypeInformation\n<\/pre><\/div>\n\n\n\n<p>For more insights and advanced techniques, visit the <a href=\"https:\/\/docs.microsoft.com\/powershell\/azure\/?view=azps-5.1.0&amp;wt.mc_id=AZ-MVP-5002833\">Azure PowerShell documentation<\/a>. Here&#8217;s to efficient management of your Azure resources. Happy scripting!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Listen &#8211; creating resources in Azure with PowerShell is easy &#8211; but actually knows what you have deployed is something else. Let&#8217;s dive into the steps to harness the power of PowerShell for a streamlined Azure inventory process. Prerequisites Before we embark on this journey, ensure you have: Configuring PowerShell for Azure Connecting to Azure &hellip; <a href=\"https:\/\/draith.com\/?p=657\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Azure Inventory Management with PowerShell&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[4,16],"class_list":["post-657","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-azure","tag-powershell"],"_links":{"self":[{"href":"https:\/\/draith.com\/index.php?rest_route=\/wp\/v2\/posts\/657","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/draith.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/draith.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/draith.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/draith.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=657"}],"version-history":[{"count":1,"href":"https:\/\/draith.com\/index.php?rest_route=\/wp\/v2\/posts\/657\/revisions"}],"predecessor-version":[{"id":658,"href":"https:\/\/draith.com\/index.php?rest_route=\/wp\/v2\/posts\/657\/revisions\/658"}],"wp:attachment":[{"href":"https:\/\/draith.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=657"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/draith.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=657"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/draith.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=657"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}