cloudbase / windows-imaging-tools

Tools to automate the creation of a Windows image for OpenStack, supporting KVM, Hyper-V, ESXi and more.
Apache License 2.0
671 stars 227 forks source link

The New-WindowsOnlineImage return Error: Input string was not in a correct format.. #271

Closed chaoMaster closed 5 years ago

chaoMaster commented 5 years ago

When I run the New-WindowsOnlineImage command, it told me the Error formatting string

New-WindowsOnlineImage -ConfigFilePath $ConfigFilePath
6/13/2019 4:53:08 PM - Windows online image generation started.
New-WindowsOnlineImage : Error formatting a string: Input string was not in a correct format..
At line:1 char:1
+ New-WindowsOnlineImage -ConfigFilePath $ConfigFilePath
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Selected switch...ce = true flag.:String) [New-WindowsOnlineImage], R
   untimeException
    + FullyQualifiedErrorId : FormatError,New-WindowsOnlineImage

The PowerShell version:

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.17763.503
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17763.503
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

The config.ini detail:

[DEFAULT]
# The location of the WIM file from the mounted Windows ISO.
wim_file_path=D:\win_server_2016\sources\install.wim
# This is the complete name of the Windows version that will be generated.
# In order to find the possible options, use the Get-WimFileImagesInfo command
# and look for the Name property.
image_name=Windows Server 2016 SERVERSTANDARDCORE
# The destination of the generated image.
image_path=D:\winserver2016.vhdx
# Select between VHD, VHDX, QCOW2, VMDK or RAW formats.
virtual_disk_format=VHDX
# This parameter allows to choose between MAAS, KVM, VMware and Hyper-V specific images.
# For HYPER-V, cloudbase-init will be installed and the generated image should be in vhd or vhdx format.
# For MAAS, in addition to cloudbase-init, the curtin tools are installed
# and the generated image should be in raw.tgz format.
# For KVM, in addition to cloudbase-init, the VirtIO drivers are installed
# and the generated image should be in qcow2 format.
image_type=HYPER-V
# This parameter can be set to either BIOS or UEFI.
disk_layout=BIOS
# The product key for the selected OS.
product_key=""
# A comma separated array of extra features that will be enabled on the resulting image.
# These features need to be present in the ISO file.
extra_features=""
# A comma separated array of extra capabilities that will be enabled on the resulting image.
# These capabilities need to be present in the ISO file.
extra_capabilities=""
# It will force the image generation when RunSysprep is False or the selected SwitchName
# is not an external one. Use this parameter with caution because it can easily generate
# unstable images.
force=False
# If set to true, MAAS Windows curtin hooks will be copied to the image root directory.
install_maas_hooks=False
# Select between tar, gz, zip formats or any combination between these.
compression_format=""
# If this parameter is set, after the image is generated,
# a password protected zip archive with the image will be created.
zip_password=""
# It will stop the image generation after the updates are installed and cleaned.
gold_image=False
# This is the full path of the already generated golden image.
# It should be a valid VHDX path.
gold_image_path=""
# This is a full path to the VMware-tools.exe version that you want to install.
vmware_tools_path=""
# This is the full path of a folder with custom resources which will be used by
# the custom scripts.
# The resources found at this path will be copied recursively to the image
# UnattendResources\CustomResources folder.
custom_resources_path=""
# This is the full path of the folder which can contain a set of PS scripts,
# that will be copied and executed during the online generation part on the VM.
# The PowerShell scripts, if existent, will be started by Logon.ps1 script,
# at different moments during image generation.
# The purpose of these scripts is to offer to the user a fully
# customizable way of defining additional logic for tweaking the final image.
# The scripts files can have the following names: RunBeforeWindowsUpdates.ps1,
# RunAfterWindowsUpdates.ps1, RunBeforeCloudbaseInitInstall.ps1, RunAfterCloudbaseInitInstall.ps1,
# RunBeforeSysprep.ps1, RunAfterSysprep.ps1.
# The script names contain the information on when the script will be executed.
# One can define only some of the hook scripts and it is not mandatory to define all of them.
# If a script does not exist, it will not be executed.
custom_scripts_path=""
# If set to true the Administrator account will be enabled on the client
# versions of Windows, which have the Administrator account disabled by default
enable_administrator_account=False
# If set, it will replace the Cloudbase Solutions wallpaper to the one specified.
# The wallpaper needs to be a valid .jpg/.jpeg image.
wallpaper_path=""
# If set, it will replace the Cloudbase Solutions wallpaper to a solid color.
# Currently, the only allowed solid color is '0 0 0' (black).
# If both wallpaper_path and wallpaper_solid_color are set,
# the script will throw an error.
wallpaper_solid_color=""
# If set to true and the target image format is QCOW2, the image conversion will
# use qemu-img built-in compression. The compressed qcow2 image will be smaller, but the conversion
# will take longer time.
compress_qcow2=False
# A comma separated list of extra packages (referenced by filepath)
# to slipstream into the underlying image.
# This allows additional local packages, like security updates, to be added to the image.
extra_packages=""
[vm]
# This will be the Administrator user's, so that AutoLogin can be performed on the instance,
# in order to install the required products,
# updates and perform the generation tasks like sysprep.
administrator_password=stack@vnet
# Used to specify the virtual switch the VM will be using.
# If it is specified but it is not external or if the switch does not exist,
# you will get an error message.
external_switch=external
# The number of CPU cores assigned to the VM used to generate the image.
cpu_count=4
# RAM (in bytes) assigned to the VM used to generate the image.
ram_size=42949672960
# Disk space (in bytes) assigned to the VM used to generate the image.
disk_size=21474836480
[drivers]
# The path to the ISO file containing the VirtIO drivers.
virtio_iso_path=D:\virtio-win.iso
# The location where the VirtIO drivers are found.
# For example, the location of a mounted VirtIO ISO. VirtIO versions supported >=0.1.6.x
virtio_base_path=""
# The location where additional drivers that are needed for the image are located.
drivers_path=""
[updates]
# If set to true, the latest updates will be downloaded and installed.
install_updates=False
# If set to true, will run DISM with /resetbase option. This will reduce the size of
# WinSXS folder, but after that Windows updates cannot be uninstalled.
purge_updates=False
[sysprep]
# Used to clean the OS on the VM, and to prepare it for a first-time use.
run_sysprep=True
# The path to the Unattend XML template file used for sysprep.
unattend_xml_path=UnattendTemplate.xml
# DisableSwap option will disable the swap when the image is generated and will add a setting
# in the Unattend.xml file which will enable swap at boot time during specialize step.
# This is required, as by default, the amount of swap space on Windows machine is directly
# proportional to the RAM size and if the image has in the initial stage low disk space,
# the first boot will fail due to not enough disk space. The swap is set to the default
# automatic setting right after the resize of the partitions is performed by cloudbase-init.
disable_swap=False
# In case the hardware on which the image is generated will also be the hardware on
# which the image will be deployed this can be set to true, otherwise the spawned
# instance is prone to BSOD.
persist_drivers_install=True
[cloudbase_init]
# This is a switch that allows the selection of Cloudbase-Init branches. If set to true, the
# beta branch will be used:
# https://cloudbase.it/downloads/CloudbaseInitSetup_<arch>.msi, where arch can be x86 or x64
# otherwise the stable branch will be used:
# https://cloudbase.it/downloads/CloudbaseInitSetup_Stable_<arch>.msi, where arch can be x86 or x64
beta_release=False
# Serial log port for Cloudbase-Init.
# If set to null, the first serial port (if any) from the generation VM will be used
serial_logging_port=COM1
# If set, the Cloudbase-Init msi at this path will be used.
# The path needs to be a locally accesible file path.
msi_path=""
ilenghel commented 5 years ago

