[Solved] How to change E-Mail domain in all e-mail tasks via powershell? - VisualCron - Forum

Community forum

Gary_W
2021-03-08T23:22:32Z
I have an existing VC job that lets me input an e-mail address then uses a powershell script to search all jobs for e-mail tasks and outputs job and task name where that e-mail address is in use in any of the e-mail fields like FromEmail or RecipientString .

The next step is to set the FromEmail value to itself after replacing a domain that needs to change.

Can someone point me to an example on how to call the set method for this? I'm having a hard time figuring this one out for some reason.

Edit 3/9/2021
My issue was my ignorance in not knowing how to read the API documentation. Now There's another problem though. here's some sample powershell code I'm using to test changing the FromEmail value in another job/task.


...
...
$jobs = Get-AllVCJobs
foreach job
  foreach task
    If job = mytestjob and tasktype = Email
 
           Write-Output ("Job: " + $job.Name + "  Task: " + $task.Name )

                # See if FromEmail contains the old domain    
                if ($task.Email.FromEmail -like "*$domainIn*" ) {  
                  # if so print it
                  Write-Output ("Before  From: " + $task.Email.FromEmail )
                  # Then change it
                  $task.Email.set_FromEmail("emailgary@testdomain.com")   
                  # print it again to verify
                  Write-Output ("After  From: " + $task.Email.FromEmail )
                }


This all works as expected, except when I look at mytestjob , FromEmail has not changed. What am I missing?

This is a testing step to help me understand before I add code to change the domain for all addresses that need updating in all tasks.

Update 3/10/2021
Thank you to Michael from support who showed me the object search function under the tools menu. My issue is I'm on version 8.5.5 which does not support the replace functionality. Looks like I'll be upgrading soon as a script should not be necessary, replacing the domain strings should be able to be done from the object search/replace tool.

Update 3/16/2021
I ended up brute-forcing the update. We only needed to change ReplyToEmail, FromName and FromEmail values. So, I used the object search functionality to verify which objects I needed, then went to file/export settings and exported jobs and notifications. To prevent this in the future, I created a server-level environment variable on all server set to the domain (this way, int he future we'll have just one place to go to change the domain). Then I edited the xmls in the backup and did a search/replace with some regex voodoo and replaced the email domain text for those From values only with "{USERVAR(EnvEmailDomain)}". Zipped it back up and imported when no jobs were running. Bam! Bob's your Uncle!
Support
2021-03-10T15:23:33Z
Originally Posted by: Gary_W 

I have an existing VC job that lets me input an e-mail address then uses a powershell script to search all jobs for e-mail tasks and outputs job and task name where that e-mail address is in use in any of the e-mail fields like FromEmail or RecipientString .

The next step is to set the FromEmail value to itself after replacing a domain that needs to change.

Can someone point me to an example on how to call the set method for this? I'm having a hard time figuring this one out for some reason.

Edit 3/9/2021
My issue was my ignorance in not knowing how to read the API documentation. Now There's another problem though. here's some sample powershell code I'm using to test changing the FromEmail value in another job/task.


...
...
$jobs = Get-AllVCJobs
foreach job
  foreach task
    If job = mytestjob and tasktype = Email
 
           Write-Output ("Job: " + $job.Name + "  Task: " + $task.Name )

                # See if FromEmail contains the old domain    
                if ($task.Email.FromEmail -like "*$domainIn*" ) {  
                  # if so print it
                  Write-Output ("Before  From: " + $task.Email.FromEmail )
                  # Then change it
                  $task.Email.set_FromEmail("emailgary@testdomain.com")   
                  # print it again to verify
                  Write-Output ("After  From: " + $task.Email.FromEmail )
                }


This all works as expected, except when I look at mytestjob , FromEmail has not changed. What am I missing?

This is a testing step to help me understand before I add code to change the domain for all addresses that need updating in all tasks.



We had email contact - just responding here to say that we have this functionality built in , in the newer version of visualcron (Object search&replace)
Michael
Support
http://www.visualcron.com 

Please like  VisualCron on facebook!
Scroll to Top