【问题标题】:Convert To HTML Azure Powershell "Get-VM"转换为 HTML Azure Powershell "Get-VM"
【发布时间】:2015-10-26 10:59:14
【问题描述】:

我遇到了覆盖 Azure Powershell 脚本中的参数的问题。

在我的 $VM 中,我有几个 $VM(虚拟机),当我尝试将它们转换为具有表格格式的 HTML 文件(列:名称、IP 地址、PowerState)时,我只能得到最终的 $VM,因为我的Foreach 和 IF 循环会覆盖所有其他 VM。

我也很想获得一些关于更好和正确代码编写的提示和反馈。

这是我的完整代码:

$style = "<style>"
$style += "BODY{background-color: #6D7B8D;}"
$style += "TABLE{border-width: 1px; border-style: solid; border-color: black; border-collapse: collapse; margin: 0px auto}"
$style += "TH{border-width: 1px; padding: 0px; border-style: solid; border-color: black; background-color:#3300CC}"
$style += "TD{border-width: 1px; padding: 0px; border-style: solid; border-color: black; background-color:#659EC7}"
$style += "</style>"
$title = "<H2 align=center>IIS Pool Status</H2>"
$destination = "C:\Users\<User>\Desktop\Test.htm"

$VMs = Get-AzureVM -ServiceName "<CloudService>"

foreach ($VM in $VMs)
{
    #Check if the current VM has an Endpoints with Port 80(HTTP) or Port 443(HTTPS)
    $HTTPEndpoint = Get-AzureEndpoint -VM $VM | Where { $_.Port -in 80, 443}
    if ($HTTPEndpoint)
    {
        '1', '2' | 
        Select @{label='VM Name';expression={$VM.Name}}, @{label='IP Address';expression={$VM.IPAddress}}, @{label='Power State';expression={$VM.PowerState}} | 
        ConvertTo-HTML -head $style -body $title | 
        Out-File $destination 
    }
}
Invoke-Expression $destination

【问题讨论】:

    标签: html css powershell azure


    【解决方案1】:

    Out-File 会覆盖文件,除非您使用 -Append 这样循环的最终执行将确定内容。

    HtH, 加雷斯

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-21
      相关资源
      最近更新 更多