Quantcast
Channel: psappdeploytoolkit Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1769

New Post: Question on registry detection

$
0
0
I borrowed this to fix an issue I was having and it took a bit of troubleshooting to get working, figured I would share my experience. The below section of code was not actually populating the $dotNet45Installed variable on machines where .NET was not installed, rather the variable would be left blank and the script would skip the install of the per-requisite item because the variable was blank rather than false.
ForEach ($dotNetVersion in $dotNetVersions) {
        If ($dotNetVersion.Version -ge "4.5") {
            $dotNet45Installed = $true
To remedy this I changed the greater than to less than, and the value from true to false. I could have completed the if statement with an else to achieve the same results but this was easier and achieves the same result. If the product is not present than it flags as false and installs the pre-requisite, if it is present it leaves the variable blank which skips the install.
ForEach ($dotNetVersion in $dotNetVersions) {
        If ($dotNetVersion.Version -lt "4.5") {
            $dotNet45Installed = $false
The complete code looks like this.

    # Get the installed .NET Framework Version
    $dotNetVersions = Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -Recurse | Get-ItemProperty -name Version -EA 0 | Where { $_.PSChildName -match '^(?!S)\p{L}'} | Select PSChildName, Version
    ForEach ($dotNetVersion in $dotNetVersions) {
        If ($dotNetVersion.Version -lt "4.5") {
            $dotNet45Installed = $false
            Break
        }
    }

    # Install .NET 4.5 if it's not already installed
    If ($dotNet45Installed -eq $false) {
        # Do installation here
    }
sintaxasn wrote:
.NET detection can be a bit tricky but this should work for you:
    # Get the installed .NET Framework Version
    $dotNetVersions = Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -Recurse | Get-ItemProperty -name Version -EA 0 | Where { $_.PSChildName -match '^(?!S)\p{L}'} | Select PSChildName, Version
    ForEach ($dotNetVersion in $dotNetVersions) {
        If ($dotNetVersion.Version -ge "4.5") {
            $dotNet45Installed = $true
            Break
        }
    }

    # Install .NET 4.5 if it's not already installed
    If ($dotNet45Installed -eq $false) {
        # Do installation here
    }
    
Hope this helps, Dan

Viewing all articles
Browse latest Browse all 1769

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>