0 votes

Hello,

is there a way to save powershell variable to axases attribute and send it via "send email notification" in Scheduled task?

for example, check if Office 2016 is installed and send report via email.

` $software = "Microsoft Office Professional Plus 2016" $installed = Get-WmiObject -ComputerName %cn% -Class Win32Product | sort-object Name | Select-Object Name | Where-Object {$.Name -eq $software}

if (-not $installed) {$customattrib = " %cn% - $($installed.name) not installed"} else {$customattrib = " %cn% - $($installed.name) installed"} ` then add $customattrib value to Send email notification.

Thank you

by (250 points)

1 Answer

0 votes
by (172k points)

Hello,

Do we understand correctly that the script you referenced and the Send email notification action will be executed in the same Scheduled Task? If that is correct, there is no possibility to pass the $customattrib variable value to the action. You will need to send the notification right in the script itself. Finally, it will look like the following:

$software = "Microsoft Office Professional Plus 2016"
$installed = Get-WmiObject -ComputerName %cn% -Class Win32Product | sort-object Name | Select-Object Name | Where-Object {$.Name -eq $software}

if (-not $installed) 
{
    $customattrib = " %cn% - $($installed.name) not installed"
} 
else 
{
    $customattrib = " %cn% - $($installed.name) installed"
}

# Send mail
$Context.SendMail("recipient@company.com", "Office 2016", $customattrib, $Null)
0

Nice, thank you!

Is there a way to use HTML formatting in $context.sendemail body?

$subject = test
$body =
@"
<h1>some
random
text with HTML formatting</h1>
"@

$context.SendMail("mail@mail.com",$Subject, $body, $null)

0

Hello,

Yes, you will just need to specify the variable containing the HTML formatted text in the fourth parameter of the $Context.SendMail method and set the third parameter to $Null. Finally, the script will look like the following:

$subject = test
$body =
@"
<h1>some
random
text with HTML formatting</h1>
"@

$context.SendMail("mail@mail.com",$Subject, $null, $body)

Related questions

0 votes
1 answer

I have a scheduled task that runs a Powershell script against an AD group, "Group 1". I need to get all of the members of Group 1, and add them to Group 2. The ... identity in the error message start with 'user;'? What is the correct way to accomplish this?

asked Aug 27, 2019 by ngb (280 points)
0 votes
1 answer

As I found out today, the enrollment email notification in the Self-Service policy emails any user account in the domain. We have some service accounts that are just mail-enabled ... = $True } Is that the way to check if they have enrolled or not?

asked Mar 25, 2013 by danftasc (3.4k points)
0 votes
0 answers

Hi Just starting to trial Adaxes and so far so good. Haven't quite grasped the PowerShell v ADSI features and was hoping someone could assist with my PS script. Basically I ... long, just wondering if I can somehow use the Adaxes ADSI to make it better. Thanks

asked Aug 22, 2016 by jask747 (250 points)
0 votes
1 answer

Is it possible when sending the email notification to include all recipients in a single email instead of individual emails going out to each user? Thanks

asked Nov 1, 2018 by cory.fiala (280 points)
0 votes
1 answer

I'm having trouble retrieving a value from an attribute but another attribute of similar type I have no trouble getting. The AD schema has been expanded to add these ... # 250 at char 41 while executing $termDate = $userRec.Get("terminationDate"). Help!

asked Mar 24, 2017 by sbanks (1.4k points)
2,125 questions
1,892 answers
5,288 comments
3,192 users