Solved

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

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

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 69

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Set OWA language and time zone in Exchange for individuals, all users or per database.
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

786 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