ansible-windows icon indicating copy to clipboard operation
ansible-windows copied to clipboard

Please make a non-interactive option for "Install-WMF3Hotfix.ps1"

Open apg036 opened this issue 6 years ago • 0 comments

Hi Jordan,

Please can you modify the code so it could be used in automation scripts: in particular remove user-interaction steps here: 142: Restart-Computer -Confirm

I'm running this script from Packer and I have to perform the following workaround otherwise Packer waits for user input forever:

# Automation script copied from
# https://github.com/jborean93/ansible-windows/tree/master/scripts
# Prepare temp directory
$tmp_dir = $env:temp
if (-not (Test-Path -Path $tmp_dir)) {
    New-Item -Path $tmp_dir -ItemType Directory > $null
}
# Download script from GitHub
$url    = "https://raw.githubusercontent.com/jborean93/ansible-windows/master/scripts/Install-WMF3Hotfix.ps1"
$file   = "$tmp_dir\Install-WMF3Hotfix.ps1"
$script = "$tmp_dir\Install-WMF3Hotfix-no-restart.ps1"
(New-Object -TypeName System.Net.WebClient).DownloadFile($url, $file)
# Remove user-interaction line asking for computer restart confirmation
(Get-Content $file) -notmatch "^(.*)Restart-Computer -Confirm$" | Out-File $script
# Run WMF3Hotfix installation
powershell.exe -ExecutionPolicy ByPass -File $script -Verbose

Followed by Windows restart handled by Packer itself

BR Pavel

apg036 avatar Jul 01 '18 13:07 apg036