guitarrapc / GraniResource

PowerShell Desired State Configuration Resources for real production workload.
https://www.powershellgallery.com/packages/GraniResource
MIT License
43 stars 8 forks source link

Issue when calling Grani_DotNetFramework #80

Open baannee opened 6 years ago

baannee commented 6 years ago

After installing module on both, Windows 10 and Server 2016, I am getting:

PowerShell DSC resource MSFT_PackageResource failed to execute Set-TargetResource functionality with error message: The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Access is denied + CategoryInfo : InvalidOperation: (:) [], CimException + FullyQualifiedErrorId : ProviderOperationExecutionFailure + PSComputerName : localhost The SendConfigurationApply function did not succeed. + CategoryInfo : NotSpecified: (root/Microsoft/...gurationManager:String) [], CimException + FullyQualifiedErrorId : MI RESULT 1 + PSComputerName : localhostImporting module Grani_DotNetFramework failed with error -At C:\Program Files\WindowsPowerShell\Modules\GraniResource\3.7.9.0\DscResources\Grani_DotNetFramework\Grani_DotNetFramework.psm1:408 char:26 + if ($result -ne 0) # should be 0 for success uninstallation { + ~ Missing statement block after if ( condition ). At C:\Program`Files\WindowsPowerShell\Modules\GraniResource\3.7.9.0\DscResources\Grani_DotNetFramework\Grani_DotNetFramework.psm1:413 char:55 + elseif ($Ensure -eq [EnsureType]::Present.ToString()) { + ~ Unexpected token '{' in expression or statement. At C:\Program`Files\WindowsPowerShell\Modules\GraniResource\3.7.9.0\DscResources\Grani_DotNetFramework\Grani_DotNetFramework.psm1:415 char:22 + if ($result -eq 0) # should be 1 for success installation { + ~ Missing statement block after if ( condition ). At C:\Program`Files\WindowsPowerShell\Modules\GraniResource\3.7.9.0\DscResources\Grani_DotNetFramework\Grani_DotNetFramework.psm1:419 char:1 + } + ~ Unexpected token '}' in expression or statement. At C:\Program`Files\WindowsPowerShell\Modules\GraniResource\3.7.9.0\DscResources\Grani_DotNetFramework\Grani_DotNetFramework.psm1:420 char:1 + } + ~ Unexpected token '}' in expression or statement. + CategoryInfo : InvalidOperation: (root/Microsoft/...gurationManager:String) [], CimException + FullyQualifiedErrorId : ImportModuleFailed + PSComputerName : localhost`

By the error message, and I am not sure why this is an issue, "{ }" making trouble. When I reorganize them, all is working as expected.

https://app.leanboard.io/board/705af88f-a126-4b24-aa44-cefb02689ee7

guitarrapc commented 6 years ago

Thank you for the report. Yeah, it seems some issue goes on. Let me check.

guitarrapc commented 6 years ago

Caused by VSCode Formatter and I did not run test. will be fix in 3.7.9.1.

guitarrapc commented 6 years ago

Fixed.

function VerifyInstallation {
    [OutputType([Void])]
    [CmdletBinding()]
    param
    (
        [parameter(Mandatory = $true)]
        [System.String]$KB,

        [parameter(Mandatory = $true)]
        [System.String]$Ensure
    )

    $result = (Get-HotFix | where HotFixId -eq $KB | measure).Count
    if ($Ensure -eq [EnsureType]::Absent.ToString()) {

        # Absent
        # should be 0 for success uninstallation
        if ($result -ne 0) {
            throw New-Object System.ArgumentException ($ErrorMessages.VerifyInstallationKBFound -f $KB);
        }
        Write-Verbose ($VerboseMessages.CompleteUninstallation -f $KB);
    }
    elseif ($Ensure -eq [EnsureType]::Present.ToString()) {
        # Present
        # should be 1 for success installation
        if ($result -eq 0) {
            throw New-Object System.NullReferenceException ($ErrorMessages.VerifyInstallationKBNotFound -f $KB);
        }
        Write-Verbose ($VerboseMessages.CompleteInstallation -f $KB);
    }
}
guitarrapc commented 6 years ago

@baannee Many thank you for report. I've fixed issue and publish hotfix 3.7.9.1. Would you mind confirm it works on your environment?

https://github.com/guitarrapc/GraniResource/releases/tag/ver.3.7.9.1

https://www.powershellgallery.com/packages/GraniResource/3.7.9.1

Install-Module -Name GraniResource
baannee commented 6 years ago

Hi, It seems that it's working. But, when I call configuration to install .NET 4.7.1, the following error displays: PowerShell DSC resource Grani_DotNetFramework failed to execute Set-TargetResource functionality' with error message: Could not find KB from Windows Hotfix list. KB : KB4033344 + CategoryInfo : InvalidOperation: (:) [], CimException + FullyQualifiedErrorId : ProviderOperationExecutionFailure + PSComputerName : localhost

