Solved

moving to powershell from dos batch - tutorial / starter advice?

Posted on 2014-12-14
3
242 Views
Last Modified: 2014-12-28
In an other question about stepping through a dos batch file, an expert said

Nowadays you should take the leap to switch to PowerShell.

Got me thinking - I've been making dos batch files since DOS, so I guess I should learn a new skill?

anyone got tips on how to start?  
Is being able to run power shell native to win 7?  XP?  I thought there was something you had to install to get PS to run on a PC? Or maybe just for XP?

What's the extension?

This would empty the windows temp folder, what would it look like as a powershell script?  ANd to run that, you just double click on the file?

Rem Clean windows temp folder
set folder=%windir%\temp
for /f "delims=" %%a in ('dir/ad/b %folder%\*') do (rd /s /q "%folder%\%%a")
del %folder%\*.* /q

 Thanks!
0
Comment
  • 2
3 Comments
 
LVL 34

Assisted Solution

by:Dan Craciun
Dan Craciun earned 167 total points
ID: 40499145
>>Is being able to run power shell native to win 7? yes, v2. You can get v3 with WinRM

>>XP, no, but you can install WinRM

>>What's the extension? ps1

>>you just double click on the file? not by default. double click will open the file for editing.

$folder=$env:windir + "\temp"
gci $folder -Recurse | %{Remove-Item $_.Fullname -Force}

Open in new window


HTH,
Dan
0
 
LVL 68

Assisted Solution

by:Qlemo
Qlemo earned 333 total points
ID: 40499272
Or, much more simple, just
remove-item -recurse $env:Windir\Temp\*

Open in new window

0
 
LVL 68

Accepted Solution

by:
Qlemo earned 333 total points
ID: 40499281
In regard of some resources:
I recommend to read the EE articles in the PowerShell TA to get an idea how it works.
Make intense use of get-help -detailed for cmdlets you need to know something about.
Get a list of commands which might apply by using e.g. get-command *item*.
Have a look at blogs.technet.com/b/heyscriptingguy/ for some simple, real-life code snippets with explanation.
Subscribe to questions posted in PowerShell here.
And, of course, there is a lot of more out there.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Synchronize a new Active Directory domain with an existing Office 365 tenant
This article will help you understand what HashTables are and how to use them in PowerShell.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now