Getting Auto-Edit variables into PowerShell

All questions about Control-M jobs definitions
Post Reply
User avatar
DocGoo
Nouveau
Nouveau
Posts: 73
Joined: 08 Sep 2010 12:00

Getting Auto-Edit variables into PowerShell

Post by DocGoo » 13 Nov 2012 10:43

We are switching from cmd.exe to PowerShell. How does one get the auto-edit variables from a CM job into the PowerShell script?

An example would be great!!

-- Goo

User avatar
piyush
Nouveau
Nouveau
Posts: 16
Joined: 05 Oct 2012 12:00

PowerShell Script for working with Control-M Jobs

Post by piyush » 08 Mar 2013 3:06

Hi,

The changes you will need to make in your Control-M jobs would be:

General Tab:

Filename: powershell.exe
Filepath: c:/windows/system32/WindowsPowerShell/v1.0/

(check powershell version and set directory accordingly)


SET Tab

1st Parameter: -command
2nd Paramter: "<location_of_script_on_box>" (eg. d:\controlm\scripts\test.ps1)
3rd Paramter: "Brahmos"
4th Paramter: "admin"
5th Paramter: "123321xxx123321"
and so on...

For eg. my purpose is to read the server name, id and password from Control-M Job.

Then 3rd Param is my server name: Brahmos
4th Param is my ID: admin
and 5th param is my password: 123321xxx123321

Now sample script for you:


##################Sample Script###################

param ([string] $serverName ,[string] $userID, [string] $Password )


if($serverName -eq "" -or $userID -eq "" -or $Password -eq "")

{

Write-Host ("parameters populated incorrectly......")
exit(1)
break;

}

else
{
Write-Host "Server name passed is: " $serverName
Write-Host "User ID passed is: " $userID
Write-Host "Password passed is: " $Password

}


##############Sample Script Ends###################


If all parameters are not passed job would fail and if all parameters are there it would print their values.


I hope it helps
:D
Last edited by piyush on 10 Mar 2013 1:20, edited 1 time in total.

User avatar
DocGoo
Nouveau
Nouveau
Posts: 73
Joined: 08 Sep 2010 12:00

Post by DocGoo » 08 Mar 2013 8:23

No Go...... Here is what I tried.

param ([string] $serverName ,[string] $userID, [string] $Password )

$exe = "F:\Program Files\BMC Software\CONTROL-M Server\Ctm_server\Exe\ctmvar.exe"

if($serverName -eq "" -or $userID -eq "" -or $Password -eq "")
{

$body = "parameters populated incorrectly......"

&$exe -action set -var "%%\EMAIL_BODY" -varexpr $body

exit 0
}
else
{

$body = "Server name passed is: " + $serverName +
"User ID passed is: " + $userID +
"Password passed is: " + $Password

&$exe -action set -var "%%\EMAIL_BODY" -varexpr $body

exit 0
}

I get an email saying "parameters populated incorrectly".

Auto-Edit Variables are set as
PARM1 AAAAAAAAAAAAAAAA
PARM2 BBBBBBBBBBBBBBBB
PARM3 CCCCCCCCCCCCCC

Any ideas????

--Goo

User avatar
piyush
Nouveau
Nouveau
Posts: 16
Joined: 05 Oct 2012 12:00

Post by piyush » 09 Mar 2013 4:44

Please go through my post again. The first two parameters should be:

-command
powershell script location on box

and then pass your other variables.

User avatar
DocGoo
Nouveau
Nouveau
Posts: 73
Joined: 08 Sep 2010 12:00

Post by DocGoo » 10 Mar 2013 10:48

Ahhhhh.................... I understand now, and will try this week.

Thank you, it has expained a couple of things.

More later in week.

Many Thanks!!!!!!!!!!!!!!

-Goo

User avatar
DocGoo
Nouveau
Nouveau
Posts: 73
Joined: 08 Sep 2010 12:00

Post by DocGoo » 11 Mar 2013 7:35

Ok, got it working now!!!!!!!!!!!!

Thanks so much, I have a better understanding of how Job vs. Command now.

--Goo

User avatar
piyush
Nouveau
Nouveau
Posts: 16
Joined: 05 Oct 2012 12:00

Post by piyush » 12 Mar 2013 7:12

No worries mate!

You are welcome.

Regards,
PG

User avatar
zailaiboke
Nouveau
Nouveau
Posts: 3
Joined: 01 Aug 2013 12:00

Post by zailaiboke » 01 Aug 2013 11:42

The first two parameters should be:





________________________________________________
FIFA Ultimate Coins

Post Reply