Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'{$ProgressPreference' is not recognized as an internal or external command #1

Closed
PatrickLang opened this issue Jun 27, 2016 · 21 comments

Comments

@PatrickLang
Copy link
Owner

Using https://dl.bintray.com/taliesins/Packer/Packer.1.0.0.104-HyperV.nupkg

packer build -var 'hyperv_switchname=Ethernet' -var 'iso_url=./server2016tp5.iso' .\windows _2016_docker.json

fails:

==> hyperv-iso: Restarting Machine
==> hyperv-iso: Waiting for machine to restart...
    hyperv-iso: A system shutdown is in progress.(1115)
    hyperv-iso: VAGRANT-2016 restarted.
    hyperv-iso: #< CLIXML
    hyperv-iso: <Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><Obj S="progress" RefId="0"><TN RefId=
"0"><T>System.Management.Automation.PSCustomObject</T><T>System.Object</T></TN><MS><I64 N="SourceId">1</I64><PR N="Record"><AV>Prepari
ng modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj></Objs>
==> hyperv-iso: Machine successfully restarted, moving on
==> hyperv-iso: Provisioning with windows-shell...
==> hyperv-iso: Provisioning with shell script: ./scripts/pin-powershell.bat
    hyperv-iso:
    hyperv-iso: C:\Users\vagrant>rem https://connect.microsoft.com/PowerShell/feedback/details/1609288/pin-to-taskbar-no-longer-workin
g-in-windows-10
    hyperv-iso:
    hyperv-iso: C:\Users\vagrant>copy "A:\WindowsPowerShell.lnk" "C:\Users\vagrant\AppData\Local\Temp\Windows PowerShell.lnk"
    hyperv-iso: 1 file(s) copied.
    hyperv-iso:
    hyperv-iso: C:\Users\vagrant>A:\PinTo10.exe /PTFOL01:'C:\Users\vagrant\AppData\Local\Temp' /PTFILE01:'Windows PowerShell.lnk'
    hyperv-iso:
    hyperv-iso: C:\Users\vagrant>exit /b 0
==> hyperv-iso: Provisioning with shell script: ./scripts/uac-enable.bat
    hyperv-iso:
    hyperv-iso: C:\Users\vagrant>reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /f /v EnableLUA /t REG_DWORD
 /d 1
    hyperv-iso: The operation completed successfully.
==> hyperv-iso: Provisioning with Powershell...
==> hyperv-iso: Provisioning with shell script: ./scripts/docker/install-docker.ps1
    hyperv-iso: The string is missing the terminator: '.
    hyperv-iso: + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    hyperv-iso: + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
    hyperv-iso:
    hyperv-iso: '{$ProgressPreference' is not recognized as an internal or external command,
    hyperv-iso: operable program or batch file.
==> hyperv-iso: Cleanup floppy drive...
==> hyperv-iso: Clean up os dvd drive...
==> hyperv-iso: Unregistering and deleting virtual machine...
==> hyperv-iso: Deleting output directory...
==> hyperv-iso: Deleting temporary directory...
Build 'hyperv-iso' errored: Script exited with non-zero exit status: 1. Allowed exit codes are: [0]

==> Some builds didn't complete successfully and had errors:
--> virtualbox-iso: Failed creating VirtualBox driver: exec: "VBoxManage": executable file not found in %PATH%
--> vmware-iso: Failed creating VMware driver: Unable to initialize any driver for this platform. The errors
from each driver are shown below. Please fix at least one driver
to continue:
* VMware application not found:
* VMware application not found:
* VMware application not found:
* VMware application not found:

--> hyperv-iso: Script exited with non-zero exit status: 1. Allowed exit codes are: [0]

==> Builds finished but no artifacts were created.
@StefanScherer
Copy link

StefanScherer commented Jun 27, 2016

I have the same issue and no clue right now what's wrong with this script. Maybe its size and a problem with the upload through WinRM.

I'm using a scheduled task inside the install-docker.ps1 to work around a problem running Install-ContainerHost.ps1 without interactive desktop. Probably the progress bar causes the problem without a real terminal window. May $ProgressPreference='SilentlyContinue'help to make this work without the scheduled task?

BTW: With packer build --only hyperv-iso ... you can skip the other builder sections.

@StefanScherer
Copy link

Or we should use the newer steps to install Docker, eg. from install-docker.ps1

@PatrickLang
Copy link
Owner Author

PatrickLang commented Jun 28, 2016

That's a good thought on the size. It looks like that happens ~17284 characters in. I suppose if line endings and/or comments were stripped during remoting, that could be around a 16k boundary.

I'm leaning towards install-docker.ps1 - that's much simpler.

@PatrickLang
Copy link
Owner Author

re: progress bar & downloads - Start-BitsTransfer is much faster. It works everywhere except Nano server.

