[英]Convert To HTML Azure Powershell “Get-VM”
我在Azure Powershell腳本中存在覆蓋參數的問題。
在我的$ VM中,我有一些$ VM(虛擬機),當我嘗試將它們轉換為具有表格式(名稱,IP地址,PowerState的列)的HTML文件時,我只能得到最終的$ 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
除非使用-Append,否則Out-File會覆蓋文件,因此循環的最終執行將確定內容。
HtH Gareth
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.