I use PowerShell to write batch files for execution. As a result, I need to
make sure they are ascii files or they will not execute. I use the -encoding
ascii all the time, is it possible to make this a default, ie:
write-output "string" | out-file -encoding ascii -append test.bat
There really isn't a way to change the way the Cmdlet works, but if
this is something you do a lot, a function might be a good way to go:
function Append-Batch( [string] $filename, [string] $command )
{
process
{
$_ | Out-File -FilePath $filename -Append -Encoding Ascii
}
end
{
$command | Out-File -FilePath $filename -Append -Encoding
Ascii
}
}
PSH$ Append-Batch test.bat "@echo off"
PSH$ 'if not "%1"=="" echo %1' | Append-Batch test.bat
PSH$ Get-Content test.bat
@echo off
if not "%1"=="" echo %1
PSH$ .\test.bat howdy
howdy
Jeff
Well if you're willing to run the v2 CTP, this might be possible. I've
not been able to get out-file working, but I think it is just a matter
of time.
You would create a scriptcmdlet, but you'd also have to likely redefine
all of the parameters you might ever use.
Marco
--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp
PowerGadgets MVP
http://www.powergadgets.com/mvp
Thanks!
PS Kiron: Email me marcoDOTshawATgmailDOTcom