0

I am new to PowerShell scripting and as I was trying to execute the command present inside the XML tag through PowerShell script, I am getting that command printed as a text rather than being executed.

<Task>
    <RegistrationInfo>
        <URI>\Power\Test</URI>
    </RegistrationInfo>
    <Principals>
        <Principal id="Author">
            <UserId>S-1-5-21-928065147-2950777667-2078638527-1001</UserId>
            <LogonType>InteractiveToken</LogonType>
        </Principal>
    </Principals>
    <Settings>
        <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
        <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
        <Enabled>false</Enabled>
        <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
        <IdleSettings>
            <Duration>PT10M</Duration>
            <WaitTimeout>PT1H</WaitTimeout>
            <StopOnIdleEnd>true</StopOnIdleEnd>
            <RestartOnIdle>false</RestartOnIdle>
        </IdleSettings>
    </Settings>
    <Triggers>
        <CalendarTrigger>
            <StartBoundary>2017-02-13T17:30:00+05:30</StartBoundary>
            <ScheduleByDay>
                <DaysInterval>1</DaysInterval>
            </ScheduleByDay>
        </CalendarTrigger>
    </Triggers>
    <Actions Context="Author">
        <Exec>
            <Command>notepad.exe</Command>
        </Exec>
    </Actions>
</Task>

And when I try the below mentioned PS script I am not getting the desired output.

 $xml = [xml](Get-Content "C:\Users\ACER\Desktop\Test.xml")
 $xml
 $xml.Task
 $xml.Task.Actions.Exec.Command
JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
Ricky
  • 35
  • 1
  • 1
  • 7
  • 2
    Possible duplicate of [Executing a Command stored in a Variable from Powershell](http://stackoverflow.com/questions/3592851/executing-a-command-stored-in-a-variable-from-powershell) – Ansgar Wiechers Feb 17 '17 at 13:24
  • Use the call operator if the node contains just a command. Use `Invoke-Expression` if the node contains an entire commandline (command with parameters/arguments). – Ansgar Wiechers Feb 17 '17 at 13:26
  • It worked, Thank you :) – Ricky Feb 19 '17 at 06:52

0 Answers0