Zi’s Blog


Text-xml

Posted in Tips n Tricks by zimakki on the July 24th, 2008

Just stumbled on this cool PowerShell method. Below is are a couple of examples of how I see myself using it:

73> ni -type file -value “<crap></xml>” -name “crap.xml”

    Directory: Microsoft.PowerShell.Core\FileSystem::C:\projects\depot\Test

Mode           LastWriteTime       Length Name
—-           ————-       —— —-
-a—    24/07/2008    19:36           12 crap.xml

74> test-xml .\crap.xml
False
75> ni -type file -value “<hello></hello>” -name “valid.xml”

    Directory: Microsoft.PowerShell.Core\FileSystem::C:\projects\depot\Test

Mode           LastWriteTime       Length Name
—-           ————-       —— —-
-a—    24/07/2008    19:37           15 valid.xml

76> test-xml .\valid.xml
True
77> test-xml .\crap.xml -ErrorVariable
Test-Xml : Missing an argument for parameter ‘ErrorVariable’. Specify a parameter of type ‘System.String’ and try again.
At line:1 char:35

+ test-xml .\crap.xml -ErrorVariable <<<<

 

This will help me out when I fiddling around with all the nAnt build scripts I seem to be playing with these days!

 

Technorati Tags: