Execute Powershell Script With Variables

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
wiredsolaris
Newbie
Posts: 10
Joined: Fri Oct 01, 2010 11:57 am

Execute Powershell Script With Variables

Post by wiredsolaris » Wed Feb 02, 2011 7:44 pm

I am creating a mini app to automate user account and mailbox creation.
I have it calling powershell using RunProgram. I am passing variables as parameters to powershell, but some of them have spaces and I need to have MS pass double quotes with the parameters. Here is a snippit:

MessageModal>%dlgFirstName% %dlgLastName% %CRLF%%dlgAddress% %dlgCity% %dlgST% %dlgZIP% %CRLF%%dlgCompany% %dlgDept% %CRLF%%dlgTEL%

RunProgram>powershell.exe C:\Scripts\UserCreate\createuser.ps1 %dlgFirstName% %dlgLastName% %dlgCompany% %dlgCity% %dlgST% %dlgZIP% %dlgDept% %dlgTEL%

When I actually call the powershell script I need it to actually look like the following for example when it runs:

powershell.exe C:\Scripts\UserCreate\createuser.ps1 "David" "Cook" "Company Name" "Charlotte" "NC" "28202" "My Department" "704-555-5555"

I am not able to find a combination where it will actually put the double quotes when it execute RunProgram. Since the company and other fields have spaces, I need to be able have double quotes around the variables once they are passed.

Any thoughts?

Kind Regards,

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Wed Feb 02, 2011 9:32 pm

Hi wiredsolaris,

Can you not set the variables to strings that include the leading and trailing double quotes... like this?

Code: Select all

Let>dlgCompany="The Company"

MessageModal>dlgCompany

RunProgram>powershell.exe C:\Scripts\UserCreate\createuser.ps1 %dlgCompany%
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

wiredsolaris
Newbie
Posts: 10
Joined: Fri Oct 01, 2010 11:57 am

Post by wiredsolaris » Tue Feb 08, 2011 1:54 pm

I tried that and it still excludes the quotes when passing to Run for some reason.
jpuziano wrote:Hi wiredsolaris,

Can you not set the variables to strings that include the leading and trailing double quotes... like this?

Code: Select all

Let>dlgCompany="The Company"

MessageModal>dlgCompany

RunProgram>powershell.exe C:\Scripts\UserCreate\createuser.ps1 %dlgCompany%

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Feb 08, 2011 2:17 pm

I'm not familiar with powershell but I notice that you have a file name with a "ps1" extension. Is the extension ps1 associated with powershell.exe? If it is, have you tried using the ExecuteFile> function rather than the RunProgram> function? I don't know that it will work. Just something to try.

Code: Select all

ExecuteFile>C:\Scripts\UserCreate\createuser.ps1 %dlgFirstName% %dlgLastName% %dlgCompany% %dlgCity% %dlgST% %dlgZIP% %dlgDept% %dlgTEL% 

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Feb 08, 2011 2:36 pm

I think you need to double quote the quotes because Windows uses quotes as the parameter separators. Have you tried:

Run>powershell.exe C:\Scripts\UserCreate\createuser.ps1 ""David"" ""Cook"" ""Company Name"" ""Charlotte"" ""NC"" ""28202"" ""My Department"" ""704-555-5555""
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

wiredsolaris
Newbie
Posts: 10
Joined: Fri Oct 01, 2010 11:57 am

Post by wiredsolaris » Fri Feb 11, 2011 7:49 pm

Not sure what I am missing. Here is the exact run line that I am passing.

Run>powershell.exe –noexit C:\Scripts\UserCreate\createuser.ps1 ""%dlgFirstName%"" ""%dlgLastName%"" ""%dlgAddress%"" ""%dlgCompany%"" ""%dlgCity%"" ""%dlgST%"" ""%dlgZIP%"" ""%dlgDept%"" ""%dlgTEL%""

Not passing everything correct to where when I have a space in one of teh attributes that it maintains the quotes around the data.

mtettmar wrote:I think you need to double quote the quotes because Windows uses quotes as the parameter separators. Have you tried:

Run>powershell.exe C:\Scripts\UserCreate\createuser.ps1 ""David"" ""Cook"" ""Company Name"" ""Charlotte"" ""NC"" ""28202"" ""My Department"" ""704-555-5555""

wiredsolaris
Newbie
Posts: 10
Joined: Fri Oct 01, 2010 11:57 am

Post by wiredsolaris » Fri Feb 11, 2011 7:50 pm

BTW,
The powershell command runs, just that it does not utilize the double quotes. It seems to ignore them being passed so it sees each word that has spaces as a new field, thus putting the data in the wrong field.

wiredsolaris
Newbie
Posts: 10
Joined: Fri Oct 01, 2010 11:57 am

Post by wiredsolaris » Tue Feb 15, 2011 4:53 pm

I got it to work by putting single quote inside of the double quotes like
"'Wired Solaris'".
wiredsolaris wrote:BTW,
The powershell command runs, just that it does not utilize the double quotes. It seems to ignore them being passed so it sees each word that has spaces as a new field, thus putting the data in the wrong field.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts