Converting simple batch file to PowerShell

USGLOBAL
USGLOBAL used Ask the Experts™
on
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

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
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?

Author

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

Author

Commented:
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.
"Batchelor", Developer and EE Topic Advisor
Top Expert 2015
Commented:
PowerShell interprets anything starting with a digit as a number. Just type
   4+4
and you will see what I mean.
You can call a tool starting with a digit e.g. by using
  . "4print" -1 -u -fn -s -loren -mf -olpt1: C:\testfolder\ugsu1005

BTW, the sequence
echo ftp download...
echo off
cls

Open in new window

doesn't make much sense - the text echoed is wiped out immediately ;-). And echo off has special meaning of switching off automated echoing of commands as they are executed, so you won't translate that into PowerShell.

echo, erase and copy are implemented as aliases, as already mentioned, so you would not even need to "translate" those. If you are interested in the correct replacement, call
  alias echo
and so on. That will show which PowerShell cmdlet is called when using that alias.
If you want to know more about a cmdlet (= PowerShell command), use something like
  get-help write-host
for a short summary, or
  get-help write-host -full
for a full-fleshed description including examples.

If you really want to dive into PowerShell, you will need to get accustomed to using objects and pipelined processing. There are some articles here on EE to give you a start, and one of them is http://www.experts-exchange.com/A_3296-The-Absolute-Beginner's-Guide-to-Powershell.html .

Author

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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial