powershell 使用
With strong organization and design for our development teams, cloud infrastructure and security considerations, we’ll now extract Azure cost information that we can share with our organization. In addition, we will see that we can retain this information if needed to track growth (or reduction) in costs. This step is important as it will allow our teams to have an insight into their development and it will also be another audit we can use on the security side to catch unusual growth (or significant reductions) in resource costs that may be the result of an attacker. Our ultimate goal with tracking these costs and sharing them with teams is to improve our development and possibly re-organize it as needed, giving us the ability to further reduce our spending.
凭借针对开发团队的强大组织和设计,云基础架构以及安全方面的考虑,我们现在将提取可与组织共享的Azure成本信息。 此外,如果需要跟踪成本的增长(或降低),我们将保留这些信息。 这一步很重要,因为这将使我们的团队能够深入了解他们的发展,这还将是我们可以在安全方面使用的另一项审核,以捕获资源成本的异常增长(或显着减少),这可能是由于攻击者。 我们跟踪这些成本并与团队共享的最终目标是改善我们的开发,并可能根据需要对其进行重组,从而使我们能够进一步减少支出。
By querying Azure cost information, we can share with development and improve to reduce costs.
通过查询Azure成本信息,我们可以与开发共享并进行改进以降低成本。
使用PowerShell获取成本信息的基本查询 (Basic Queries to Get Costs Information with PowerShell)
We’ll begin querying cost information by logging into AzureRm. To confirm the version that we’re using as well, we’ll import the AzureRm module and check for the version. These scripts were executed with version 6.13.1.
我们将通过登录AzureRm开始查询成本信息。 为了确认我们也正在使用的版本,我们将导入AzureRm模块并检查版本。 这些脚本在6.13.1版中执行。
Login-AzureRmAccount | Out-Null
Import-Module AzureRm
Get-Module | Where-Object {$_.Name -eq "AzureRm" } | Select-Object Name, Version
PowerShell will output the version and these scripts may require a higher version if below the one shown.
PowerShell将输出该版本,如果这些脚本低于所显示的版本,则这些脚本可能需要更高的版本。
In the below PowerShell call, we get the full Azure cost information of our logged in account. This will return everything for our Azure profile, which we’ll be filtering for details later. It’s worth seeing a view of the information that we’ll have access to and in some cases, we may want to see all the Azure information for a profile since some environments may demarcate assets by profile instead of other methods, such as subscriptions, resource groups, etc. We can wrap the PowerShell call in parenthesis and get spe