My client doesn't have Puppet or Chef or Choco, and I can't install them on his server to install my App.
- Check installed versions of dotnet framework.
- Convert to '.' split string
- Convert to System.Version (some have 2 split or 3 split array
- Compare with desired dotnetframework version e.g. 4.6.2
- If a higher version is installed abort
- If not then install MSI/EXE of desired framework version
Step 1: Check dotnet version as System.Version:
So far I have :
Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -Recurse |
Get-ItemProperty -name Version, Release -EA 0 |
Where-Object { $_.PSChildName -match 'Full'} |
Select-Object Version
But GetType, Split, Select-String, just aren't working for me.
Errors and code tried so far:
| Select-String $_
results in: Select-String : Cannot bind argument to parameter 'Pattern' because it is null.
| {Select-String $_}
results in: Expressions are only allowed as the first element of a pipeline.
|Select-Object $_.GetType
Does not list the type of Version
|Select-Object $_.Split(".")
results in: You cannot call a method on a null-valued expression.
Edit: @Theo answer is good it can now wrap the install .net 4.6.2 logic which is:
$SourceURI = "https://download.microsoft.com/download/F/9/4/F942F07D-F26F-4F30-B4E3-EBD54FABA377/NDP462-KB3151800-x86-x64-AllOS-ENU.exe"
$FileName = $SourceURI.Split('/')[-1]
$BinPath = Join-Path $env:TEMP -ChildPath "dotnet462\$FileName"
if (!(Test-Path $BinPath))
{
Invoke-Webrequest -Uri $SourceURI -OutFile $BinPath
}
write-verbose "Executing $binpath /q /norestart"
Sleep 5
Start-Process -FilePath $BinPath -ArgumentList "/q /norestart" -Wait -NoNewWindow