SID to username

$sid = Read-Host “What is the SID?”
$objSID = New-Object System.Security.Principal.SecurityIdentifier `
$sid
$objUser = $objSID.Translate( [System.Security.Principal.NTAccount])
write-host $objUser.Value

Advertisements

Powershell HTML Table Color

# Create header for HTML Report

$Head = “<style>”
$Head +=”BODY{font-family:Calibri,sans-serif; font-size: small;}”
$Head +=”TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse; width: 98%;}”
#$Head +=”TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:#ff0000;color:white;padding: 5px; font-weight: bold;text-align:left;}”
#$Head +=”TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:#ff0000; padding: 2px;}”
$Head +=”</style>”
$values = 1,2,3,4,5

$thold = 3

$output += “<table><th style = ‘text-align:left;’>Values</th>”

foreach ( $i in $values)
{

if ($i -le 3)

{

$output += “<tr><td style = ‘border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:#ff0000; padding: 5px;’>Lower</td></tr>”

}
else
{

$output += “<tr><td style = ‘border-width: 1px;padding: 0px;border-style: solid;border-color: black;padding: 5px;’>Upper</td></tr>”

}
}

$output += “</table>”

# Close the Body of the Report
$output += “</body>”

# Send Final Report by email…

Write-Host “Emailing Report”
$SMTPServer =””
$Body = ConvertTo-HTML -head $Head -body “$output”
$SmtpClient = New-Object Net.Mail.SmtpClient($smtpServer);
$mailmessage = New-Object system.net.mail.mailmessage
$mailmessage.from = “”
#$mailmessage.To.add(“”)
#$mailmessage.To.add(“”)
$mailmessage.to.add(“”)
# Want more recipient’s? Just add a new line
#$mailmessage.To.add(“anotherrecipient@company.com”)
$mailmessage.Subject = “Disk Space Check Report”
$MailMessage.IsBodyHtml = $true
$mailmessage.Body = $Body
$smtpclient.Send($mailmessage)