Link to home
Start Free TrialLog in
Avatar of USGLOBAL
USGLOBALFlag 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

Avatar of Brent Challis
Brent Challis
Flag of Australia image

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?
Avatar of USGLOBAL

ASKER

Thank you for your input. My goal, ultimately, is to move into the PowerShell world. I will try your suggestion sometime today.
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.
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
As always Qlemo has provided a correct solution to my problem!!