![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | executing commands from an xml file I have an xml file that I am parsing with powershell. The xml file contains functions, variables and commands that are being parsed to perform a task. I have an issue now where a function in the xml file executes a set of commands (an array) using invoke-expression. When I run this in powershell it takes the array and displays the command as text and I want it to execute the command. For example, I have the installation files for Acrobat Reader in a folder and one of the commands from my xml file is: msiexec acroread.msi....transform=...., and then a second command will open a pdf in acrobat reader. When my script runs is displays the msiexec command instead of launching the installer. I have the same problem with executables that I am installing. I have tried dot sourcing and I know my install commands are correct becuase I can run them outside of my script and it works as expected. I hope I am clear enough, and I would be willing to post the contents of my files if it would help. This is kind of a continuation of the post below when I was trying to find out how to parse the xml file and run the commands: http://www.microsoft.com/communities...6562a05773&p=1 Thanks for any help that you may have for me. |
My System Specs![]() |
| | #2 (permalink) |
| | Re: executing commands from an xml file Just curious, why XML? Why not scripts? With a script you can avoid the parsing and invoking actions, which I believe is also slower, and even run parts of code by executing scriptblocks. Anyway, what about a code snippet or errors description? It can help understand your situation. Shay http://scriptolog.blogspot.com Quote: > I have an xml file that I am parsing with powershell. The xml file > contains functions, variables and commands that are being parsed to > perform a task. I have an issue now where a function in the xml file > executes a set of commands (an array) using invoke-expression. When I > run this in powershell it takes the array and displays the command as > text and I want it to execute the command. For example, I have the > installation files for Acrobat Reader in a folder and one of the > commands from my xml file is: msiexec acroread.msi....transform=...., > and then a second command will open a pdf in acrobat reader. When my > script runs is displays the msiexec command instead of launching the > installer. I have the same problem with executables that I am > installing. I have tried dot sourcing and I know my install commands > are correct becuase I can run them outside of my script and it works > as expected. > > I hope I am clear enough, and I would be willing to post the contents > of my files if it would help. > > This is kind of a continuation of the post below when I was trying to > find > > out how to parse the xml file and run the commands: > > http://www.microsoft.com/communities...us/default.asp > x?dg=microsoft.public.windows.powershell&tid=e6cc707d-a501-4eb2-bd99-e > 06562a05773&p=1 > > Thanks for any help that you may have for me. > |
My System Specs![]() |
| | #3 (permalink) |
| | Re: executing commands from an xml file I am trying to use powershell to automate some tasks that we do at our office. Basic stuff like install acrobat reader, create user in AD, etc... Here is the process for my powerhshell "program". Out IT staff will goto an internal website and download a powershell script with when run creates a few variables and downloads this xml file. The xml file contains a menu (for stupid proofing), variables, functions, installation commands, dsadd's, etc... I chose the xml file becase I could have everything in one place as opposed to our current structure with a bunch of scripts. When I make a change to the XML file it takes affect the next time the script is run. Here is the function that I am having the problem with: function command_execute ($command = $info.data.$choice.$sub_choice.command) { $command | foreach-object {invoke-expression $_} $logging = $info.data.$choice.$sub_choice.comment date | write-output | out-file $logs\foundation_log.txt -append write-output "$logging" "$command" -- | out-file $logs\foundation_log.txt -append } $command would be the following: <command>download ar.zip</command> <command>unzip ar.zip</command> <command>msiexec /i $unzip_location\acroread8.msi transforms=$unzip_location\acroread8.mst /lv $logs\ar.log /qn</command> download and unzip from above are other functions pulled from the xml file that do just that, download the file and unzip it to a directory. When my script runs command execute it displays the contents of the command element above. Funny thing is it runs the functions for the download and unzip properly but when it gets to the msiexec it displays it as if it were text. This also happens on executables that run installations. Hope I was clearer here? "Shay Levi" wrote: Quote: > Just curious, why XML? Why not scripts? With a script you can avoid the parsing > and invoking actions, which I believe is also slower, and even run parts > of code by > executing scriptblocks. > > Anyway, what about a code snippet or errors description? It can help understand > your situation. > > Shay > http://scriptolog.blogspot.com > > > Quote: > > I have an xml file that I am parsing with powershell. The xml file > > contains functions, variables and commands that are being parsed to > > perform a task. I have an issue now where a function in the xml file > > executes a set of commands (an array) using invoke-expression. When I > > run this in powershell it takes the array and displays the command as > > text and I want it to execute the command. For example, I have the > > installation files for Acrobat Reader in a folder and one of the > > commands from my xml file is: msiexec acroread.msi....transform=...., > > and then a second command will open a pdf in acrobat reader. When my > > script runs is displays the msiexec command instead of launching the > > installer. I have the same problem with executables that I am > > installing. I have tried dot sourcing and I know my install commands > > are correct becuase I can run them outside of my script and it works > > as expected. > > > > I hope I am clear enough, and I would be willing to post the contents > > of my files if it would help. > > > > This is kind of a continuation of the post below when I was trying to > > find > > > > out how to parse the xml file and run the commands: > > > > http://www.microsoft.com/communities...us/default.asp > > x?dg=microsoft.public.windows.powershell&tid=e6cc707d-a501-4eb2-bd99-e > > 06562a05773&p=1 > > > > Thanks for any help that you may have for me. > > > > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: executing commands from an xml file If my code snippets were not good enough please let me know and I can send an email or upload the complete files (foundation.ps1(3k) and data.xml (9k))somewhere. "Brett" wrote: Quote: > I am trying to use powershell to automate some tasks that we do at our > office. Basic stuff like install acrobat reader, create user in AD, etc... > Here is the process for my powerhshell "program". Out IT staff will goto an > internal website and download a powershell script with when run creates a few > variables and downloads this xml file. The xml file contains a menu (for > stupid proofing), variables, functions, installation commands, dsadd's, > etc... I chose the xml file becase I could have everything in one place as > opposed to our current structure with a bunch of scripts. When I make a > change to the XML file it takes affect the next time the script is run. > > Here is the function that I am having the problem with: > > function command_execute > > ($command = $info.data.$choice.$sub_choice.command) > { > $command | foreach-object {invoke-expression $_} > $logging = $info.data.$choice.$sub_choice.comment > date | write-output | out-file $logs\foundation_log.txt -append > write-output "$logging" "$command" -- | out-file $logs\foundation_log.txt > -append > > } > > $command would be the following: > > <command>download ar.zip</command> > <command>unzip ar.zip</command> > <command>msiexec /i $unzip_location\acroread8.msi > transforms=$unzip_location\acroread8.mst /lv $logs\ar.log /qn</command> > > download and unzip from above are other functions pulled from the xml file > that do just that, download the file and unzip it to a directory. > > When my script runs command execute it displays the contents of the command > element above. Funny thing is it runs the functions for the download and > unzip properly but when it gets to the msiexec it displays it as if it were > text. This also happens on executables that run installations. > > Hope I was clearer here? > > > > > > "Shay Levi" wrote: > Quote: > > Just curious, why XML? Why not scripts? With a script you can avoid the parsing > > and invoking actions, which I believe is also slower, and even run parts > > of code by > > executing scriptblocks. > > > > Anyway, what about a code snippet or errors description? It can help understand > > your situation. > > > > Shay > > http://scriptolog.blogspot.com > > > > > > Quote: > > > I have an xml file that I am parsing with powershell. The xml file > > > contains functions, variables and commands that are being parsed to > > > perform a task. I have an issue now where a function in the xml file > > > executes a set of commands (an array) using invoke-expression. When I > > > run this in powershell it takes the array and displays the command as > > > text and I want it to execute the command. For example, I have the > > > installation files for Acrobat Reader in a folder and one of the > > > commands from my xml file is: msiexec acroread.msi....transform=...., > > > and then a second command will open a pdf in acrobat reader. When my > > > script runs is displays the msiexec command instead of launching the > > > installer. I have the same problem with executables that I am > > > installing. I have tried dot sourcing and I know my install commands > > > are correct becuase I can run them outside of my script and it works > > > as expected. > > > > > > I hope I am clear enough, and I would be willing to post the contents > > > of my files if it would help. > > > > > > This is kind of a continuation of the post below when I was trying to > > > find > > > > > > out how to parse the xml file and run the commands: > > > > > > http://www.microsoft.com/communities...us/default.asp > > > x?dg=microsoft.public.windows.powershell&tid=e6cc707d-a501-4eb2-bd99-e > > > 06562a05773&p=1 > > > > > > Thanks for any help that you may have for me. > > > > > > > |
My System Specs![]() |
| | #5 (permalink) |
| | Re: executing commands from an xml file What happens if you use the & operator instead of invoke-expression? & $_ & {$_} & "$_" Shay http://scriptolog.blogspot.com Quote: > I am trying to use powershell to automate some tasks that we do at our > office. Basic stuff like install acrobat reader, create user in AD, > etc... Here is the process for my powerhshell "program". Out IT staff > will goto an internal website and download a powershell script with > when run creates a few variables and downloads this xml file. The xml > file contains a menu (for stupid proofing), variables, functions, > installation commands, dsadd's, etc... I chose the xml file becase I > could have everything in one place as opposed to our current structure > with a bunch of scripts. When I make a change to the XML file it takes > affect the next time the script is run. > > Here is the function that I am having the problem with: > > function command_execute > > ($command = $info.data.$choice.$sub_choice.command) > { > $command | foreach-object {invoke-expression $_} > $logging = $info.data.$choice.$sub_choice.comment > date | write-output | out-file $logs\foundation_log.txt -append > write-output "$logging" "$command" -- | out-file > $logs\foundation_log.txt > -append > } > > $command would be the following: > > <command>download ar.zip</command> > <command>unzip ar.zip</command> > <command>msiexec /i $unzip_location\acroread8.msi > transforms=$unzip_location\acroread8.mst /lv $logs\ar.log > /qn</command> > download and unzip from above are other functions pulled from the xml > file that do just that, download the file and unzip it to a directory. > > When my script runs command execute it displays the contents of the > command element above. Funny thing is it runs the functions for the > download and unzip properly but when it gets to the msiexec it > displays it as if it were text. This also happens on executables that > run installations. > > Hope I was clearer here? > > "Shay Levi" wrote: > Quote: >> Just curious, why XML? Why not scripts? With a script you can avoid >> the parsing >> and invoking actions, which I believe is also slower, and even run >> parts >> of code by >> executing scriptblocks. >> Anyway, what about a code snippet or errors description? It can help >> understand your situation. >> >> Shay >> http://scriptolog.blogspot.com Quote: >>> I have an xml file that I am parsing with powershell. The xml file >>> contains functions, variables and commands that are being parsed to >>> perform a task. I have an issue now where a function in the xml file >>> executes a set of commands (an array) using invoke-expression. When >>> I run this in powershell it takes the array and displays the command >>> as text and I want it to execute the command. For example, I have >>> the installation files for Acrobat Reader in a folder and one of the >>> commands from my xml file is: msiexec >>> acroread.msi....transform=...., and then a second command will open >>> a pdf in acrobat reader. When my script runs is displays the msiexec >>> command instead of launching the installer. I have the same problem >>> with executables that I am installing. I have tried dot sourcing and >>> I know my install commands are correct becuase I can run them >>> outside of my script and it works as expected. >>> >>> I hope I am clear enough, and I would be willing to post the >>> contents of my files if it would help. >>> >>> This is kind of a continuation of the post below when I was trying >>> to find >>> >>> out how to parse the xml file and run the commands: >>> >>> http://www.microsoft.com/communities...n-us/default.a >>> sp >>> x?dg=microsoft.public.windows.powershell&tid=e6cc707d-a501-4eb2-bd99 >>> -e 06562a05773&p=1 >>> >>> Thanks for any help that you may have for me. >>> |
My System Specs![]() |
| | #6 (permalink) |
| | Re: executing commands from an xml file Can you integrate this and see if the cmd.exe is executing? <command>cmd /k echo executing</command> Shay http://scriptolog.blogspot.com Quote: > What happens if you use the & operator instead of invoke-expression? > > & $_ > & {$_} > & "$_" > Shay > http://scriptolog.blogspot.com Quote: >> I am trying to use powershell to automate some tasks that we do at >> our office. Basic stuff like install acrobat reader, create user in >> AD, etc... Here is the process for my powerhshell "program". Out IT >> staff will goto an internal website and download a powershell script >> with when run creates a few variables and downloads this xml file. >> The xml file contains a menu (for stupid proofing), variables, >> functions, installation commands, dsadd's, etc... I chose the xml >> file becase I could have everything in one place as opposed to our >> current structure with a bunch of scripts. When I make a change to >> the XML file it takes affect the next time the script is run. >> >> Here is the function that I am having the problem with: >> >> function command_execute >> >> ($command = $info.data.$choice.$sub_choice.command) >> { >> $command | foreach-object {invoke-expression $_} >> $logging = $info.data.$choice.$sub_choice.comment >> date | write-output | out-file $logs\foundation_log.txt -append >> write-output "$logging" "$command" -- | out-file >> $logs\foundation_log.txt >> -append >> } >> $command would be the following: >> >> <command>download ar.zip</command> >> <command>unzip ar.zip</command> >> <command>msiexec /i $unzip_location\acroread8.msi >> transforms=$unzip_location\acroread8.mst /lv $logs\ar.log >> /qn</command> >> download and unzip from above are other functions pulled from the xml >> file that do just that, download the file and unzip it to a >> directory. >> When my script runs command execute it displays the contents of the >> command element above. Funny thing is it runs the functions for the >> download and unzip properly but when it gets to the msiexec it >> displays it as if it were text. This also happens on executables that >> run installations. >> >> Hope I was clearer here? >> >> "Shay Levi" wrote: >> Quote: >>> Just curious, why XML? Why not scripts? With a script you can avoid >>> the parsing >>> and invoking actions, which I believe is also slower, and even run >>> parts >>> of code by >>> executing scriptblocks. >>> Anyway, what about a code snippet or errors description? It can help >>> understand your situation. >>> Shay >>> http://scriptolog.blogspot.com >>>> I have an xml file that I am parsing with powershell. The xml file >>>> contains functions, variables and commands that are being parsed to >>>> perform a task. I have an issue now where a function in the xml >>>> file executes a set of commands (an array) using invoke-expression. >>>> When I run this in powershell it takes the array and displays the >>>> command as text and I want it to execute the command. For example, >>>> I have the installation files for Acrobat Reader in a folder and >>>> one of the commands from my xml file is: msiexec >>>> acroread.msi....transform=...., and then a second command will open >>>> a pdf in acrobat reader. When my script runs is displays the >>>> msiexec command instead of launching the installer. I have the same >>>> problem with executables that I am installing. I have tried dot >>>> sourcing and I know my install commands are correct becuase I can >>>> run them outside of my script and it works as expected. >>>> >>>> I hope I am clear enough, and I would be willing to post the >>>> contents of my files if it would help. >>>> >>>> This is kind of a continuation of the post below when I was trying >>>> to find >>>> >>>> out how to parse the xml file and run the commands: >>>> >>>> http://www.microsoft.com/communities.../en-us/default. >>>> a sp >>>> x?dg=microsoft.public.windows.powershell&tid=e6cc707d-a501-4eb2-bd9 >>>> 9 -e 06562a05773&p=1 >>>> >>>> Thanks for any help that you may have for me. >>>> |
My System Specs![]() |
| | #7 (permalink) |
| | Re: executing commands from an xml file Brett, were you able to resolve it? Shay http://scriptolog.blogspot.com Quote: > Can you integrate this and see if the cmd.exe is executing? > > <command>cmd /k echo executing</command> > > Shay > http://scriptolog.blogspot.com Quote: >> What happens if you use the & operator instead of invoke-expression? >> >> & $_ >> & {$_} >> & "$_" >> Shay >> http://scriptolog.blogspot.com Quote: >>> I am trying to use powershell to automate some tasks that we do at >>> our office. Basic stuff like install acrobat reader, create user in >>> AD, etc... Here is the process for my powerhshell "program". Out IT >>> staff will goto an internal website and download a powershell script >>> with when run creates a few variables and downloads this xml file. >>> The xml file contains a menu (for stupid proofing), variables, >>> functions, installation commands, dsadd's, etc... I chose the xml >>> file becase I could have everything in one place as opposed to our >>> current structure with a bunch of scripts. When I make a change to >>> the XML file it takes affect the next time the script is run. >>> >>> Here is the function that I am having the problem with: >>> >>> function command_execute >>> >>> ($command = $info.data.$choice.$sub_choice.command) >>> { >>> $command | foreach-object {invoke-expression $_} >>> $logging = $info.data.$choice.$sub_choice.comment >>> date | write-output | out-file $logs\foundation_log.txt -append >>> write-output "$logging" "$command" -- | out-file >>> $logs\foundation_log.txt >>> -append >>> } >>> $command would be the following: >>> <command>download ar.zip</command> >>> <command>unzip ar.zip</command> >>> <command>msiexec /i $unzip_location\acroread8.msi >>> transforms=$unzip_location\acroread8.mst /lv $logs\ar.log >>> /qn</command> >>> download and unzip from above are other functions pulled from the >>> xml >>> file that do just that, download the file and unzip it to a >>> directory. >>> When my script runs command execute it displays the contents of the >>> command element above. Funny thing is it runs the functions for the >>> download and unzip properly but when it gets to the msiexec it >>> displays it as if it were text. This also happens on executables >>> that >>> run installations. >>> Hope I was clearer here? >>> >>> "Shay Levi" wrote: >>> >>>> Just curious, why XML? Why not scripts? With a script you can avoid >>>> the parsing >>>> and invoking actions, which I believe is also slower, and even run >>>> parts >>>> of code by >>>> executing scriptblocks. >>>> Anyway, what about a code snippet or errors description? It can >>>> help >>>> understand your situation. >>>> Shay >>>> http://scriptolog.blogspot.com >>>>> I have an xml file that I am parsing with powershell. The xml file >>>>> contains functions, variables and commands that are being parsed >>>>> to perform a task. I have an issue now where a function in the xml >>>>> file executes a set of commands (an array) using >>>>> invoke-expression. When I run this in powershell it takes the >>>>> array and displays the command as text and I want it to execute >>>>> the command. For example, I have the installation files for >>>>> Acrobat Reader in a folder and one of the commands from my xml >>>>> file is: msiexec acroread.msi....transform=...., and then a second >>>>> command will open a pdf in acrobat reader. When my script runs is >>>>> displays the msiexec command instead of launching the installer. I >>>>> have the same problem with executables that I am installing. I >>>>> have tried dot sourcing and I know my install commands are correct >>>>> becuase I can run them outside of my script and it works as >>>>> expected. >>>>> >>>>> I hope I am clear enough, and I would be willing to post the >>>>> contents of my files if it would help. >>>>> >>>>> This is kind of a continuation of the post below when I was trying >>>>> to find >>>>> >>>>> out how to parse the xml file and run the commands: >>>>> >>>>> http://www.microsoft.com/communities.../en-us/default >>>>> . a sp >>>>> x?dg=microsoft.public.windows.powershell&tid=e6cc707d-a501-4eb2-bd >>>>> 9 9 -e 06562a05773&p=1 >>>>> >>>>> Thanks for any help that you may have for me. >>>>> |
My System Specs![]() |
| | #8 (permalink) |
| | Re: executing commands from an xml file I will not be able to test this till the end of today. I will know soon and post back for you. "Shay Levi" wrote: Quote: > Brett, were you able to resolve it? > > Shay > http://scriptolog.blogspot.com > > > Quote: > > Can you integrate this and see if the cmd.exe is executing? > > > > <command>cmd /k echo executing</command> > > > > Shay > > http://scriptolog.blogspot.com Quote: > >> What happens if you use the & operator instead of invoke-expression? > >> > >> & $_ > >> & {$_} > >> & "$_" > >> Shay > >> http://scriptolog.blogspot.com > >>> I am trying to use powershell to automate some tasks that we do at > >>> our office. Basic stuff like install acrobat reader, create user in > >>> AD, etc... Here is the process for my powerhshell "program". Out IT > >>> staff will goto an internal website and download a powershell script > >>> with when run creates a few variables and downloads this xml file. > >>> The xml file contains a menu (for stupid proofing), variables, > >>> functions, installation commands, dsadd's, etc... I chose the xml > >>> file becase I could have everything in one place as opposed to our > >>> current structure with a bunch of scripts. When I make a change to > >>> the XML file it takes affect the next time the script is run. > >>> > >>> Here is the function that I am having the problem with: > >>> > >>> function command_execute > >>> > >>> ($command = $info.data.$choice.$sub_choice.command) > >>> { > >>> $command | foreach-object {invoke-expression $_} > >>> $logging = $info.data.$choice.$sub_choice.comment > >>> date | write-output | out-file $logs\foundation_log.txt -append > >>> write-output "$logging" "$command" -- | out-file > >>> $logs\foundation_log.txt > >>> -append > >>> } > >>> $command would be the following: > >>> <command>download ar.zip</command> > >>> <command>unzip ar.zip</command> > >>> <command>msiexec /i $unzip_location\acroread8.msi > >>> transforms=$unzip_location\acroread8.mst /lv $logs\ar.log > >>> /qn</command> > >>> download and unzip from above are other functions pulled from the > >>> xml > >>> file that do just that, download the file and unzip it to a > >>> directory. > >>> When my script runs command execute it displays the contents of the > >>> command element above. Funny thing is it runs the functions for the > >>> download and unzip properly but when it gets to the msiexec it > >>> displays it as if it were text. This also happens on executables > >>> that > >>> run installations. > >>> Hope I was clearer here? > >>> > >>> "Shay Levi" wrote: > >>> > >>>> Just curious, why XML? Why not scripts? With a script you can avoid > >>>> the parsing > >>>> and invoking actions, which I believe is also slower, and even run > >>>> parts > >>>> of code by > >>>> executing scriptblocks. > >>>> Anyway, what about a code snippet or errors description? It can > >>>> help > >>>> understand your situation. > >>>> Shay > >>>> http://scriptolog.blogspot.com > >>>>> I have an xml file that I am parsing with powershell. The xml file > >>>>> contains functions, variables and commands that are being parsed > >>>>> to perform a task. I have an issue now where a function in the xml > >>>>> file executes a set of commands (an array) using > >>>>> invoke-expression. When I run this in powershell it takes the > >>>>> array and displays the command as text and I want it to execute > >>>>> the command. For example, I have the installation files for > >>>>> Acrobat Reader in a folder and one of the commands from my xml > >>>>> file is: msiexec acroread.msi....transform=...., and then a second > >>>>> command will open a pdf in acrobat reader. When my script runs is > >>>>> displays the msiexec command instead of launching the installer. I > >>>>> have the same problem with executables that I am installing. I > >>>>> have tried dot sourcing and I know my install commands are correct > >>>>> becuase I can run them outside of my script and it works as > >>>>> expected. > >>>>> > >>>>> I hope I am clear enough, and I would be willing to post the > >>>>> contents of my files if it would help. > >>>>> > >>>>> This is kind of a continuation of the post below when I was trying > >>>>> to find > >>>>> > >>>>> out how to parse the xml file and run the commands: > >>>>> > >>>>> http://www.microsoft.com/communities.../en-us/default > >>>>> . a sp > >>>>> x?dg=microsoft.public.windows.powershell&tid=e6cc707d-a501-4eb2-bd > >>>>> 9 9 -e 06562a05773&p=1 > >>>>> > >>>>> Thanks for any help that you may have for me. > >>>>> > > |
My System Specs![]() |
| | #9 (permalink) |
| | Re: executing commands from an xml file Good Luck Shay http://scriptolog.blogspot.com Quote: > I will not be able to test this till the end of today. I will know > soon and post back for you. > > "Shay Levi" wrote: > Quote: >> Brett, were you able to resolve it? >> >> Shay >> http://scriptolog.blogspot.com Quote: >>> Can you integrate this and see if the cmd.exe is executing? >>> >>> <command>cmd /k echo executing</command> >>> >>> Shay >>> http://scriptolog.blogspot.com >>>> What happens if you use the & operator instead of >>>> invoke-expression? >>>> >>>> & $_ >>>> & {$_} >>>> & "$_" >>>> Shay >>>> http://scriptolog.blogspot.com >>>>> I am trying to use powershell to automate some tasks that we do at >>>>> our office. Basic stuff like install acrobat reader, create user >>>>> in AD, etc... Here is the process for my powerhshell "program". >>>>> Out IT staff will goto an internal website and download a >>>>> powershell script with when run creates a few variables and >>>>> downloads this xml file. The xml file contains a menu (for stupid >>>>> proofing), variables, functions, installation commands, dsadd's, >>>>> etc... I chose the xml file becase I could have everything in one >>>>> place as opposed to our current structure with a bunch of scripts. >>>>> When I make a change to the XML file it takes affect the next time >>>>> the script is run. >>>>> >>>>> Here is the function that I am having the problem with: >>>>> >>>>> function command_execute >>>>> >>>>> ($command = $info.data.$choice.$sub_choice.command) >>>>> { >>>>> $command | foreach-object {invoke-expression $_} >>>>> $logging = $info.data.$choice.$sub_choice.comment >>>>> date | write-output | out-file $logs\foundation_log.txt -append >>>>> write-output "$logging" "$command" -- | out-file >>>>> $logs\foundation_log.txt >>>>> -append >>>>> } >>>>> $command would be the following: >>>>> <command>download ar.zip</command> >>>>> <command>unzip ar.zip</command> >>>>> <command>msiexec /i $unzip_location\acroread8.msi >>>>> transforms=$unzip_location\acroread8.mst /lv $logs\ar.log >>>>> /qn</command> >>>>> download and unzip from above are other functions pulled from the >>>>> xml >>>>> file that do just that, download the file and unzip it to a >>>>> directory. >>>>> When my script runs command execute it displays the contents of >>>>> the >>>>> command element above. Funny thing is it runs the functions for >>>>> the >>>>> download and unzip properly but when it gets to the msiexec it >>>>> displays it as if it were text. This also happens on executables >>>>> that >>>>> run installations. >>>>> Hope I was clearer here? >>>>> "Shay Levi" wrote: >>>>> >>>>>> Just curious, why XML? Why not scripts? With a script you can >>>>>> avoid >>>>>> the parsing >>>>>> and invoking actions, which I believe is also slower, and even >>>>>> run >>>>>> parts >>>>>> of code by >>>>>> executing scriptblocks. >>>>>> Anyway, what about a code snippet or errors description? It can >>>>>> help >>>>>> understand your situation. >>>>>> Shay >>>>>> http://scriptolog.blogspot.com >>>>>>> I have an xml file that I am parsing with powershell. The xml >>>>>>> file contains functions, variables and commands that are being >>>>>>> parsed to perform a task. I have an issue now where a function >>>>>>> in the xml file executes a set of commands (an array) using >>>>>>> invoke-expression. When I run this in powershell it takes the >>>>>>> array and displays the command as text and I want it to execute >>>>>>> the command. For example, I have the installation files for >>>>>>> Acrobat Reader in a folder and one of the commands from my xml >>>>>>> file is: msiexec acroread.msi....transform=...., and then a >>>>>>> second command will open a pdf in acrobat reader. When my script >>>>>>> runs is displays the msiexec command instead of launching the >>>>>>> installer. I have the same problem with executables that I am >>>>>>> installing. I have tried dot sourcing and I know my install >>>>>>> commands are correct becuase I can run them outside of my script >>>>>>> and it works as expected. >>>>>>> >>>>>>> I hope I am clear enough, and I would be willing to post the >>>>>>> contents of my files if it would help. >>>>>>> >>>>>>> This is kind of a continuation of the post below when I was >>>>>>> trying to find >>>>>>> >>>>>>> out how to parse the xml file and run the commands: >>>>>>> >>>>>>> http://www.microsoft.com/communities...st/en-us/defau >>>>>>> lt . a sp >>>>>>> x?dg=microsoft.public.windows.powershell&tid=e6cc707d-a501-4eb2- >>>>>>> bd 9 9 -e 06562a05773&p=1 >>>>>>> >>>>>>> Thanks for any help that you may have for me. >>>>>>> |
My System Specs![]() |
| | #10 (permalink) |
| | Re: executing commands from an xml file I believe that your response will fix my problem. I have to change more than I thought in my xml file to test this out. I forgot about the command versus expression mode, the part that I will have to rework is changing some of my command elements in the xml file to process in expression mode becase they are powershell functions. Thanks again. "Shay Levi" wrote: Quote: > Good Luck > > Shay > http://scriptolog.blogspot.com > > > Quote: > > I will not be able to test this till the end of today. I will know > > soon and post back for you. > > > > "Shay Levi" wrote: > > Quote: > >> Brett, were you able to resolve it? > >> > >> Shay > >> http://scriptolog.blogspot.com > >>> Can you integrate this and see if the cmd.exe is executing? > >>> > >>> <command>cmd /k echo executing</command> > >>> > >>> Shay > >>> http://scriptolog.blogspot.com > >>>> What happens if you use the & operator instead of > >>>> invoke-expression? > >>>> > >>>> & $_ > >>>> & {$_} > >>>> & "$_" > >>>> Shay > >>>> http://scriptolog.blogspot.com > >>>>> I am trying to use powershell to automate some tasks that we do at > >>>>> our office. Basic stuff like install acrobat reader, create user > >>>>> in AD, etc... Here is the process for my powerhshell "program". > >>>>> Out IT staff will goto an internal website and download a > >>>>> powershell script with when run creates a few variables and > >>>>> downloads this xml file. The xml file contains a menu (for stupid > >>>>> proofing), variables, functions, installation commands, dsadd's, > >>>>> etc... I chose the xml file becase I could have everything in one > >>>>> place as opposed to our current structure with a bunch of scripts. > >>>>> When I make a change to the XML file it takes affect the next time > >>>>> the script is run. > >>>>> > >>>>> Here is the function that I am having the problem with: > >>>>> > >>>>> function command_execute > >>>>> > >>>>> ($command = $info.data.$choice.$sub_choice.command) > >>>>> { > >>>>> $command | foreach-object {invoke-expression $_} > >>>>> $logging = $info.data.$choice.$sub_choice.comment > >>>>> date | write-output | out-file $logs\foundation_log.txt -append > >>>>> write-output "$logging" "$command" -- | out-file > >>>>> $logs\foundation_log.txt > >>>>> -append > >>>>> } > >>>>> $command would be the following: > >>>>> <command>download ar.zip</command> > >>>>> <command>unzip ar.zip</command> > >>>>> <command>msiexec /i $unzip_location\acroread8.msi > >>>>> transforms=$unzip_location\acroread8.mst /lv $logs\ar.log > >>>>> /qn</command> > >>>>> download and unzip from above are other functions pulled from the > >>>>> xml > >>>>> file that do just that, download the file and unzip it to a > >>>>> directory. > >>>>> When my script runs command execute it displays the contents of > >>>>> the > >>>>> command element above. Funny thing is it runs the functions for > >>>>> the > >>>>> download and unzip properly but when it gets to the msiexec it > >>>>> displays it as if it were text. This also happens on executables > >>>>> that > >>>>> run installations. > >>>>> Hope I was clearer here? > >>>>> "Shay Levi" wrote: > >>>>> > >>>>>> Just curious, why XML? Why not scripts? With a script you can > >>>>>> avoid > >>>>>> the parsing > >>>>>> and invoking actions, which I believe is also slower, and even > >>>>>> run > >>>>>> parts > >>>>>> of code by > >>>>>> executing scriptblocks. > >>>>>> Anyway, what about a code snippet or errors description? It can > >>>>>> help > >>>>>> understand your situation. > >>>>>> Shay > >>>>>> http://scriptolog.blogspot.com > >>>>>>> I have an xml file that I am parsing with powershell. The xml > >>>>>>> file contains functions, variables and commands that are being > >>>>>>> parsed to perform a task. I have an issue now where a function > >>>>>>> in the xml file executes a set of commands (an array) using > >>>>>>> invoke-expression. When I run this in powershell it takes the > >>>>>>> array and displays the command as text and I want it to execute > >>>>>>> the command. For example, I have the installation files for > >>>>>>> Acrobat Reader in a folder and one of the commands from my xml > >>>>>>> file is: msiexec acroread.msi....transform=...., and then a > >>>>>>> second command will open a pdf in acrobat reader. When my script > >>>>>>> runs is displays the msiexec command instead of launching the > >>>>>>> installer. I have the same problem with executables that I am > >>>>>>> installing. I have tried dot sourcing and I know my install > >>>>>>> commands are correct becuase I can run them outside of my script > >>>>>>> and it works as expected. > >>>>>>> > >>>>>>> I hope I am clear enough, and I would be willing to post the > >>>>>>> contents of my files if it would help. > >>>>>>> > >>>>>>> This is kind of a continuation of the post below when I was > >>>>>>> trying to find > >>>>>>> > >>>>>>> out how to parse the xml file and run the commands: > >>>>>>> > >>>>>>> http://www.microsoft.com/communities...st/en-us/defau > >>>>>>> lt . a sp > >>>>>>> x?dg=microsoft.public.windows.powershell&tid=e6cc707d-a501-4eb2- > >>>>>>> bd 9 9 -e 06562a05773&p=1 > >>>>>>> > >>>>>>> Thanks for any help that you may have for me. > >>>>>>> > > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Executing PS1 file with AD MS cmdlets | PowerShell | |||
| Error executing file, help ! | Vista General | |||
| Error executing file | Vista General | |||
| Error Executing File | Vista General | |||
| PS script prints output instead of executing commands | PowerShell | |||