Powershell output html email help

Hi,

Im a noobie with Powershell, please go easy on me. The help desk or systems team forgets to move the newly created workstation or servers from the COMPUTERS OU into their respective OUs.

The goal is to create a powershell script that pulls a list of computer objects, along with their Operating System. Also, For computer objects running a server operating system (i.e. Windows Server 2008/2012, etc), email that list to the systems team and non server machines to the helpdesk email.

I only found a way to output these results via csv, but not html or export the html to email. Any help master powershell writers? e-books, links. Thanks for reading.

Get-ADComputer -Filter {(OperatingSystem -notlike “Windows XP Professional”) -and (OperatingSystem -notlike “Windows 7”) -and (OperatingSystem -notlike “Windows 10 Pro”) -and (OperatingSystem -notlike “Windows 10 Enterprise”) -and (OperatingSystem -notlike “MAC”)} -SearchBase “CN=null,DC=null,DC=null” -Properties Name,OperatingSystem,Description | Select Name,OperatingSystem,Description |Sort-Object -Property OperatingSystem -Descending | Export-Csv C:\Servers_OU_Info.csv -NoTypeInformation -Encoding UTF8

Since you are new to PS. It’s really important that you get some edification to solidify your basics.

Visit Microsfot Virtual Academy, Microsoft MSDN Channel9 and YouTube, search for Beginning PowerShell, or just PowerShell to get to the video training / education.

As for your post, please use the code formatting tools so that it’s easier of folks willing help you.

Also, don’t make a habit of trying to squeeze everything in to one line. One liners are good for adhoc stuff, but not for shared scripts or PS apps. It makes the hard to read, debug, support and maintain.

Be sure to use resources that already exist …

'powershellgallery.com'
... before struggling to write from scratch. Know that Windows Server 2012 using the ADAC will write PS code for you that you can tweak as well.

You say you want HTML< but you are not using the HTML cmdlets.

Get-Command -Name '*html*' | Format-Table -AutoSize

If all you want to work on are servers, then only ask for them…

Get-ADComputer -Filter {OperatingSystem -Like ‘Server’}

If all you want is clients then…

Get-ADComputer -Filter {OperatingSystem -NotLike ‘Server’}

So, something like this…

Get-ADComputer -Filter "OperatingSystem -Notlike '*Server*'" -Properties Name,OperatingSystem,Description | 
Select Name,OperatingSystem,Description | 
Sort-Object -Property OperatingSystem -Descending | 
ConvertTo-Html | Out-File 'c:\temp\Servers_OU_Info.html'
Invoke-item 'c:\temp\Servers_OU_Info.html'

Then just use Send-MailMessage to send this to whomever.

For whatever reasons, my post got locked and I cannot update / modify / cleanup my post, so there’s that.

I am not sure why that footer was added. I did not do that.

But I can edit this one as needed. Hummmm….

Thank you!! I wasnt sure where to begin. Thanks again for all your help and guidance.

@Postanote, Myself faced same issue(reply came along with footer and not able to edit it). Just updated it in Web Site Feedback & Assistance forum.