Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

need to read from text file & write another batch file with some text

$
0
0

I have powershell script that export folder names to text file. then search for one file in all that folders, if found delete it. need to create batch file with some other text as well as folder names. it shoild run as loop ( for folders listed in text file)

batch file codeshould be like this ( xyz is folder name)

d:\mainfolder\xyz\bin\abc.exe -e d:\mainfolder\backup\xyz.xml

Pleas see below code, please check & correct me

#============================================
# need to run from main folder only
#============================================

$path = Get-Location
$spath ="$path\"
$lpath = "\C8\configuration"
$epath = "\c8\bin\cogconfigw.exe -e "

New-Item -Path $path\Backup -ItemType directory -ErrorAction SilentlyContinue
$bpath = "$path\Backup "

#===========================================================================================================
#export eBO folder list in text file
Get-ChildItem | select Name | Where {$_.name -like "*eBO841*"} | Out-File $path\list.txt
#===========================================================================================================
#read one by one line from text file & delete cogstartup.lock
$lines=Get-Content $path\list.txt

$lines |
ForEach-Object {
Get-ChildItem $path\"$_."\$lpath $filePath -ErrorAction SilentlyContinue | Where-Object { ($_.PSIsContainer -eq $false) -and ( $_.Name -like "cogstartup.lock") } | remove-item
}
#===========================================================================================================
issue with below code only ( looping issue &
# run cogconfigw.exe
$nlines=Get-Content $path\list.txt | Where {$_.name -like "eBO841*"}
$nlines |
ForEach-object {
$nitem = "$nlines.$_."

"$spath"+"$nitem"+"$epath"+"$path"+"$nitem" | Out-File $path\run.bat

}

#============================================================================================================

its giving output in batch file as below
D:\mainfolder\\c8\bin\cogconfigw.exe -e D:\mainfolder


Viewing all articles
Browse latest Browse all 6937

Trending Articles