/build/static/layout/Breadcrumb_cap_w.png

Powershell script running in a batch file

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

 

Thanks!

 

 


0 Comments   [ + ] Show comments

Answers (1)

Posted by: SMal.tmcc 11 years ago
Red Belt
3

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

 

http://technet.microsoft.com/en-us/library/ee176828.aspx

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