Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - executing commands from an xml file

Reply
 
Old 09-14-2007   #1 (permalink)
Brett


 
 

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 SpecsSystem Spec
Old 09-14-2007   #2 (permalink)
Shay Levi


 
 

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 SpecsSystem Spec
Old 09-14-2007   #3 (permalink)
Brett


 
 

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 SpecsSystem Spec
Old 09-14-2007   #4 (permalink)
Brett


 
 

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 SpecsSystem Spec
Old 09-14-2007   #5 (permalink)
Shay Levi


 
 

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 SpecsSystem Spec
Old 09-14-2007   #6 (permalink)
Shay Levi


 
 

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 SpecsSystem Spec
Old 09-17-2007   #7 (permalink)
Shay Levi


 
 

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 SpecsSystem Spec
Old 09-17-2007   #8 (permalink)
Brett


 
 

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 SpecsSystem Spec
Old 09-17-2007   #9 (permalink)
Shay Levi


 
 

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 SpecsSystem Spec
Old 09-18-2007   #10 (permalink)
Brett


 
 

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 SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46