Execute Powershell Script With Variables
Moderators: JRL, Dorian (MJT support)
-
- Newbie
- Posts: 10
- Joined: Fri Oct 01, 2010 11:57 am
Execute Powershell Script With Variables
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,
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,
Hi wiredsolaris,
Can you not set the variables to strings that include the leading and trailing double quotes... like this?
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 -
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 -

-
- Newbie
- Posts: 10
- Joined: Fri Oct 01, 2010 11:57 am
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%
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%
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
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""
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?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
-
- Newbie
- Posts: 10
- Joined: Fri Oct 01, 2010 11:57 am
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.
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""
-
- Newbie
- Posts: 10
- Joined: Fri Oct 01, 2010 11:57 am
-
- Newbie
- Posts: 10
- Joined: Fri Oct 01, 2010 11:57 am
I got it to work by putting single quote inside of the double quotes like
"'Wired Solaris'".
"'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.