Невозможно создать журналы после перезагрузки в сценарии PowerShell DS C - PullRequest
0 голосов
/ 07 января 2020

Конфигурация appInstall {param ([строка []] $ ComputerName = 'localhost', [параметр (обязательный)] [String] $ DownloadUrl, [параметр (обязательный)] [String] $ SetupFileDrive) Import-DscResource -ModuleName " PSDesiredStateConfiguration "# Локальный диспетчер конфигурации для ожидающего узла перезагрузки $ ComputerName {LocalConfigurationManager {RebootNodeIfNeeded = $ true}

    # Install .NET 4.7
    Script Install_Net_4_7
    {
        GetScript = {
                        if (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full' | %{ $_ -match 'Release' })
                        {
                            $NetBuildVersion = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full').Release
                            return $NetBuildVersion
                        }
                        else
                        {
                            Write-Verbose ".Net build version not recognised"
                            return ".Net 4.7 not found"
                        }
                    }
        TestScript = {
                        [int]$NetBuildVersion = 460805
                        if (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full' | %{ $_ -match 'Release' })
                        {
                            [int]$CurrentRelease = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full').Release
                            if ($CurrentRelease -lt $NetBuildVersion)
                            {
                                Write-Verbose "Current .Net build version is less than 4.7 ($CurrentRelease)"
                                return $false
                            }
                            else
                            {
                                Write-Verbose "Current .Net build version is the same as or higher than 4.7 ($CurrentRelease)"
                                return $true
                            }
                        }
                        else
                        {
                            Write-Verbose ".Net build version not recognised"
                            return $false
                        }
                    }
        SetScript = {
                        $FileName = "NDP471-KB4033342-x86-x64-AllOS-ENU.exe"
                        $BinPath = "$using:SetupFileDrive\setupfiles\$FileName"
                        write-verbose "Installing .Net 4.7 from $BinPath"
                        write-verbose "Executing $binpath /q"
                        Sleep 5
                        Start-Process -FilePath $BinPath -ArgumentList "/q" -Wait -NoNewWindow
                    }
        DependsOn = "[Archive]ArchiveSetupFileZip"
    }
    # Reboot Node
    Script Reboot {
        TestScript = {
            return (Test-Path HKLM:\SOFTWARE\MyMainKey\RebootKey)
        }
        SetScript  = {
            New-Item -Path HKLM:\SOFTWARE\MyMainKey\RebootKey -Force
            $global:DSCMachineStatus = 1
        }
        GetScript  = {
            return @{result = 'result' }
        }
        DependsOn  = '[Script]Install_Net_4_7'
    }
    # Install OpenJDK
    Package OpenJDK11
    {
        Ensure    = "Present"
        Name      = "AdoptOpenJDK JDK with Hotspot 11.0.4.11 (x64)"
        Path      = "$SetupFileDrive\setupfiles\OpenJDK11U-jdk_x64_windows_hotspot_11.0.4_11.msi"
        Arguments = "AllUsers=1 ACCEPTEULA=1"
        ProductID = "4C2A33A6-2427-xxxx-xxxx-xxxxxx" 
        DependsOn  = '[Script]Reboot'          
    }
}

} appInstall Start-DscConfiguration -ComputerName localhost -Path appInstall -Wait -Verb_setup_setup_name_set_set_set_set_> Файл_установки_приложения_Пакета_установки $ $ (Get-Date -Format "MMddyyyy_HHmm"). Txt

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...