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 (20 points)

1 Answer

0 votes
by (304k 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

Hi, is it possible to save to an Adaxes attribute the value of the last Sign In from Azure AD? When we query users for Last Logon, we, of course, can only see the Last Logon value from AD It would be very useful to know the latest login in Azure AD as well

asked Jun 22, 2020 by manuel.galli (100 points)
0 votes
1 answer

We are using the below snippet to grab the email of a single custom attribute object. Can I get guidance on the best way to modify this to get all the emails of each ... "The user specified in parameter 'MyParameter' has no email address. ", "Information") }

asked Dec 23, 2024 by msheppard (840 points)
0 votes
1 answer

For creating a computer object, we want to check if the entered CN is already used in our AD. And for that we want to use a powershell script. An other dot ... powershell script should be start before creating the computer object, right? Thanks for your help.

asked Jun 4, 2024 by KEME (80 points)
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 (360 points)
0 votes
1 answer

My security team is looking to do a security review and would like the vendor to fill out a questionnaire.

asked Aug 25, 2023 by LarrySargent (20 points)
3,729 questions
3,407 answers
8,616 comments
550,138 users