VERBOSE: [B-IIS-TDSC-01]: LCM: [ End Set ] The SendConfigurationApply function did not succeed. + CategoryInfo : NotSpecified: (root/Microsoft/...gurationManager:String) [], CimException + FullyQualifiedErrorId : MI RESULT 1 + PSComputerName : localhost

VERBOSE: Operation 'Invoke CimMethod' complete. VERBOSE: Time taken for configuration job to complete is 9.551 seconds

After reboot, it shows that .NET 4.7.1 is installed.

rdavisunr commented 6 years ago

@guitarrapc - I have having the same issue as @baannee on Windows 2012 Server R2. I have also tried with .NET 4.6.2 and .NET 4.7

Here's the verbose output

VERBOSE: [DB]: LCM:  [ Start  Resource ]  [[cDotNetFramework]InstallNETFramework]
VERBOSE: [DB]: LCM:  [ Start  Test     ]  [[cDotNetFramework]InstallNETFramework]
VERBOSE: [DB]:                            [[cDotNetFramework]InstallNETFramework] Importing the module Grani_DotNetFramework in force mode.
VERBOSE: [DB]:                            [[cDotNetFramework]InstallNETFramework] Check KB entry is exists.
VERBOSE: [DB]:                            [[cDotNetFramework]InstallNETFramework] Did not find a KB entry KB3186505.
VERBOSE: [DB]: LCM:  [ End    Test     ]  [[cDotNetFramework]InstallNETFramework]  in 1.1050 seconds.
VERBOSE: [DB]: LCM:  [ Start  Set      ]  [[cDotNetFramework]InstallNETFramework]
VERBOSE: [DB]:                            [[cDotNetFramework]InstallNETFramework] Importing the module Grani_DotNetFramework in force mode.
VERBOSE: [DB]:                            [[cDotNetFramework]InstallNETFramework] Start Installation with process'D:\DOTNET\NDP47-KB3186497-x86-x64-AllOS-ENU.exe', arguments '/q
/x:C:\Windows\Temp\78813ef2-0f95-4553-ac24-1edb16fde487'
VERBOSE: [DB]:                            [[cDotNetFramework]InstallNETFramework] Verifying Exit Code.
VERBOSE: [DB]:                            [[cDotNetFramework]InstallNETFramework] ExitCode : 0. Installation success.Installation completed successfully.
VERBOSE: [DB]:                            [[cDotNetFramework]InstallNETFramework] Start Installation with process 'C:\Windows\Temp\78813ef2-0f95-4553-ac24-1edb16fde487\setup.exe', arguments '/q /x86 /x64 /redist /norestart /log C:\Windows\Temp'
VERBOSE: [DB]:                            [[cDotNetFramework]InstallNETFramework] Verifying Exit Code.
VERBOSE: [DB]:                            [[cDotNetFramework]InstallNETFramework] ExitCode : 0. Installation success. Installation completed successfully.
VERBOSE: [DB]: LCM:  [ End    Set      ]  [[cDotNetFramework]InstallNETFramework]  in 32.2200 seconds.
PowerShell DSC resource Grani_DotNetFramework  failed to execute Set-TargetResource functionality with error message:
Could not find KB from Windows Hotfix list. KB : KB3186505
    + CategoryInfo          : InvalidOperation: (:) [], CimException
    + FullyQualifiedErrorId : ProviderOperationExecutionFailure
    + PSComputerName        : DB

Also, this has worked fine in the past. Maybe a recent Windows Update has caused a change in behavior?

guitarrapc commented 6 years ago

First of all, thank you for using this resource and verbose situation. I was not using the resource currently so that I need to setup VM for Win2012 R2 to fix this issue.

Let me check it. I will check with latest windows update applied instance.

guitarrapc commented 6 years ago

Log and actual behavior shows installation is finished.

After reboot, it shows that .NET 4.7.1 is installed. ExitCode : 0. Installation success. Installation completed successfully.

So that issue would be it can't detect KB installed without a reboot.

Could not find KB from Windows Hotfix list. KB : KB3186505

rdavisunr commented 6 years ago

@guitarrapc - thanks for the prompt response. Using this article, I was able to determine that my system actually had 4.7.1 already installed (maybe from a Windows update). So, I suppose this would be expected behavior when using your resource to install 4.6.2?

guitarrapc commented 6 years ago

thanks. the article is what I refer when created this resource. I will review again.

rdavisunr commented 6 years ago

I guess the question is, what should happen if a higher version of the framework is already installed?

Since they are in-place updates, maybe the Test should return that it is already in the desired state? Like, when you are trying to install 4.6.2, but 4.7.1 is already there?

guitarrapc commented 6 years ago

Correct.