运行 来自 PowerShell 关机脚本的安装程序

Run Installer From PowerShell Shutdown Script

目标:

给定:

问题:

已经尝试过

#
$registry = Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -recurse |
Get-ItemProperty -name Version,Release -EA 0 |
Where { $_.PSChildName -match '^(?!S)\p{L}'} |
Select Version

$flag = $false

foreach ($version in $registry){
    if ($version.Version -like "4.5*"){
        "Found Version " + $version.Version
        $flag = $true
        break
    } else {

    }
}
if($flag){
    # .NET 4.5* is installed
} else {
    # install .NET 4.5.2
    & "\ad1dc01\deployment$\Microsoft\DotNet2\NDP452-KB2901907-x86-x64-AllOS-ENU.exe" /q /norestart
}

可能安装程序没有在系统完成关闭之前完成。尝试使用 -Wait 参数启动进程 cmdlet?

Start-Process -FilePath "\ad1dc01\deployment$\Microsoft\DotNet2\NDP452-KB2901907-x86-x64-AllOS-ENU.exe" -ArgumentList "/q /norestart" -Wait