$xfer = Start-BitsTransfer -Source https://aka.ms/tp5/serveriso -Destination .\server2016tp5.iso -Asynchronous
while ($xfer.JobState -eq "Transferring") { Write-Host Transferred $xfer.BytesTransferred / $xfer.BytesTotal ; Start-Sleep -Seconds 10 }
$xfer | Complete-BitsTransfer

@PatrickLang
Copy link
Owner Author

I started down the path with the shorter scripts - see branch "shorterinstall." I'm too tired to finish testing it tonight

@StefanScherer
Copy link

Great work!

@PatrickLang
Copy link
Owner Author

PatrickLang commented Jun 28, 2016

It's not size related. It fails with the shorter script.

This is the first PowerShell script in the provisioners section of windows_2016_docker.json. I need to dig into the Packer code to see if there's a bug in how it invokes PowerShell scripts over WinRM.

windows_2016 and windows_2016_core.json succeed. Neither of them use PowerShell provisioner scripts.

@StefanScherer
Copy link

https://www.packer.io/docs/other/debugging.html may help, setting environment variable PACKER_LOG=1

@StefanScherer
Copy link

StefanScherer commented Jun 28, 2016

@StefanScherer
Copy link

I'll try another build with a modified json file, adding the execute_command with its default from upstream packer. This should overwrite the broken(?) default in the special packer.exe.

    {
      "type": "powershell",
      "execute_command": "powershell \"& { {{.Vars}}{{.Path}}; exit $LastExitCode}\"",
      "scripts": [
        "./scripts/docker/install-docker.ps1",
        "./scripts/docker/patch-boot-time-for-containers.ps1",
        "./scripts/docker/enable-docker-insecure.ps1",
        "./scripts/docker/add-docker-group.ps1",
        "./scripts/docker/remove-docker-key-json.ps1"
      ]
    },

@StefanScherer
Copy link

Yes this seems to work even with the old install-docker.ps1 script. But packer couldn't export the Hyper-V TP5 VM as my Win10 VM only has a 60 GByte disk. So I first have to create a bigger Win10 VM with Packer on my Mac...

PatrickLang added a commit that referenced this issue Jun 28, 2016
@PatrickLang
Copy link
Owner Author

Thanks! that worked.

@StefanScherer
Copy link

In the meantime I tried a similar tp5 json template to build the TP5 with docker installed for Hyper-V. I wanted to make a breakthrough to check which problems occur on that way using Vagrant.
And using Vagrant 1.8.4 there is one issue with Hyper-V:

C:\Users\vagrant\packer-windows [hyperv ≡ +1 ~2 -0 !]> vagrant box add windows_2016_tp5_docker .\windows_2016_docker_hyperv.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'windows_2016_tp5_docker' (v0) for provider:
    box: Unpacking necessary files from: file://C:/Users/vagrant/packer-windows/windows_2016_docker_hyperv.box
    box: Progress: 100% (Rate: 218M/s, Estimated time remaining: --:--:--)
==> box: Successfully added box 'windows_2016_tp5_docker' (v0) for 'hyperv'!
C:\Users\vagrant\packer-windows [hyperv ≡ +1 ~2 -0 !]> vagrant box list
windows_2016_tp5_docker (hyperv, 0)
C:\Users\vagrant\packer-windows [hyperv ≡ +1 ~2 -0 !]> cd ..
C:\Users\vagrant> git clone [email protected]:StefanScherer/docker-windows-box
Cloning into 'docker-windows-box'...
Warning: Permanently added the RSA host key for IP address '192.30.253.112' to the list of known hosts.
remote: Counting objects: 422, done.
Receiving objects:  92% (389/422), 6.71 MiB | 3.27 MiB/s    0), reused 0 (delta 0), pack-reused 4226.71 MiB | 3.27 MiB/s
Receiving objects: 100% (422/422), 7.11 MiB | 3.27 MiB/s, done.
Resolving deltas: 100% (228/228), done.
Checking connectivity... done.
C:\Users\vagrant> cd .\docker-windows-box\
C:\Users\vagrant\docker-windows-box [master ≡]> atom .
C:\Users\vagrant\docker-windows-box [master ≡]> vagrant up --provider hyperv
Bringing machine 'default' up with 'hyperv' provider...
==> default: Verifying Hyper-V is enabled...
==> default: Configured Dynamic memory allocation, maxmemory is 2048
==> default: Configured cpus number is 2
==> default: Configured differencing disk instead of cloning
==> default: Importing a Hyper-V instance
    default: Cloning virtual hard drive...
    default: Creating and registering the VM...
    default: Successfully imported a VM with name: windows2016
An error occurred while executing a PowerShell script. This error
is shown below. Please read the error message and see if this is
a configuration error with your system. If it is not, then please
report a bug.

Script: get_vm_status.ps1
Error:

