【问题标题】:How can I properly format the output generated by combining two Get-Azure cmdlets?如何正确格式化通过组合两个 Get-Azure cmdlet 生成的输出?
【发布时间】:2015-08-07 20:32:02
【问题描述】:

我从 (Get-AzureVM) 获取 Name 属性,从 (Get-AzureSubscription -Current) 获取 SubscriptionName 属性,并将它们放入文本文件中。我试图让每个虚拟机都在自己的线上,但由于某种原因,我最终得到了 {vm1,vm2,vm3,vm4...}。当有超过 4 个对象时,它不会换行并执行“...”。我怎样才能让它显示这样的输出?

vm1 订阅1

vm2 订阅1

vm3 订阅 1

到目前为止,这是我的脚本:

cd C:\PowerShellThings
$machine = Get-AzureVM
$subscription = Get-AzureSubscription -Current
$props = @{
VMHostName  = $machine.Name
Subscription  = $subscription.SubscriptionName
    }
New-Object PSObject -Property $props | select VMHostName,Subscription | ft -HideTableHeaders -Wrap | Out-File VM-Subs2.txt -Append -NoClobber

【问题讨论】:

    标签: powershell azure


    【解决方案1】:

    不要用 PS 对象过度复杂化它,尝试这些方法。

    $VMs = Get-AzureVM
    $subscription = Get-AzureSubscription -Current
    ForEach ($VM in $VMs) {
       "$($VM.Name): $($Subscription.SubscriptionName)" | out-file .\output.txt -append
    }
    

    【讨论】:

    • 写出来的时候,我什至没有想过做一个 for 循环。很好,谢谢!
    猜你喜欢
    • 1970-01-01
    • 2014-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-23
    • 2016-01-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多