dracoblue.net

PowerShell Community Extensions in Vagrant for Windows

Setting up windows machines with vagrant, is pretty good supported. To have less problems, you might want to use vagrant-windows plugin.

Since the windows version relies on Microsoft's PowerShell, you usually want to use the PowerShell Community Extensions.

To ensure that those are installed, you have to provision this package by using for instance puppet.

But, since pscx is only available as .zip-File, we need to install 7-Zip in first place.

Download the .msi-File from http://www.7-zip.org/download.html and put it into the files folder within the vagrant directory.

Define the package for 7-Zip in your puppet file:

package { '7-Zip 9.20 (x64 edition)':
     provider => "windows",
     source          => 'c:\vagrant\files\7z920-x64.msi',
     install_options => { 'INSTALLDIR' => 'C:\apps\7zip' },
     ensure => 'present'
}

It's very important to use 7-Zip 9.20 (x64 edition) as name of the package, since otherwise puppet can't find out if the package is already installed. Use the x86-Version if you have a 32bit system.

As soon as 7-Zip is available, we can add a dependency to install Pscx. First download the latest release (or your required one: it's Pscx 2.1.x for Windows 2008 Server!) from http://pscx.codeplex.com/releases.

Now define the Pscx-Package in your puppet file:

exec { "Pscx":
     cwd => "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\Modules\\",
     command => "c:\\apps\\7zip\\7z.exe x c:\\vagrant\\files\\Pscx-2.1.1.zip",
     creates => "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\Modules\\Pscx",
     require => [ Package['7-Zip 9.20 (x64 edition)'] ]
}

It's important to put Pscx into the folder c:\windows\system32\WindowsPowerShell\v1.0\Modules\Pscx, because otherwise PowerShell cannot find the module. You have to require the package of 7-Zip, to make sure that 7-Zip is available, before Pscx is unzipped.

In powershell, puppet, vagrant, windows by
@ 06 Dec 2013, Comments at Reddit & Hackernews

Give something back

Were my blog posts useful to you? If you want to give back, support one of these charities, too!

Report hate in social media Campact e.V. With our technology and your help, we protect the oceans from plastic waste. Gesellschaft fur Freiheitsrechte e. V. The civil eye in the mediterranean

Recent Dev-Articles

Read recently

Recent Files

About