At C:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.8.4\plugins\providers\hyperv\scripts\get_vm_status.ps1:21 char:8
+ } catch $ExceptionType {
+        ~
The Catch block is missing its statement block.
At C:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.8.4\plugins\providers\hyperv\scripts\get_vm_status.ps1:21 char:24
+ } catch $ExceptionType {
+                        ~
Unexpected token '{' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : MissingCatchHandlerBlock

C:\Users\vagrant\docker-windows-box [master ≡ +0 ~1 -0 !]>

Searching for that error message I found this

I've patched my Vagrant 1.8.4 installation in Windows 10 with

wget -uri https://raw.githubusercontent.com/codekaizen/vagrant/d3859a33aa37aa238fd4022a3ad4e7546f149570/plugins/providers/hyperv/scripts/get_vm_status.ps1 -outfile C:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.8.4\plugins\providers\hyperv\scripts\get_vm_status.ps1

I think that will be fixed and available in Vagrant 1.8.5. Testing all these tools with Hyper-V helps making them better.

Now booting the docker-windows-box works

git clone https://github.com/StefanScherer/docker-windows-box
cd docker-windows-box
vagrant up --provider hyperv

But then another error occurs which I know from OSX as there is an issue with WinRM in Vagrant 1.8.4

...
==> default:
==> default: Running provisioner: shell...
C:/HashiCorp/Vagrant/embedded/gems/gems/winrm-fs-0.3.2/lib/winrm-fs/core/file_transporter.rb:378:in `parse_response': [WinRM::FS::Core::FileTransporter] Upload failed (exitcode: 0), but stderr present (WinRM::FS::Core::FileTransporterFailed)
        from C:/HashiCorp/Vagrant/embedded/gems/gems/winrm-fs-0.3.2/lib/winrm-fs/core/file_transporter.rb:192:in `check_files'
...

The issue is filed at hashicorp/vagrant#7526 with a workaround to update winrm-fs ruby gem to 0.4.3 as described in hashicorp/vagrant#7476 (comment).

I fixed it on Windows 10 with

C:\Users\vagrant\docker-windows-box [master ≡ +0 ~1 -0 !]> atom c:/HashiCorp/Vagrant/embedded/gems/specifications/vagrant-1.8.4.gemspec

C:\Users\vagrant\docker-windows-box [master ≡ +0 ~1 -0 !]> vagrant plugin install winrm-fs
Installing the 'winrm-fs' plugin. This can take a few minutes...
Installed the plugin 'winrm-fs (0.4.3)'!

So the breakthrough with a TP5 Vagrant box in Hyper-V is only possible with a developer version of packer + Vagrant 1.8.4 with some unsupported patches to make everything work. But this gives me hope that in a future version when all patches will be merged Windows users will have the same experience with packer + vagrant -> windows docker engine as others on Mac/Linux/Windows with VMware/VirtualBox

@StefanScherer
Copy link

This is the modification in the docker-windows-box Vagrantfile for the hyperv provider in Vagrant.

@StefanScherer
Copy link

Current status: Windows 10 build 10586 running Vagrant 1.8.4 with two patches (^^) to spin up a Hyper-V Vagrant box with Server 2016 TP5 and Docker with windowsservercore images.

vagrant-hyperv-tp5-docker-in-win10

Would love to see a Vagrant 1.8.5 very soon with these fixes. /cc @sethvargo :-)

@taliesins
Copy link

Looking good. Well done :-)

@StefanScherer
Copy link

@taliesins Thanks! My first intensive usage of your packer hyperv fork. 👍 Still some work to do.
BTW: I've tried the packer https://dl.bintray.com/taliesins/Packer/Packer.1.0.0.104-HyperV.nupkg build in Windows Insider 14366 but it failed with a ParseInt error

C:\Users\vagrant\packer-windows [hyperv ↕ +1 ~0 -0 !]> type .\build.ps1
packer build --only=hyperv-iso --var hyperv_switchname=packer --var iso_url=$(pwd)\iso\14300.1000.160324-1723.RS1_RELEASE_SVC_SERVER_OEMRET_X64FRE_EN-US.ISO windows_2016_docker.json
C:\Users\vagrant\packer-windows [hyperv ↕ +1 ~0 -0 !]> .\build.ps1
hyperv-iso output will be in this color.

Warnings for build 'hyperv-iso':

* Hyper-V might fail to create a VM if there is not enough free memory in the system.

Build 'hyperv-iso' errored: Failed creating Hyper-V driver: strconv.ParseInt: parsing "5\r\nC:\\Users\\vagrant\\packer-windows [hyperv \x12 +1 ~0 -0 !]>": invalid syntax

