Packer - Windows Server 2012R2 - Install PowerShell 5 - powershell

I'm having trouble with installing PowerShell 5 on Windows Server 2012 R2 using Packer.
To install PowerShell 5.1, I'm using chocolatey
powershell
iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex
choco install PowerShell -y
I need to to do this for two packer builder:
Amazon Web Services EC2 AMI.
Hyper-V Vagrant.
With the Amazon Web Services EC2 AMI I've tried executing the above from the following locations
As part of the user_data_file script.
As an inline provision script.
I've added the windows-restart provision in the flow after the execution of the fragment.
Similarly I've tried the same with the Hyper-V Vagrant both as part of the Autounattend flow and as an inline provision.
In both cases the installation fails because the user profile is not created. At least I think that is the problem. As a reference, I've faced the exact same problem when installing sql server express.
Has anyone managed to accomplish this flow and what is your recommendation?

PowerShell package uses MSU (Windows Update file). There are a couple of considerations here:
Ensure Windows Updates Service is turned on. Chocolatey doesn't do that yet, although there is an issue filed.
MSUs must be run locally from the machine. So if you are running over WinRM, you instead need to have it set up a scheduled task to call choco install and then run it that way.
Yes, that second point is accurate. No, it is not Chocolatey's fault. That's a Microsoft design decision with MSU files. It's a real PITA.
FYI - BoxStarter handles it appropriately, and it can be used with Packer. You will find less pain if you look there.
HTH

Related

AzurePS System capability is not available on a newly installed vsts-agent

I have successfully installed a new VSTS agent on a new Azure VM - Windows Server 2012 R2 (64bit). When I am try to execute any pipelines containing azure powershell tasks on the new vsts agent, I get an error message :-
Error message 'No agent found in pool BuildAgent2 which satisfies the specified demands:azureps Agent.Version -gtVersion 2.119.1'
Is there any way to add AzurePS as a system capability ?
Please advise on the steps to do this - thanks.
AzurePS System capability is not available on a newly installed vsts-agent
Agree with jessehouwing.
If you want to enable AzurePS System capability, you could install the PowerShell 5.1 or higher on Windows, or PowerShell Core 6.x and later on all platforms, then install/update the Azure PowerShell module on the Azure VM:
Install the Azure PowerShell module
But the error you got should more related to the demands you set on the option tab of your build :
Check the agent version you have installed, make sure you set the correct version, or you can try to remove that demands to check if you still have this issue.
Hope this helps.
I got the same error using the AzureFileCopy#4 task in a self-hosted agent, but I solved it by installing the az module https://www.powershellgallery.com/packages/Az
Install-Module -Name Az

Best practice for uninstalling software with PowerShell

Like a lot of other applications out there the BlueJeans Desktop App MSI comes in two flavours: Per User MSI & Per Machine MSI.
Today, it is possible to have both installed on the same machine, but I have an increasing number of customers who have users with both installed and want to be able to clean it up. I have put together a cleanup script that handles uninstalling our application, but what I need to know from the community is whether I should utilize PowerShell to connect to each machine and run the script remotely or deploy the script via SCCM, IBM BigFix etc. to each machine and run the script locally?
A copy of my script can be found here: https://github.com/stuartminch/powershell/blob/master/cleanup_utility.ps1
If you have two separate MSI installers (User MSI & Per Machine MSI) the easiest way would be to use MSI {GUID} to uninstall them.
example msiexec.exe /x {GUID} /q
If you have them installed on a machine you can find uninstall string with GUID under
"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall{GUID}\UninstallString
You can then configure it in SCCM.
Best practice would be to configure the deployment along with uninstall so if you deployed it through SCCM just add Uninstall commands there.

FailoverClusters module is not getting listed while running the cmdlet Get-Module -ListAvailable

I tried below command
Get-Module -ListAvailable
But it did not showed me "FailoverClusters" in the list
From where I can download this module? Do I have to install any SDK?
Note: I do not want to install Azure SDK. Is there any other way?
Update
I am using my local windows 10 to remote connect to the Azure Virtual Machine (Windows Server 2012 R2). I do want to manage all configurations using powershell from my local windows 10 machine.
As jisaak already explained, the FailoverClusters module is installed when you install the Failover Clustering feature on a Windows Server.
If, however, you want to manage a cluster from a computer without the Failover Clustering feature installed, this is what you do:
Download the appropriate version of Remote Server Administration Tools
Run the installer
Navigate to the Programs and Features control panel pane (run appwiz.cpl)
Choose "Turn Windows Features on or off"
Find the "Failover Cluster Management" feature under Remote Server Administration Tools
Enable it
Voila
The FailoverClusters Windows PowerShell module is installed on the
computer with the Failover Clustering feature
Source
Install the Failover Clustering Feature

Can I install WIndows Management Framework 3 on WS 2008 r2 using PowerShell

Can I use PowerShell to script an install of this? I already use module PSWindowsUpdate and would like to install KB2506143-x86 but it is not available as an update in get-WUInstall -KBArticleID. Need to run this on hundreds of machines and would like to avoid manually updating each from a browser.
Many thanks,
I think this is not possible due to
Close all Windows PowerShell windows.
paragraph in install instructions.
Microsoft makes a supported product to correctly deal with your problem, why are you trying to solve it with a homebrewed script?

Automated deployment using VMware powercli

We are having build environment where we did not use any tools like Cruise control , TFS or buildforge.
We are purely depend upon Msbuild and powershell. We decided to automate the deployment process.
As we are using VMWare ESXi to meet our Virtual machine needs. We decided to use VMWare powercli to automate deployment process.
After build is over , VMware powercli will revert the snapshot of VM to fresh state and we tried using Invoke-VMScript to do automated deployment.
But as our deployment has UI , this is nearly impossible as Powercli try to invoke UI in session 0 and it doesn't support UI application.
Does any body overcome this problem and installed your application successfully in Virtual machine?
I have some experience in the area. I use PowerCLI and Windows Remote to get the job done. I have a machine with VMWare snapshot where windows remoting is activated and configured and then I use PowerCLI to revert to snapshot and power the machine on and then I call Invoke-Command. Not sure if it will survive the UI thing, but worth a try. First make sure that you can execute your task from PowerShell and if yes - then windows remouting will most probably be able to do it as well. You can read how to configure Windows Remouting here:
http://amarchuk.blogspot.com/2011/10/windows-remoting-and-powershell.html