$servers = @("DDC01","DMMS01","DMMS02","DDC02","FakeServer","Tempvm4") #Listing all servers in " " quotes. Take input from a file if server count is large.
$date = (Get-Date -Format "dd_MM_yyyy")+".html"
$outputHTML = "<HTML>
<Body><Table border='2'>
<h2> SMB1 Status Report Started at $(Get-Date)</h2>
<TR><Td>Name</Td><Td>Operating System</Td><Td>DistinguishedName</Td>s
<Td>SMB1Status</Td></Tr>"
foreach($server in $servers)
{
$server = $server.trim()
$error.Clear()
try{
$command1 = Get-ADComputer -Identity $server -Properties OperatingSystem,DistinguishedName | Select-Object -Property Name,OperatingSystem,DistinguishedName -ErrorAction Stop
}
catch{
$command1 = "Error"
}
try{
$command2 = Invoke-Command -ComputerName $server -ScriptBlock{(Get-WindowsOptionalFeature -Online -FeatureName SMB1Protocol).State} -ErrorAction Stop
}
catch{
$command2 = "Error"
}
if(($command1 -eq "Error"))
{
$outputHTML += "<TR style='background-color:orange'>"
$outputHTML += "
<TD>$($server)</TD>
<TD>$("NA")</TD>
<TD>$("NA")</TD>
<TD>$("Unable to fetch, please check manually")</TD>
</TR>"
}
elseif(($command2 -eq "Error"))
{
$outputHTML += "<TR style='background-color:orange'>"
$outputHTML += "
<TD>$($server)</TD>
<TD>$($command1.OperatingSystem)</TD>
<TD>$($command1.DistinguishedName)</TD>
<TD>$("Unable to fetch, please check manually")</TD>
</TR>"
}
else
{
$command3 = $command1 | Select-Object -Property Name,OperatingSystem,DistinguishedName,@{n="SMB1Status";e={$command2}}
if(($($command3.SMB1Status.Value) -eq "Disabled"))
{
$outputHTML += "<TR style='background-color:red'>"
}
else
{
$outputHTML += "<TR>"
}
$outputHTML += "
<TD>$($command3.Name)</TD>
<TD>$($command3.OperatingSystem)</TD>
<TD>$($command3.DistinguishedName)</TD>
<TD>$($command3.SMB1Status.Value)</TD>
</TR>"
}
}
$outputHTML += "</Table></Body></Html>"
$outputHTML += "<h2> SMB1 Status Report Ended at $(Get-Date) </h2>"
$outputHTML | Out-File ./SMB1Status_$date
Sample Output
No comments:
Post a Comment