Hello,
im new here and im completly newbie in powershell scripting, im trying to write my first powershell script.
The script is supposed to restore virtual machines from a copy, change their parameters, run them and test them in a simple way, and more precisely check whether the ports defined in the csv file are open and the services are running. And it works fine, but I would like the script to additionally create a nice html report based on the collected data. Below I present a part of the script that is responsible for testing virtual machines, an example input csv file and how less the output html file should look like.
Please guide me on how this can be done.
input csv file
ServerName;SourceID;vCPU;vRAM;console;ports;services
ServerX;1;2;4096;PS;1433 445;DHCP SENS
ServerY;2;2;4096;PS;1433 80 445;BITS DHCP SENS
script
foreach ($line in $lines)
{
if($line.console -eq 'PS')
{
$cred = Get-StoredCredential -Target VM
foreach($ports in $line.ports)
{
$ports = $line.ports -split '\s+'
foreach ($port in $ports)
{
Invoke-Command -VMName $line.ServerName -Credential $cred { Param($s,$p) Test-NetConnection -ComputerName $s -port $p } -ArgumentList ($line.ServerName,$port) | Select-Object -Property Remoteport,TcpTestSucceeded
}
}
foreach($service in $line.services )
{
$services = $line.services -split '\s+'
foreach ($service in $services)
{
Invoke-Command -VMName $line.ServerName -Credential $cred { Param($Service) Get-Service -Name $Service } -ArgumentList ($Service) | Select-Object -Property Name,Status
}
}
}
elseif($line.console -eq 'SSH')
{
}
}
example html report