Hello

Can you please try to call the New-WindowsOnlineImage function with the actual path of the config.ini instead of the variable?

I have tested your config file with a couple of changes, needed to reflect my system configuration, but it worked just fine. I changed:

Please also check that you are using the latest master code. Let us know if you manage to get it working.

chaoMaster commented 5 years ago

It's still returning this Error:

PS C:\windows-openstack-imaging-tools> git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
PS C:\windows-openstack-imaging-tools> Import-Module .\WinImageBuilder.psm1
PS C:\windows-openstack-imaging-tools> Import-Module .\Config.psm1
PS C:\windows-openstack-imaging-tools> Import-Module .\UnattendResources\ini.psm1
PS C:\windows-openstack-imaging-tools> New-WindowsOnlineImage -ConfigFilePath .\config.ini
6/14/2019 9:07:37 AM - Windows online image generation started.
New-WindowsOnlineImage : Error formatting a string: Input string was not in a correct format..
At line:1 char:1
+ New-WindowsOnlineImage -ConfigFilePath .\config.ini
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Selected switch...ce = true flag.:String) [New-WindowsOnlineImage], R
   untimeException
    + FullyQualifiedErrorId : FormatError,New-WindowsOnlineImage
VuNgocTan commented 5 years ago

Hi, I have the same issue, my previous Windows version to use to create image was 2012r2, I tried some work around like update PS to latest version but still no luck, I tried to install windows 2016 and it can create the image now, dont know what is the root cause but if you are using VM to create image, try to reinstall it to newer version of windows.

ader1990 commented 5 years ago

@chaoMaster do you have an English version of Windows? The error you got might be a string parsing or a Powershell quirk that is a little bit harder to debug.

Thank you, Adrian Vladu

ader1990 commented 5 years ago

@chaoMaster Can you also run only 'Get-WindowsImageConfig $ConfigFilePath'?

ader1990 commented 5 years ago

The error you got was because of the fact that the VM switch you used was not an external one. The proper error message was fixed by https://github.com/cloudbase/windows-openstack-imaging-tools/pull/256