Hey all,

I have a small PS script I am trying to run in a batch file for the purpose of renaming a folder with in an applications configuration file. The end goal being that I would like to attach the batch file to the MSI I am building without having to run it seperatly.


Anyway, The batch file returns with the error: "Foreach-Object is not recognized as an internal or external command"

Here's the batch file it it's entierty, I'm hoping I just have a comma out of place or somthing:

echo off

powershell.exe -Command $username = $env:username;(get-content ${env:PROGRAMFILES(X86)}\Accumap\default.cfg)|;Foreach-Object {$_ -replace "useridfolder", "$username"}|;Set-Content ${env:PROGRAMFILES(X86)}\Accumap\default.cfg





0 Comments   [ - ] Hide Comments


Please log in to comment

Answer this question or Comment on this question for clarity



I believe you need a space after the pipe not a ;

powershell.exe -Command $username = $env:username;(get-content ${env:PROGRAMFILES(X86)}\Accumap\default.cfg)| Foreach-Object {$_ -replace "useridfolder", "$username"}| Set-Content ${env:PROGRAMFILES(X86)}\Accumap\default.cfg



Answered 11/05/2012 by: SMal.tmcc
Red Belt

Please log in to comment