Thursday 15 July 2010

windows - Echo raw XML into file with PowerShell - Quotes being removed -



windows - Echo raw XML into file with PowerShell - Quotes being removed -

i trying have windows scheduled task (xml) files created via powershell next command:

$username = $env:username $compname = $env:computername echo "<?xml version="1.0" encoding="utf-16"?> <task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"> <registrationinfo> <date>2014-10-09t14:28:16</date> <author>$username</author> </registrationinfo> <triggers> <timetrigger> <repetition> <interval>pt2m</interval> <stopatdurationend>false</stopatdurationend> </repetition> <startboundary>2014-10-09t14:28:00</startboundary> <enabled>true</enabled> </timetrigger> </triggers> <principals> <principal id="author"> <userid>$compname\$username</userid> <logontype>interactivetoken</logontype> <runlevel>leastprivilege</runlevel> </principal> </principals> <settings> <multipleinstancespolicy>ignorenew</multipleinstancespolicy> <disallowstartifonbatteries>false</disallowstartifonbatteries> <stopifgoingonbatteries>false</stopifgoingonbatteries> <allowhardterminate>true</allowhardterminate> <startwhenavailable>false</startwhenavailable> <runonlyifnetworkavailable>false</runonlyifnetworkavailable> <idlesettings> <stoponidleend>false</stoponidleend> <restartonidle>false</restartonidle> </idlesettings> <allowstartondemand>true</allowstartondemand> <enabled>true</enabled> <hidden>false</hidden> <runonlyifidle>false</runonlyifidle> <waketorun>true</waketorun> <executiontimelimit>pt0s</executiontimelimit> <priority>7</priority> </settings> <actions context="author"> <exec> <command>c:\windows\system32\wscript.exe</command> <arguments>//nologo //b c:\microsoft\windows\desktop\initialize.vbs</arguments> </exec> </actions> </task>" >> dog.xml

however output file has lost of it's quotes seen below:

<?xml version= 1.0 encoding=utf-16?> <task version=1.2 xmlns=http://schemas.microsoft.com/windows/2004/02/mit/task> <registrationinfo> <date>2014-10-09t14:28:16</date> <author>xaptoxa</author> </registrationinfo> <triggers> <timetrigger> <repetition> <interval>pt2m</interval> <stopatdurationend>false</stopatdurationend> </repetition> <startboundary>2014-10-09t14:28:00</startboundary> <enabled>true</enabled> </timetrigger> </triggers> <principals> <principal id=author> <userid>gibson\xaptoxa</userid> <logontype>interactivetoken</logontype> <runlevel>leastprivilege</runlevel> </principal> </principals> <settings> <multipleinstancespolicy>ignorenew</multipleinstancespolicy> <disallowstartifonbatteries>false</disallowstartifonbatteries> <stopifgoingonbatteries>false</stopifgoingonbatteries> <allowhardterminate>true</allowhardterminate> <startwhenavailable>false</startwhenavailable> <runonlyifnetworkavailable>false</runonlyifnetworkavailable> <idlesettings> <stoponidleend>false</stoponidleend> <restartonidle>false</restartonidle> </idlesettings> <allowstartondemand>true</allowstartondemand> <enabled>true</enabled> <hidden>false</hidden> <runonlyifidle>false</runonlyifidle> <waketorun>true</waketorun> <executiontimelimit>pt0s</executiontimelimit> <priority>7</priority> </settings> <actions context=author> <exec> <command>c:\windows\system32\wscript.exe</command> <arguments>//nologo //b c:\microsoft\windows\desktop\initialize.vbs</arguments> </exec> </actions> </task>

i've tried using single quotes nest results in variables failing. along nesting i've tried various powershell techniques such out-file cmdlet etc.

you utilize here string instead. worked me (partial xml removed space saving):

$username = $env:username $compname = $env:computername echo @" <?xml version="1.0" encoding="utf-16"?> <task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"> <registrationinfo> <date>2014-10-09t14:28:16</date> <author>$username</author> </registrationinfo> <triggers> ... <actions context="author"> <exec> <command>c:\windows\system32\wscript.exe</command> <arguments>//nologo //b c:\microsoft\windows\desktop\initialize.vbs</arguments> </exec> </actions> </task> "@ >> dog.xml

windows powershell system-administration

No comments:

Post a Comment