Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
ITEngineer
Posts: 210 Joined: Wed Oct 12, 2011 10:52 am
Post
by ITEngineer » Tue Sep 15, 2020 6:01 am
Hi All,
The below contents are from the $Results variable I got from my larger script.
Code: Select all
MachineName : PRDDC03.domain.com
Id : 4624
TimeCreated : 4/09/2020 12:12:12 PM
Account : DOMAIN\SVC-SQL
LogonType : 3
LogonTypeString : Network
WorkstationName :
SourceIP : 172.16.32.99
SourceName :
MachineName : PRDDC02-VM.domain.com
Id : 4624
TimeCreated : 3/09/2020 10:21:27 AM
Account : DOMAIN\SVC-prtg
LogonType : 3
LogonTypeString : Network
WorkstationName :
SourceIP : 10.10.13.97
SourceName :
MachineName : AD01.domain.com
Id : 4624
TimeCreated : 3/09/2020 9:15:27 AM
Account : DOMAIN\Admin.local
LogonType : 3
LogonTypeString : Network
WorkstationName :
SourceIP : 192.168.32.58
SourceName :
MachineName : SVRDC33.domain.com
Id : 4624
TimeCreated : 28/08/2020 4:51:13 PM
Account : DOMAIN\GLobal.Admin
LogonType : 3
LogonTypeString : Network
WorkstationName :
SourceIP : 192.168.13.66
SourceName :
MachineName : AD01.domain.com
Id : 4624
TimeCreated : 28/08/2020 11:54:27 AM
Account : DOMAIN\svc.avs
LogonType : 3
LogonTypeString : Network
WorkstationName :
SourceIP : 192.168.1.66
SourceName :
MachineName : AD02.domain.com
Id : 4624
TimeCreated : 26/08/2020 9:29:53 AM
Account : DOMAIN\testing1
LogonType : 3
LogonTypeString : Network
WorkstationName :
SourceIP : 192.168.13.77
SourceName :
How can I get the display for the Unique IP address like the below format:
Code: Select all
192.168.1.66 - LAPTOP66
192.168.32.58 - No-DNS
10.10.13.97 - SVRPRTG01
172.16.32.99 - NoDNS
The below code is not producing the output I wanted:
Write-Host "Unique IP addresses are as follows"**
Write-Host "$(($Results | Select-Object -ExpandProperty SourceIP -Unique)) - Resolve-DnsName -Type A -Name (($Results | Select-Object -ExpandProperty SourceIP -Unique))"
Hence I need your help.
I want to convert the
$Results variable as HTML so I can attach it in Send-MailMessage body
Code: Select all
$params = @{
SmtpServer = 'SMTP.DOMAIN.com'
From = "$env:COMPUTERNAME@$env:userdnsdomain"
To = 'boss@IT.com'
Subject = "The report email as at $(Get-Date -Format 'F')"
Body = $Results
BodyAsHtml = $true
}
Send-MailMessage @params
Thank you in advance.
/* IT Engineer */
jvierra
Posts: 14676 Joined: Tue May 22, 2007 9:57 am
Answers: 6
Has voted: 1 time
Been upvoted: 5 times
Contact:
Post
by jvierra » Tue Sep 15, 2020 3:43 pm
To send an object collection as HTML you would use "ConvertTo-Html" .
$body = $results | ConvertTo-Html | Out-String
ITEngineer
Posts: 210 Joined: Wed Oct 12, 2011 10:52 am
Post
by ITEngineer » Tue Sep 15, 2020 4:40 pm
jvierra wrote: ↑ Tue Sep 15, 2020 3:43 pm
To send an object collection as HTML you would use "ConvertTo-Html" .
$body = $results | ConvertTo-Html | Out-String
Hi Mr. Vierra,
Yes, that works partially on the email body to show the
$Results content.
However, how to allow the output to be like:
Unique IP address:
Code: Select all
192.168.1.66 - LAPTOP66
192.168.32.58 - No-DNS
10.10.13.97 - SVRPRTG01
172.16.32.99 - NoDNS
No need to be in the HTML table.
/* IT Engineer */
jvierra
Posts: 14676 Joined: Tue May 22, 2007 9:57 am
Answers: 6
Has voted: 1 time
Been upvoted: 5 times
Contact:
Post
by jvierra » Tue Sep 15, 2020 5:43 pm
Don't make the body HTML and the line breaks will persist.
ITEngineer
Posts: 210 Joined: Wed Oct 12, 2011 10:52 am
Post
by ITEngineer » Tue Sep 15, 2020 8:19 pm
jvierra wrote: ↑ Tue Sep 15, 2020 5:43 pm
Don't make the body HTML and the line breaks will persist.
Yes, that does make sense.
Thank you Mr, Vierra.
/* IT Engineer */
Anayazius
Posts: 11 Joined: Tue Jun 23, 2020 5:04 am
Post
by Anayazius » Sun Sep 27, 2020 3:41 am
ITEngineer wrote: ↑ Tue Sep 15, 2020 6:01 am
Hi All,
The below contents are from the $Results variable I got from my larger script.
Code: Select all
MachineName : PRDDC03.domain.com
Id : 4624
TimeCreated : 4/09/2020 12:12:12 PM
Account : DOMAIN\SVC-SQL
LogonType : 3
LogonTypeString : Network
WorkstationName :
SourceIP : 172.16.32.99
SourceName :
MachineName : PRDDC02-VM.domain.com
Id : 4624
TimeCreated : 3/09/2020 10:21:27 AM
Account : DOMAIN\SVC-prtg
LogonType : 3
LogonTypeString : Network
WorkstationName :
SourceIP : 10.10.13.97
SourceName :
MachineName : AD01.domain.com
Id : 4624
TimeCreated : 3/09/2020 9:15:27 AM
Account : DOMAIN\Admin.local
LogonType : 3
LogonTypeString : Network
WorkstationName :
SourceIP : 192.168.32.58
SourceName :
MachineName : SVRDC33.domain.com
Id : 4624
TimeCreated : 28/08/2020 4:51:13 PM
Account : DOMAIN\GLobal.Admin
LogonType : 3
LogonTypeString : Network
WorkstationName :
SourceIP : 192.168.13.66
SourceName :
MachineName : AD01.domain.com
Id : 4624
TimeCreated : 28/08/2020 11:54:27 AM
Account : DOMAIN\svc.avs
LogonType : 3
LogonTypeString : Network
WorkstationName :
SourceIP : 192.168.1.66
SourceName :
MachineName : AD02.domain.com
Id : 4624
TimeCreated : 26/08/2020 9:29:53 AM
Account : DOMAIN\testing1
LogonType : 3
LogonTypeString : Network
WorkstationName :
SourceIP : 192.168.13.77
SourceName :
How can I get the display for the Unique IP address like the below format:
Code: Select all
192.168.1.66 - LAPTOP66
192.168.32.58 - No-DNS
10.10.13.97 - SVRPRTG01
172.16.32.99 - NoDNS
The below code is not producing the output I wanted:
Write-Host "Unique IP addresses are as follows"**
Write-Host "$(($Results | Select-Object -ExpandProperty SourceIP -Unique)) - Resolve-DnsName -Type A -Name (($Results | Select-Object -ExpandProperty SourceIP -Unique))"
I also wanted to know how to filter out fake news that I can see online every day. Recently found a valuable essay for me on this topic https://writingbros.com/essay-examples/fake-news/ You can read and make sure that the problem is really serious.
Hence I need your help.
I want to convert the
$Results variable as HTML so I can attach it in Send-MailMessage body
Code: Select all
$params = @{
SmtpServer = 'SMTP.DOMAIN.com'
From = "$env:COMPUTERNAME@$env:userdnsdomain"
To = 'boss@IT.com'
Subject = "The report email as at $(Get-Date -Format 'F')"
Body = $Results
BodyAsHtml = $true
}
Send-MailMessage @params
Thank you in advance.
I am also interested in solving the problem. Thank you for your inquiry.