Discuss RoboTask here
Rukbunker
Posts: 218 Joined: Mon Feb 22, 2016 4:06 pm
Location: Netherlands
Post
by Rukbunker » Wed Aug 29, 2018 9:18 am
Hey, it's me again.
I'm using Powershell to determine a mail address which is attached to the username. The powershell script is working perfectly when I execute it directly from Powershell.
Code: Select all
Get-ADUser -Identity [i]username[/i] -Properties ProxyAddresses | select -ExpandProperty ProxyAddresses | ? {$_ -clike "SMTP:*"}
As you can see, the last part of the command is using { and } . Robotask sees this part as a variable which is absolutely not the case. I've tried to include it between " and ' but no result.
Capture.PNG (12.8 KiB) Viewed 12413 times
Capture 2.PNG (8.67 KiB) Viewed 12413 times
Also I checked the helpfile to use the "internal" code for the {
Capture 3.PNG (3.64 KiB) Viewed 12413 times
But also this doesn't solve this. However, I really need this command, else output is too large. How can I do this the best?
Oleg
Site Admin
Posts: 3201 Joined: Thu Jan 01, 1970 1:00 am
Contact:
Post
by Oleg » Wed Aug 29, 2018 10:52 am
Run POWERSHELL through system command interpreter CMD.EXE
Command line is:
CMD.EXE /c <any_command_line>
Also look at my example below. It should work
Code: Select all
;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|1075658632
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task335"
Hide=INTEGER|0
ID=INTEGER|638450132
LogOnAsUser=INTEGER|1
Name=STRING|"Run powershell"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0
[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER
[Actions\Action1]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""CMD"" with value ""Get-ADUser -Identity [i]username[/i] -Properties ProxyAddresses | select -ExpandProperty ProxyAddresses | ? {$_ -clike ""SMTP:*""}"""
Params=FOLDER
[Actions\Action1\Params]
expand=STRING|"0"
varkind=STRING|"1"
varname=STRING|"CMD"
varvalue=STRING|"Get-ADUser -Identity [i]username[/i] -Properties ProxyAddresses | select -ExpandProperty ProxyAddresses | ? {$_ -clike ""SMTP:*""}"
[Actions\Action2]
ActionID=STRING|"A_MISC_RUNCONSOLEAPP"
Enabled=INTEGER|-1
Name=STRING|"Run command-line utility: cmd.exe /c powershell.exe {cmd}"
Params=FOLDER
[Actions\Action2\Params]
convertansi=STRING|"0"
ifnonzero=STRING|"0"
outputvar=STRING|"out"
params=STRING|"/c powershell.exe {cmd}"
program=STRING|"cmd.exe"
saveexitcode=STRING|"0"
saveoutput=STRING|"1"
[Actions\Action3]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""{out}"""
Params=FOLDER
[Actions\Action3\Params]
icon=STRING|"1"
msg0=STRING|"{out}"
msgcount=STRING|"1"
playsound=STRING|"0"
showmessage=STRING|"1"
Save the text of the task to a file and use menu Task->Import to import the task into RoboTask.
Oleg Yershov
Rukbunker
Posts: 218 Joined: Mon Feb 22, 2016 4:06 pm
Location: Netherlands
Post
by Rukbunker » Wed Aug 29, 2018 11:33 am
Almost there. It seems that the pipe sign | is messing up.
"Get-ADUser -Identity user -Properties ProxyAddresses
| select -ExpandProperty ProxyAddresses | ? {$_ -clike "SMTP:*"}"
Capture.PNG (3.5 KiB) Viewed 12402 times
Oleg
Site Admin
Posts: 3201 Joined: Thu Jan 01, 1970 1:00 am
Contact:
Post
by Oleg » Wed Aug 29, 2018 12:24 pm
It seems you
have to save your script into file with extension
.PS1
and start it by command line
powershell -executionpolicy bypass -File <Filename>
Read more here, please
Also look at my example:
Code: Select all
;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|1604865554
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task335"
Hide=INTEGER|0
ID=INTEGER|638450132
LogOnAsUser=INTEGER|1
Name=STRING|"Run powershell from file"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0
[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
[Actions\Action1]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""CMD"" with value ""Get-ADUser -Identity [i]username[/i] -Properties ProxyAddresses | select -ExpandProperty ProxyAddresses | ? {$_ -clike ""SMTP:*""}"""
Params=FOLDER
[Actions\Action1\Params]
expand=STRING|"0"
varkind=STRING|"1"
varname=STRING|"CMD"
varvalue=STRING|"Get-ADUser -Identity [i]username[/i] -Properties ProxyAddresses | select -ExpandProperty ProxyAddresses | ? {$_ -clike ""SMTP:*""}"
[Actions\Action2]
ActionID=STRING|"A_FILE_TEXTWRITE"
Enabled=INTEGER|-1
Name=STRING|"Create text file {TempDir}\script.ps1"
Params=FOLDER
[Actions\Action2\Params]
encode=STRING|"0"
fileexists=STRING|"0"
filname=STRING|"{TempDir}\script.ps1"
line0=STRING|"{cmd}"
linecount=STRING|"1"
suppress=STRING|"1"
[Actions\Action3]
ActionID=STRING|"A_MISC_RUNCONSOLEAPP"
Enabled=INTEGER|-1
Name=STRING|"Run command-line utility: powershell.exe -ExecutionPolicy Bypass -file ""{TempDir}\script.ps1"""
Params=FOLDER
[Actions\Action3\Params]
convertansi=STRING|"0"
ifnonzero=STRING|"0"
outputvar=STRING|"out"
params=STRING|"-ExecutionPolicy Bypass{EOL}-file ""{TempDir}\script.ps1"""
program=STRING|"powershell.exe"
saveexitcode=STRING|"0"
saveoutput=STRING|"1"
[Actions\Action4]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""{out}"""
Params=FOLDER
[Actions\Action4\Params]
icon=STRING|"1"
msg0=STRING|"{out}"
msgcount=STRING|"1"
playsound=STRING|"0"
showmessage=STRING|"1"
Oleg Yershov
Rukbunker
Posts: 218 Joined: Mon Feb 22, 2016 4:06 pm
Location: Netherlands
Post
by Rukbunker » Wed Aug 29, 2018 2:30 pm
It works perfectly. Many thanks!