Solved

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

Posted on 2014-12-14
3
228 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
A procedure for exporting installed hotfix details of remote computers using 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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

706 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

13 Experts available now in Live!

Get 1:1 Help Now