Failure Installing DotNet 4.6.1 via Chocolatey using DSC cChocoPackageInstaller - azure

I'm attempting to set up a server Windows 2012 R2 in Azure via ARM templates and DSC. The DSC script runs the cChocoPackageInstaller to install dotnet4.6.1 (after running the cChocoInstaller). It looks like this:
cChocoInstaller Choco
{
InstallDir = "c:\choco"
}
cChocoPackageInstaller DotNet461
{
Name = "dotnet-461"
DependsOn = "[cChocoInstaller]Choco"
}
The DotNet installer is downloaded but it ultimately fails when it is run. The log looks like this (I've excerpted just the errors here).
2016-06-17 13:05:52,001 [DEBUG] - Running 'Start-ChocolateyProcessAsAdmin' with exeToRun:'C:\Windows\system32\config\systemprofile\AppData\Local\Temp\chocolatey\dotnet-461\4.6.01055.006\NDP461-KB3102436-x86-x64-AllOS-ENU.exe', statements: '/q /norestart /log "C:\Windows\system32\config\systemprofile\AppData\Local\Temp\chocolatey\net461.log" '
2016-06-17 13:05:52,001 [DEBUG] - Elevating Permissions and running ["C:\Windows\system32\config\systemprofile\AppData\Local\Temp\chocolatey\dotnet-461\4.6.01055.006\NDP461-KB3102436-x86-x64-AllOS-ENU.exe" /q /norestart /log "C:\Windows\system32\config\systemprofile\AppData\Local\Temp\chocolatey\net461.log" ]. This may take a while, depending on the statements.
2016-06-17 13:05:52,110 [DEBUG] - Setting RunAs for elevation
2016-06-17 13:05:53,487 [INFO ] - The application cannot find one of its required files, possibly
2016-06-17 13:05:53,487 [INFO ] -
2016-06-17 13:05:53,487 [INFO ] - because it was unable to create it in the folder. Please make
2016-06-17 13:05:53,487 [INFO ] -
2016-06-17 13:05:53,487 [INFO ] - sure that the folder in which this application was downloaded is
2016-06-17 13:05:53,487 [INFO ] -
2016-06-17 13:05:53,487 [INFO ] - accessible and not read-only.
2016-06-17 13:05:53,487 [INFO ] -
2016-06-17 13:05:53,503 [DEBUG] - Command ["C:\Windows\system32\config\systemprofile\AppData\Local\Temp\chocolatey\dotnet-461\4.6.01055.006\NDP461-KB3102436-x86-x64-AllOS-ENU.exe" /q /norestart /log "C:\Windows\system32\config\systemprofile\AppData\Local\Temp\chocolatey\net461.log" ] exited with '3'.
2016-06-17 13:05:53,518 [ERROR] - ERROR: Running ["C:\Windows\system32\config\systemprofile\AppData\Local\Temp\chocolatey\dotnet-461\4.6.01055.006\NDP461-KB3102436-x86-x64-AllOS-ENU.exe" /q /norestart /log "C:\Windows\system32\config\systemprofile\AppData\Local\Temp\chocolatey\net461.log" ] was not successful. Exit code was '3'. See log for possible error messages.
2016-06-17 13:05:53,518 [DEBUG] - Built-in PowerShell host called with ['[System.Threading.Thread]::CurrentThread.CurrentCulture = '';[System.Threading.Thread]::CurrentThread.CurrentUICulture = ''; & import-module -name 'c:\choco\helpers\chocolateyInstaller.psm1'; & 'c:\choco\helpers\chocolateyScriptRunner.ps1' -packageScript 'c:\choco\lib\dotnet-461\tools\chocolateyInstall.ps1' -installArguments '' -packageParameters '''] exited with '3'.
2016-06-17 13:05:53,534 [DEBUG] - Calling command ['"C:\Windows\System32\shutdown.exe" /a']
2016-06-17 13:05:53,549 [DEBUG] - Command ['"C:\Windows\System32\shutdown.exe" /a'] exited with '1116'
So a couple of things:
No log file is produced for the DotNet installer...so it doesn't look like it's successfully launching the installer.
The installer package is definitely downloaded to the expected location. Not sure why it would be able to download the installer to this directory but then later not access/run it.
If I RDP onto the box and run the "choco install dotnet4.6.1" command as a local admin the package installs with no errors.
I'm now running choco 0.9.10 but had the same issue with 0.9.9
I'm running the newer version of the dotnet4.6.1 installer (unapproved) that runs in /q (quite) mode instead of /passive. I had the same issue in Passive mode.
Any ideas are appreciated. Thanks!

Sorry about the delay. So you need to have an automation account. I have modified my template deployment script to create the automation account, then with the Get-AzureRmAutomationRegistrationInfo cmdlet, i get the primary key and endpoint like so:
$RegistrationInfo = Get-AzureRmAutomationRegistrationInfo `
-ResourceGroupName $ResourceGroupName `
-AutomationAccountName $AccountName
New-AzureRmResourceGroupDeployment `
-Name ((Get-ChildItem $TemplateFile).BaseName + '-' + ((Get-Date).ToUniversalTime()).ToString('MMdd-HHmm')) `
-ResourceGroupName $ResourceGroupName -TemplateFile $TemplateFile `
-TemplateParameterFile $TemplateParametersFile `
# extra params here
-RegistrationKey ($RegistrationInfo.PrimaryKey | ConvertTo-SecureString -AsPlainText -Force) `
-RegistrationUrl $RegistrationInfo.Endpoint `
-AutomationAccountName $AccountName
Then in the template itself, you have an automation account there as well (name from param), and as child resources of that, a configuration and a compilation.
See here for automation account part of the template and the configuration. (I was doing the same thing v recently, with issues, but it works in the end.) As you can see, the configuration is a script that downloads .net installer and installs. FYI, this requires a reboot, so if you have anything else going on on the vm during deploy, you may get conflicts.
Like I said, you can also do it with a custom script extension if you want. Msft have a script on service profiler site that does it:
{
"properties": {
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.7",
"autoUpgradeMinorVersion": false,
"settings": {
"fileUris": [ "https://serviceprofiler.azurewebsites.net/content/downloads/InstallNetFx46.ps1" ],
"commandToExecute": "powershell.exe -ExecutionPolicy Unrestricted -File InstallNetFx46.ps1"
},
"forceUpdateTag": "RerunExtension"
},
"name": "CustomScriptExtensionInstallNet46"
}

Not saying this is the best answer possible, but this works both via Chocolatey (launched directly from a CustomScript ARM extension) or via DSC (using a pull server and a custom DSC module for .Net 4.6.1) when either is initiated from an ARM template. Below is from my chocolateyInstall.ps1. I'm basically manually conducting the install instead of relying on the chocolatey install functionality. This came from the following SO question which used this approach for 4.5.2.
Function IsInstalled {
$ver = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full').Release
return (!($ver -eq $null) -and ($ver -ge 394254))
}
if (IsInstalled) {
Write-Host "Microsoft .NET Framework 4.6.1 or later is already installed"
}
else {
$SourceURI = "https://download.microsoft.com/download/3/5/9/35980F81-60F4-4DE3-88FC-8F962B97253B/NDP461-KB3102438-Web.exe"
$FileName = $SourceURI.Split('/')[-1]
$BinPath = Join-Path $env:SystemRoot -ChildPath "Temp\$FileName"
if (!(Test-Path $BinPath))
{
Invoke-Webrequest -Uri $SourceURI -OutFile $BinPath
}
write-verbose "Installing .Net 4.6.1 from $BinPath"
write-verbose "Executing $Binpath /q /norestart"
Sleep 5
Start-Process -FilePath $BinPath -ArgumentList "/q /norestart" -Wait -NoNewWindow
Sleep 5
Write-Verbose "DotNet 4.6.1 Install completed"
}

Related

How to add custom extension to existing vm using arm template

How to add the following custom extension to run the powershell script in already existing VM ? How to refer to existing VM ?
{
"condition":"[empty(parameters ('DR User Secret'))]",
"type":"Microsoft.Compute/virtualMachines/extensions",
"name":"[concat(parameters('vmName'),'/', 'customscript')]",
"apiVersion":"2015-06-15",
"location":"[resourceGroup().location]",
"properties":{
"publisher":"Microsoft.Compute",
"type":"CustomScriptExtension",
"typeHandlerVersion":"1.9",
"autoUpgradeMinorVersion":true,
"settings":{
"fileUris":[
]
},
"protectedSettings":{
"commandToExecute":"[concat('powershell -ExecutionPolicy Unrestricted -file ', 'C:\\test.ps1', ' -AdminPass ', parameters('Password'))]"
}
}
}
Here is an alternate way you may also try.
I created a VM using the ARM template.
Reference: https://learn.microsoft.com/en-us/azure/virtual-machines/windows/ps-template
And I use the below following command that uses the Custom Script extension to download a script from a GitHub repository onto the target virtual machine and then run the script.
fileUris: The locations where the script files are stored.
Set-AzVMCustomScriptExtension -ResourceGroupName "v-rash18" -VMName "SampleVM" -Name "myCustomScript"
-FileUri "https://raw.githubusercontent.com/neilpeterson/nepeters-azure-templates/master/windows-custom-script-simple/support-scripts/Create-File.ps1"
`
-Run "Create-File.ps1" -Location "Central US".
Reference: https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/features-windows#run-vm-extensions
To check the extension is set on the existing VM is Get-AzVMExtension

How do you configuring Azure VMs with .NET 5.0 from the command line?

I'm setting up some virtual machines to run my service. There may be several, so I'm trying to automate the process. I've got a PowerShell script that successfully build the virtual machine, but now I want to install the dependent software that my .NET Core Web Application requires in the same script.
The first dependency I want to install is .NET 5.0 Runtime. I've done this many times from the browser, but now I want to commit this to a script that runs after the VM has been built.
Test locally or on a test VM by installing using the dotnet-install-script and finalize the parameters. Then use Set-AzVMExtension to install that script using custom script extension. The code would look like this (not tested)
$Command = "&powershell -NoProfile -ExecutionPolicy unrestricted -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; &([scriptblock]::Create((Invoke-WebRequest -UseBasicParsing 'https://dot.net/v1/dotnet-install.ps1'))) <additional install-script args>"
$Settings = #{"commandToExecute" = "Powershell $Command";};
Set-AzVMExtension `
-ResourceGroupName "ResourceGroupName" `
-Location "Location" `
-VMName "VirtualMachineName" `
-Name "ExtensionName" `
-Publisher "Contoso.Compute" `
-Type "CustomScriptExtension" `
-TypeHandlerVersion "1.1" `
-Settings $Settings
Full details and schema of settings custom-script-windows
You can also use Set-AzureVMCustomScriptExtension for running custom scripts.
As #amit_g recommended, you can use Azure VM run command functionality to run install .net with scripts by PowerShell directly to meet your requirement.
This seems to work pretty well:
Invoke-AzureRmVMRunCommand -ResourceGroupName "$resourceGroupName" -Name "$machineName" -CommandId "RunPowerShellScript" -ScriptPath "configureMachine.ps1" -Parameter #{"machineName" = "$machineName"}
The contents of the Powershell script look something like this:
# The name of the VM is passed in as the first parameter.
param ($machineName)
if ($machineName -eq $null)
{
Write-Host "Usage: configureMachine -machineName <machineName>";
Exit;
}
# Download the agent installation files.
$agentZip="agent.zip";
Invoke-WebRequest -Uri "https://vstsagentpackage.azureedge.net/agent/2.181.1/vsts-agent-win-x64-2.181.1.zip" -OutFile $agentZip
# Unpack them.
$agentDirectory="$env:SystemDrive\azagent";
Add-Type -AssemblyName System.IO.Compression.FileSystem;
[System.IO.Compression.ZipFile]::ExtractToDirectory($agentZip, $agentDirectory);
# Configure the machine to work as a DevOps Agent.
&"$agentDirectory\config.cmd" --unattended --deploymentgroup --deploymentgroupname "Production" --agent "$machineName" --runasservice --work "_work" --url "https://dev.azure.com/theta-rex/" --projectname "openbook" --auth PAT --token te64yuv36tina2rvc2lsvwcsvctpwomiewz5fxihcubbdzaasoka
# Remove the Agent Zip files when installation is complete.
Remove-Item $agentZip;
# Download and install .NET 5.0
Invoke-WebRequest -Uri "https://dot.net/v1/dotnet-install.ps1" -OutFile "dotnet-install.ps1"
&"./dotnet-install.ps1" -Channel 5.0 -Runtime aspnetcore -InstallDir "C:\Program Files\dotnet"
The end result is a machine configured to participate in Azure DevOps and ASP.NET 5.0.

Service Fabric: pkg\Debug is not found

I have created Service Fabric Application and added Stateless ASP.NET Core Web API 3.1 project into it. When I run the Service Fabric Application locally using VS 2019, I am getting the below error:-
The PowerShell script failed to execute. See the Service Fabric Tools pane in the output window for details.
Bellow is the output window info
C:\Users\malle\Documents\Mahesh\Projects\RetentionPortal\API\Application1\pkg\Debug is not found.
At C:\Program Files\Microsoft SDKs\Service
Fabric\Tools\PSModule\ServiceFabricSDK\Publish-NewServiceFabricApplication.ps1:120 char:9
+ throw $errMsg
+ ~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (C:\Users\malle\...g is not found.:String) [], RuntimeException
+ FullyQualifiedErrorId : C:\Users\malle\Documents\Mahesh\Projects\RetentionPortal\API\Application1\pkg\Debug is n
ot found.
Finished executing script 'Publish-NewServiceFabricApplication'.
Time elapsed: 00:00:01.7629461
Started executing script 'Unpublish-ServiceFabricApplication'.
powershell -NonInteractive -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -Command "[void](Connect-ServiceFabricCluster); Import-Module 'C:\Program Files\Microsoft SDKs\Service Fabric\Tools\PSModule\ServiceFabricSDK\ServiceFabricSDK.psm1'; Unpublish-ServiceFabricApplication -ApplicationName 'fabric:/Application1' -ErrorAction Stop"
Removing application...
Finished executing script 'Unpublish-ServiceFabricApplication'.
Time elapsed: 00:00:01.5278716
Started executing script 'UnregisterApplicationType'.
powershell -NonInteractive -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -Command "[void](Connect-ServiceFabricCluster); Import-Module 'C:\Program Files\Microsoft SDKs\Service Fabric\Tools\PSModule\ServiceFabricSDK\ServiceFabricSDK.psm1'; if (Get-ServiceFabricApplicationType -ApplicationTypeName 'Application1Type' | Where-Object { $_.ApplicationTypeVersion -eq '1.0.0' }) { Unregister-ServiceFabricApplicationType -ApplicationTypeName 'Application1Type' -ApplicationTypeVersion '1.0.0' -ErrorAction Stop -Force }"
Finished executing script 'UnregisterApplicationType'.
Time elapsed: 00:00:01.4425472
Any help is really appreciated
General solution steps:
Reboot Computer
Log On
Start Visual Studio as Admin
Open Service Fabric Project
F5 to Debug
Try to run the same project again, same output
Run POwerShell as Admin, Connect-ServiceFabricCluster.
Start debugging (F5) in Visual Studio
Everything's fine now
For more details, you can check the issues oin github.
Publish-NewServiceFabricApplication fails to read ApplicationManifest.xml
If the above solution does not work, it is recommended to try the following steps.
Create pkg/Debug folder.
I have some files under Debug folder, so I deleted them.
Clean and Rebuild Solution.
F5 Run. It will generate files you want.

Azure Automation Powershell runbook failed to load assembly

Code That I am running on azure portal
Write-Output "Starting"
$assemblyPath = "C:\Modules\Global\Azure\Compute\Microsoft.Exchange.WebServices.dll"
dir $assemblyPath
Write-Output "1"
Add-Type -Path $assemblyPath
Write-Output "2"
Output
Any idea on this?
To load the .dll assembly, you could refer to the steps.
1.Navigate to your automation account in the portal-> Modules -> Add Module, compress the Microsoft.ApplicationInsights.dll file to Microsoft.ApplicationInsights.zip, then upload. After uploading, you will find it in the portal.
2.Change the $assemblyPath, your complete command should be as below, it will work fine.
Write-Output "Starting"
$assemblyPath = "C:\Modules\User\Microsoft.ApplicationInsights\Microsoft.ApplicationInsights.dll"
dir $assemblyPath
Write-Output "1"
Add-Type -Path $assemblyPath
Write-Output "2"
Output:

How can i install ARR on azure VM via PowerShell?

I have deployed my project to Azure Cloud Service but additionally i must install Application Request Routing (ARR).
peace of .ps1 PowerShell command:
if( Get-Service was ) {
Write-Host "Stopping IIS and WAS..."
Stop-Service was -Force
}
$filepath="%temp%\arr.msi"
$process = (Start-Process -FilePath msiexec -ArgumentList /i, $filepath, /qn -Wait).ExitCode
Write-Host $process
if( Get-Service was ) {
Start-Service was,w3svc -Verbose
}
output:
Downloading MSI packages...
Downloading MSI package: D:\Users\BUTTER~1\AppData\Local\Temp\2\arr.msi
Downloaded...
Done. Performing installation...
Stopping IIS and WAS...
1619
Done
VERBOSE: Performing operation "Start-Service" on Target "World Wide Web Publishing Service (w3svc)".
VERBOSE: Performing operation "Start-Service" on Target "Windows Process Activation Service (was)".
there is no error but it doesn't install ARR. can anyone help?
I couldn't find a good way of doing this directly through PowerShell. If you don't mind using Chocolatey you can do it all from the Web Platform Installer Command Line (WebPICMD), example:
#Download and install Chocolatey and through Chocolatey install WebPICMD
iex ((new-object net.webclient).DownloadString("https://chocolatey.org/install.ps1"))
cinst webpicommandline
#Install Url Rewrite and ARR
$webPiProducts = #('UrlRewrite2', 'ARRv3_0')
WebPICMD /Install /Products:"$($webPiProducts -join ',')" /AcceptEULA
More info about WebPICMD here: http://www.iis.net/learn/install/web-platform-installer/web-platform-installer-v4-command-line-webpicmdexe-rtw-release
Inspiration for Chocolatey came from this blog post: http://www.tugberkugurlu.com/archive/script-out-everything-initialize-your-windows-azure-vm-for-your-web-server-with-iis-web-deploy-and-other-stuff

Resources