Christophe
asked on
Powershell condition
Hello,
I do not know how to do that. I'd like to add condition to this code below. I'd like the value "$visio" writes "none" if the software is not found. For the moment, if the software is not found, result is empty.
Thank you in advance for your help
Best,
Christophe
I do not know how to do that. I'd like to add condition to this code below. I'd like the value "$visio" writes "none" if the software is not found. For the moment, if the software is not found, result is empty.
$visio = Get-WmiObject -Class Win32_Product | sort-object Name | select Name | where { $_.Name -match “visio”} |
Format-table -HideTableHeaders |
Out-String
Thank you in advance for your help
Best,
Christophe
ASKER
Thank you for your help. Yes it is like this but I'd like to write the result of value $visio in email body. I do not know how to use your code to do that. I will try
ASKER
Because for the moment, I get result value in email. For exemple I receive "Microsoft Visio Viewer 2010"
If software with visio in name is not found, I'd like to receive "none". But I need to keep the result of the code. ie visio version found.
If software with visio in name is not found, I'd like to receive "none". But I need to keep the result of the code. ie visio version found.
Something like this? It will send mail on each occasion, I could probably simplify it more but I'm limited in time right now...
IF ($visio = Get-WmiObject -Class Win32_Product | sort-object Name | select Name | where { $_.Name -match “visio”} | Format-table -HideTableHeaders | Out-String) {Send-MailMessage -To <email> -From <email> -Subject "Visio Files" -body "Visio Files found" -SmtpServer <your-smtp-server>}
Else {Send-MailMessage -To <email> -From <email> -Subject "Visio Files" -body "No Visio Files found" -SmtpServer <your-smtp-server>}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you! it works perfectly. You are right, it was complicated.
Open in new window
The write-host can be replaced by other things of course.