==> Some builds didn't complete successfully and had errors:
--> hyperv-iso: Failed creating Hyper-V driver: strconv.ParseInt: parsing "5\r\nC:\\Users\\vagrant\\packer-windows [hyperv \x12 +1 ~0 -0 !]>": invalid syntax

==> Builds finished but no artifacts were created.

And some more details with $env:PACKER_LOG=1


2016/07/04 01:56:33 ui: Warnings for build 'hyperv-iso':
2016/07/04 01:56:33 ui: * Hyper-V might fail to create a VM if there is not enough free memory in the system.
2016/07/04 01:56:33 ui:
2016/07/04 01:56:33 Waiting on builds to complete...
2016/07/04 01:56:33 Starting build run: hyperv-iso
2016/07/04 01:56:33 Running builder: hyperv-iso
Warnings for build 'hyperv-iso':

* Hyper-V might fail to create a VM if there is not enough free memory in the system.

2016/07/04 01:56:33 packer.exe: 2016/07/04 01:56:33 Enter method: verifyPSVersion
2016/07/04 01:56:34 packer.exe: 2016/07/04 01:56:34 $host.version.Major output: 5
2016/07/04 01:56:34 packer.exe: C:\Users\vagrant\packer-windows [hyperv � +1 ~0 -0 !]>
2016/07/04 01:56:34 ui error: Build 'hyperv-iso' errored: Failed creating Hyper-V driver: strconv.ParseInt: parsing "5\r\nC:\\Users\\vagrant\\packer-windows [hyperv \x12 +1 ~0 -0 !]>": invalid syntax
2016/07/04 01:56:34 Builds completed. Waiting on interrupt barrier...
2016/07/04 01:56:34 machine readable: error-count []string{"1"}
2016/07/04 01:56:34 ui error:
==> Some builds didn't complete successfully and had errors:
2016/07/04 01:56:34 machine readable: hyperv-iso,error []string{"Failed creating Hyper-V driver: strconv.ParseInt: parsing \"5\\r\\nC:\\\\Users\\\\vagrant\\\\packer-windows [hyperv \\x12 +1 ~0 -0 !]>\": invalid syntax"}
2016/07/04 01:56:34 ui error: --> hyperv-iso: Failed creating Hyper-V driver: strconv.ParseInt: parsing "5\r\nC:\\Users\\vagrant\\packer-windows [hyperv \x12 +1 ~0 -0 !]>": invalid syntax
2016/07/04 01:56:34 ui:
==> Builds finished but no artifacts were created.
2016/07/04 01:56:34 waiting for all plugin processes to complete...
Build 'hyperv-iso' errored: Failed creating Hyper-V driver: strconv.ParseInt: parsing "5\r\nC:\\Users\\vagrant\\packer-windows [hyperv \x12 +1 ~0 -0 !]>": invalid syntax

==> Some builds didn't complete successfully and had errors:
--> hyperv-iso: Failed creating Hyper-V driver: strconv.ParseInt: parsing "5\r\nC:\\Users\\vagrant\\packer-windows [hyperv \x12 +1 ~0 -0 !]>": invalid syntax

==> Builds finished but no artifacts were created.

Have you covered this issue in a newer version?

@taliesins
Copy link

Have you got a custom prompt? Why is "$host.version.Major" returning the path as well? May be an issue with how we execute powershell on this host when it has powershell 5?

Seems like problem is at:

// check PS is available and is of proper version
versionCmd := "$host.version.Major"

var ps powershell.PowerShellCmd
cmdOut, err := ps.Output(versionCmd)
if err != nil {
    return err
}

versionOutput := strings.TrimSpace(string(cmdOut))
log.Printf("%s output: %s", versionCmd, versionOutput)

ver, err := strconv.ParseInt(versionOutput, 10, 32)

@StefanScherer
Copy link

Yes, I'm using post-git, but even after removing it and logoff/logon the error is the same. Both in cmd and powershell window.

Tried retrieving $host.version.Major and it looks good to me, even with the post-git prompt active.

bildschirmfoto 2016-07-04 um 21 18 55

@PatrickLang
Copy link
Owner Author

Excellent - I pulled your changes back into my branch for testing. Since your packerfiles seem to have all needed changes, I may just close this one.

Also, I should mention that this isn't specific to Windows 10 Insider Preview builds. I'm running the same Vagrant & Packer builds on my Windows 10 - 1511 machine.

Specific build info (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\').BuildLabEx is 10586.420.amd64fre.th2_release_sec.160527-1834

@StefanScherer
Copy link

Thanks for your help starting this enhancement.
In the meantime I've automated the installation + patching of Vagrant 1.8.4 to make it work for Hyper-V https://github.com/StefanScherer/packer-windows/blob/my/hyperv/scripts/install-vagrant.ps1

PatrickLang pushed a commit that referenced this issue Nov 17, 2017
PatrickLang pushed a commit that referenced this issue Sep 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants