Avatar of USGLOBAL
USGLOBAL
Flag for United States of America asked on

Converting simple batch file to PowerShell

I need this batch file process as a PowerShell script... Please..

echo ftp download...
echo off
cls
erase somefile1. 
erase somefile1.z
erase somefile2. 
erase somefile2.z
ftp -s:\testfolder\ftp.in
gzip -d somefile1
gzip -d somefile2

4print -1 -u -fn -s -loren -mf -olpt2: C:\testfolder\somefile2

Copy C:\DDC\somefile2 somefile2.txt

Open in new window


The ftp.in file is the information to log into the FTP server to download the files.

open ftp.anyserver.com
username
password
cd ftp_in
lcd C:\testfolder
binary
prompt n
get somefile1.Z
get somefile2.Z
bye

Open in new window

PowershellWindows Batch

Avatar of undefined
Last Comment
USGLOBAL

8/22/2022 - Mon
Brent Challis

You should be able to copy what yu have written in the batch file into a .ps1 file, simply changing echo to Write-Host, erase to Remove-Item and Copy to Copy-Item.  In fact in many cases there are DOS compatible aliases for the PowerShell cmdlets that perform the same tasks.  All external programs (the .exes) work in exactly the same way in PowerShell as they do in the DOS environment.

Is there some specific PowerShell functionality that you want to implement or are you simply wanting to move into the PowerShell world?
USGLOBAL

ASKER
Thank you for your input. My goal, ultimately, is to move into the PowerShell world. I will try your suggestion sometime today.
USGLOBAL

ASKER
Here is my PS1 script:
Write-Host ftp download...
Write-Host off
cls
Remove-Item somefile1. 
Remove-Item somefile1.z
Remove-Item somefile2. 
Remove-Item somefile2.z
ftp -s:\testfolder\ftp.in
gzip -d somefile1
gzip -d somefile2

4print -1 -u -fn -s -loren -mf -olpt1: C:\testfolder\ugsu1005

Copy-Item C:\testfolder\somefile2 somefile2.txt

Open in new window

And it returned this error:
Bad numeric constant: 4.
At C:\testfolder\test.ps1:12 char:2
+ 4 <<<< print -1 -u -fn -s -loren -mf -olpt1: C:\testfolder\somefile2
    + CategoryInfo          : ParserError: (4:String) [], ParseException
    + FullyQualifiedErrorId : BadNumericConstant

Open in new window

4PRINT is a DOS application that is in the path statement on the server the script is run on.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER CERTIFIED SOLUTION
Qlemo

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
USGLOBAL

ASKER
As always Qlemo has provided a correct solution to my problem!!