Hi,
I have a CSV file which has some duplicate entries.
Get-VM | select Name | sort Name | Export-Csv -path “C:\Users\venkatak\Desktop\Test\Duplicate_Replication\Duplicates.csv” –NoTypeInformation
This CSV file will have duplicate entries.
Import-Csv ‘ihsvc03_Duplicates.csv’ | Group-Object -Property Name | Where-Object { $.count -ge 2 } | Foreach-Object { $.Group } | select Name | Export-csv -Path “C:\Users\venkatak\Desktop\Test\Duplicate_Replication\Duplicate_Found.csv” –NoTypeInformation
This will get the information from above file & write only duplicate entries to separate file.
Is there a way, I can send an e-mail, if I found only duplicate entries, if not found, no e-mail is necessary.
-Kalyan
$duplicates = Import-Csv 'ihsvc03_Duplicates.csv' |
Group-Object -Property Name |
Where-Object { $_.Count -gt 1 }
if ( $duplicates ) {
#Send Email
}
$group = Get-VM | Select-Object Name | Group-Object -Property Name
$result = foreach ($g in $group){If ($g.Count -gt 1) {$g.Name}}
$send = @{
To = 'test1.com'
From = 'test2.com'
Subject = 'Get-VM Duplicates'
Body = $result
SMTPServer = ''}
Send-MailMessage @send
Hi Rob,
I am looking for the duplicate names in the e-mail as-well.
-Kalyan
Hi Random,
It’s giving me error: cannot validate argument on parameter ‘body’
-Kalyan
Hey Venkata,
I think the results in $Result are empty.
You could have a look by inspecting the Variable.
$group = Get-VM | Select-Object Name | Group-Object -Property Name
$result = foreach ($g in $group){If ($g.Count -gt 1) {$g.Name}}
$result
Is there any data displayed?
BR,
BBC
Thanks. There are no data.
One more thing, I need to add some text to body if data is there.
body = $result ?
-Kalyan
Hi,
I got it.
body - “$result - Test here”
-Kalyan
Hi,
But, if the data is present, I am receiving e-mail twice. I just want only one e-mail.
$group = Get-VM | Select-Object Name | Group-Object -Property Name
$result = foreach ($g in $group){If ($g.Count -gt 1) {$g.Name}}
$send = @{
To = ‘test1.com’
From = ‘test2.com’
Subject = ‘Get-VM Duplicates’
Body = $result
SMTPServer = ‘’}
Send-MailMessage @send
-Kalyan