I have an problem of overriding parameters in my Azure Powershell Script.
Into my $VMs I have a few $VM(Virtual Machines) and when I try to convert them to HTML file with table format(Columns of: Name, IP address, PowerState) I only get the final $VM because my Foreach and IF loops override all other VMs.
I would also love to some tips and feedback about better and correct code writing.
This is my Full Code:
$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
Out-File overwrites the file, unless you use -Append so the final execution of the loop will determine the content.
HtH, Gareth
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.