Showing posts with label PowerShell. Show all posts
Showing posts with label PowerShell. Show all posts

Sunday, 29 March 2015

How to update Chocolatey

I’ve recently started using Chocolatey - a package manager for Windows – to install tools and applications. If you’re not familiar with Chocolatey it’s described thus:

“Chocolatey is a package manager for Windows (like apt-get or yum but for Windows). It was designed to be a decentralized framework for quickly installing applications and tools that you need. It is built on the NuGet infrastructure currently using PowerShell as its focus for delivering packages from the distros to your door, err computer.” [1]

Installing Chocolatey is easy and is explained on their homepage. But how do you upgrade Chocolatey to the latest version after you’ve installed?

Firstly, I opened a command prompt as administrator and ran Powershell - actually I used ConEmu which has a convenient tab for just this purpose. I then ran ‘chocolatey version’ to see what’s what.

choco001

Looks like there’s a new version. Let’s update. Doing so is just like updating anything with Chocolatey. Run the ‘chocolatey update’ passing in the package name; ‘chocolatey’ in this case.

choco002

I’ve truncated the console output but suffice is to say Chocolatey has been updated.

Refecences

[1] About Chocolatey

Monday, 23 January 2012

Counting lines of code

Not that it means a great deal every now and then you get asked for the number of lines of code in a project. Greg D answered a question on StackOverflow about this using PowerShell. I liked his answer a lot because it’s so simple. Here’s his line of PowerShell code:

(dir -include *.cs,*.xaml -recurse | select-string .).Count

Monday, 25 July 2011

Renaming files with PowerShell

Problem: I had a directory full of PDF files that needed renaming. Specifically, I had to remove part of each file name.

Solution: Let’s try PowerShell!

PowerShell has been sitting on my machine for ages but for some reason I haven’t got around to using it. This seemed like a great opportunity to get my feet wet and – happily - this example turned out to be very straight forward. Firstly, I discovered that PowerShell was installed to C:\WINDOWS\system32\windowspowershell\v1.0 and I checked that the directory was in my Path system environment variable.

I launched Console2  - it’s so much more fun than using the standard Windows command prompt – and changed directory to the one holding the files I wanted to rename. I then ran powershell.exe which brought up the PowerShell command prompt and used the following PowerShell command to rename the files in the current directory:

get-childitem *.pdf | foreach{rename-item $_ $_.Name.Replace("text to replace", "")}

 

Untitled 

 

That was it. The files were renamed replacing “text to replace” with an empty string.

References