VMware Cloud Community
infra3
Enthusiast
Enthusiast

Powershell Script Email Sending Issue

I have an issue with schedule the power shell script

HTML report is not showing complete out put with schedule

HTML report shows properly if I trigger manually

Exchange 2016 with SMTP

15 Replies
LucD
Leadership
Leadership

You will have to provide a bit more info on this.
What script are you using?
How are you scheduling it?
What exactly is missing?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
bechaker
Contributor
Contributor

Send the script to see where the problem is
Reply
0 Kudos
infra3
Enthusiast
Enthusiast

What script are you using? - vCheck Report    

How are you scheduling it?  Program Powershella nd argument as  -file "C:\Scripts\vCheck-vSphere-master\vCheck.ps1"

What exactly is missing? -  not showing any output of scripts only the shows below info  , if we ran manually the scripts from powershell / vsphere cli it gives output

  • General Information
  • vSwitch Security
  • VMs by Operating System
  • Plugin Report

General Information

General details on the infrastructure

Number of Hosts:

1

Number of Templates:

1

In-active VMs:

0

Number of Datastores:

1

Active VMs:

0

Number of Clusters:

1

Number of VMs:

1

DRS Migrations for last 1 Days:

0

Back To Top

vSwitch and portgroup security settings

All security options for standard vSwitches should be set to REJECT. Distributed vSwitches may require ForgedTrasmits in the default portgroup but should be disabled in other VM Network portgroups unless expressly required.

Message

PowerCLi version installed is lower than 5.1 Release 2, please update to use this plugin

Back To Top

VMs by Operating System : 1

The following Operating Systems are in use in this vCenter

OS

Count

Unknown - no VMTools

1

Back To Top

Plugin Report

Plugins in numerical order, enabled plugins listed first

Reply
0 Kudos
infra3
Enthusiast
Enthusiast

Script working fine only through schedule it gives error , its vcheck report

Reply
0 Kudos
LucD
Leadership
Leadership

Under which account does the scheduled task run?

How do you connect to the vSphere Server in the scheduled task? VICredentialStoreItem, hard-coded...?

Did you suppress all 'interactivity'? For example did you disable Depreciation Warning message?

Is there any reason why you are using that rather old PowerCLI version?
That is what the VDS plugin is telling you.

To allow the plugin to detect the guest OS name, requires that VMware Tools are installed inside the guest OS.
Apparently they aren't on the VM you tested against.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
infra3
Enthusiast
Enthusiast

Under which account does the scheduled task run? - one service account

How do you connect to the vSphere Server in the scheduled task? VICredentialStoreItem, hard-coded...? no the account has access to vcenter when it runs automatically connects

Did you suppress all 'interactivity'? For example did you disable Depreciation Warning message?   - yes

Is there any reason why you are using that rather old PowerCLI version?  - it was configured earlier not changed , it was working  recently there exchange migration happened 2010 to 2016 and this issue started and they cannot find a reason / fix
That is what the VDS plugin is telling you. -  how to use instead of old PowerCLI

To allow the plugin to detect the guest OS name, requires that VMware Tools are installed inside the guest OS.
Apparently they aren't on the VM you tested against.     - Tools are available

Reply
0 Kudos
LucD
Leadership
Leadership

Let's take this step by step.
Can you first check that sending an email is working, from an interactive session and from a scheduled job?

Use something like the following to perform the tests.

$sMail = @{

   To = 'you@domain'

   From = 'me@domain'

   Subject = 'Test Email'

   SmtpServer = 'mail.domain'

}


Send-MailMessage @sMail


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
infra3
Enthusiast
Enthusiast

Yes it is working fine .

When I ran vcheck from vsphere cli I will get complete report in html to mail

Reply
0 Kudos
LucD
Leadership
Leadership

"Yes it is working fine ." -> You mean from a scheduled job?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
infra3
Enthusiast
Enthusiast

Manual working fine from power cli

schedule not working

Reply
0 Kudos
LucD
Leadership
Leadership

Ok, we can conlcude that there is an issue with sending mail via SMTP to the mail server with the account the scheduled task is using.

You said earlier that the scheduled task uses a system account, can you try with the account you use to run the script in interactive mode?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
infra3
Enthusiast
Enthusiast

Schedule of test mail works now , just I deleted and create task again .

Reply
0 Kudos
sjesse
Leadership
Leadership

How are you scheduling it? For the action you should call powershell.exe and then for the arguments you should have -ExecutionPolicy bypass -File C:\path\to\vcheck.ps1. You also want to make sure that you are letting the schedule run while the user isn't logged in, but don't check the do not store password, as I've had problems with the vcheck . They should look kinda like this

pastedImage_0.png

pastedImage_1.png

I've seen that report blank out like that if you don't have the scheduled task setup correctly.

infra3
Enthusiast
Enthusiast

Thanks , it worked

Reply
0 Kudos
infra3
Enthusiast
Enthusiast

It works only when ran manually from schedule task , automatic schedule still not shows

Reply
0 Kudos