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

can't run the powershell #166

Closed pennpeng closed 5 years ago

pennpeng commented 6 years ago

OS: win10 1703(15063.608)

PS D:\git\windows-openstack-imaging-tools\Examples> D:\git\windows-openstack-imaging-tools\Examples\create-windows-cloud-image.ps1
Image generation started at: 2017/9/19 10:49:05
Transform-Xml : 使用“3”个参数调用“AddParam”时发生异常:“值不能为 null。
参数名: parameter”
所在位置 D:\git\windows-openstack-imaging-tools\WinImageBuilder.psm1:281 字符: 5
+     Transform-Xml "$scriptPath\Unattend.xslt" $inUnattendXmlPath $out ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Transform-Xml], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentNullException,Transform-Xml

PS D:\git\windows-openstack-imaging-tools\Examples>
ader1990 commented 6 years ago

Hello,

Are you using the master branch? If that is the case, can you try with the experimental branch? For better logging, can you also run this command before? Set-PSDebug -Trace 1

Thank you, Adrian Vladu

pennpeng commented 6 years ago

@ader1990 yes, i use the master branch。

PS D:\git\windows-openstack-imaging-tools\Examples> .\create-windows-cloud-image.ps1
调试:    1+  >>>> .\create-windows-cloud-image.ps1
调试:   15+  >>>> $ErrorActionPreference = "Stop"
调试:   17+  >>>> git submodule update --init
调试:   18+  >>>> Import-Module ..\WinImageBuilder.psm1
调试:    1+  >>>> $ErrorActionPreference = "Stop"
调试:    2+  >>>> Set-StrictMode -Version 2
调试:    3+  >>>> Import-Module Dism
调试:    1+  >>>> @{
调试:   15+          >>>> 'Add-AppxProvisionedPackage',
调试:   35+          >>>> 'Get-WindowsOptionalFeature',
调试:   11+  >>>> Set-Alias Apply-WindowsUnattend Use-WindowsUnattend
调试:   12+  >>>> Set-Alias Add-ProvisionedAppxPackage Add-AppxProvisionedPackage
调试:   13+  >>>> Set-Alias Remove-ProvisionedAppxPackage Remove-AppxProvisionedPackage
调试:   14+  >>>> Set-Alias Get-ProvisionedAppxPackage Get-AppxProvisionedPackage
调试:   16+  >>>> Export-ModuleMember -Alias * -Function * -Cmdlet *
调试:    5+  >>>> $scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Definition
调试:    6+  >>>> $localResourcesDir = "$scriptPath\UnattendResources"
调试:    7+  >>>> $noHypervWarning = @"
调试:   18+  >>>> $noSysprepWarning = @"
调试:   25+  >>>> $VirtIODrivers = @("balloon", "netkvm", "pvpanic", "qemupciserial", "qxl",
调试:   28+  >>>> $VirtIODriverMappings = @{
调试:   40+  >>>> . "$scriptPath\Interop.ps1"
调试:    1+  >>>> $code  = @"
调试: 1351+ if ( >>>> -not ([System.Management.Automation.PSTypeName]'WIMInterop.WimFile').Type)
调试: 1353+      >>>> Add-Type -TypeDefinition $code -ReferencedAssemblies
"System.Xml","System.Linq","System.Xml.Linq"
调试: 1405+  >>>> Export-ModuleMember New-WindowsCloudImage, Get-WimFileImagesInfo, New-MaaSImage, Resize-VHDImage,
调试:   21+  >>>> $virtualDiskPath = "D:\images\windows-2008E-image.raw"
调试:   24+  >>>> $wimFilePath = "E:\Sources\install.wim"
调试:   27+  >>>> $VirtIOISOPath = "D:\images\virtio-win.iso"
调试:   37+  >>>> $extraDriversPath = "C:\drivers\"
调试:   41+  >>>> $image = (Get-WimFileImagesInfo -WimFilePath $wimFilePath)[2]
调试:  109+      >>>> {
调试:  110+          >>>> $w = Get-WimInteropObject $WimFilePath
调试:   84+ function Get-WimInteropObject  >>>> {
调试:   89+     return  >>>> (New-Object WIMInterop.WimFile -ArgumentList $WimFilePath)
New-Object : 使用“1”个参数调用“.ctor”时发生异常:“无法找到指定文件。”
所在位置 D:\git\windows-openstack-imaging-tools\WinImageBuilder.psm1:89 字符: 13
+     return (New-Object WIMInterop.WimFile -ArgumentList $WimFilePath)
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [New-Object],MethodInvocationException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
pennpeng commented 6 years ago

use experimental branch, also error,and i can't edit anyting

PS D:\git\windows-openstack-imaging-tools\Examples> & '.\create-windows-cloud-image.ps1'
所在位置 D:\git\windows-openstack-imaging-tools\Examples\create-windows-cloud-image.ps1:71 字符: 85
+ ...  -Path $fCfgPath -Section "sysprep" -Key "disable_swap" -Value "True"
+                                                                         ~
字符串缺少终止符: "。
    + CategoryInfo          : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
pennpeng commented 6 years ago

the file;

# Copyright 2016 Cloudbase Solutions Srl
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

$ErrorActionPreference = "Stop"

$scriptPath =Split-Path -Parent $MyInvocation.MyCommand.Definition | Split-Path
git submodule update --init
if ($LASTEXITCODE) {
    throw "Failed to update git modules."
}

try {
    Join-Path -Path $scriptPath -ChildPath "\WinImageBuilder.psm1" | Remove-Module -ErrorAction SilentlyContinue
    Join-Path -Path $scriptPath -ChildPath "\Config.psm1" | Remove-Module -ErrorAction SilentlyContinue
    Join-Path -Path $scriptPath -ChildPath "\UnattendResources\ini.psm1" | Remove-Module -ErrorAction SilentlyContinue
} finally {
    Join-Path -Path $scriptPath -ChildPath "\WinImageBuilder.psm1" | Import-Module
    Join-Path -Path $scriptPath -ChildPath "\Config.psm1" | Import-Module
    Join-Path -Path $scriptPath -ChildPath "\UnattendResources\ini.psm1" | Import-Module
}

# The Windows image file path that will be generated
$virtualDiskPath = "D:\images\win2008e-image.raw"

# The wim file path is the installation image on the Windows ISO
$wimFilePath = "E:\Sources\install.wim"

# VirtIO ISO contains all the synthetic drivers for the KVM hypervisor
$virtIOISOPath = "D:\images\virtio-win.iso"
# Note(avladu): Do not use stable 0.1.126 version because of this bug https://github.com/crobinso/virtio-win-pkg-scripts/issues/10
# $virtIODownloadLink = "https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.133-2/virtio-win.iso"

# Download the VirtIO drivers ISO from Fedora
# (New-Object System.Net.WebClient).DownloadFile($virtIODownloadLink, $virtIOISOPath)

# Extra drivers path contains the drivers for the baremetal nodes
# Examples: Chelsio NIC Drivers, Mellanox NIC drivers, LSI SAS drivers, etc.
# The cmdlet will recursively install all the drivers from the folder and subfolders
$extraDriversPath = "C:\drivers\"

# Every Windows ISO can contain multiple Windows flavors like Core, Standard, Datacenter
# Usually, the second image version is the Standard one
$image = (Get-WimFileImagesInfo -WimFilePath $wimFilePath)[1]

# The path were you want to create the config fille
$configFilePath = Join-Path $scriptPath "Examples\config.ini
New-WindowsImageConfig -ConfigFilePath $configFilePath
$fCfgPath = Resolve-Path $configFilePath

#This is an example how to automate the image configuration file according to your needs
Set-IniFileValue -Path $fCfgPath -Section "Default" -Key "wim_file_path" -Value $wimFilePath
Set-IniFileValue -Path $fCfgPath -Section "Default" -Key "image_name" -Value $image.ImageName
Set-IniFileValue -Path $fCfgPath -Section "Default" -Key "image_path" -Value $virtualDiskPath
Set-IniFileValue -Path $fCfgPath -Section "Default" -Key "virtual_disk_format" -Value "RAW"
Set-IniFileValue -Path $fCfgPath -Section "vm" -Key "disk_size" -Value (30GB)
Set-IniFileValue -Path $fCfgPath -Section "drivers" -Key "virtio_iso_path" -Value $virtIOISOPath
Set-IniFileValue -Path $fCfgPath -Section "drivers" -Key "drivers_path" -Value $extraDriversPath
Set-IniFileValue -Path $fCfgPath -Section "updates" -Key "install_updates" -Value "False"
Set-IniFileValue -Path $fCfgPath -Section "updates" -Key "purge_updates" -Value "True"
Set-IniFileValue -Path $fCfgPath -Section "sysprep" -Key "disable_swap" -Value "True"

# This scripts generates a raw image file that, after being started as an instance and
# after it shuts down, it can be used with Ironic or KVM hypervisor in OpenStack.
New-WindowsCloudImage -ConfigFilePath $configFilePath
ader1990 commented 6 years ago

This might be an issue with the Windows language and default encoding/line endings. You can try to use the Notepad.exe editor if you want to edit the files and before cloning the repo, setting the git commit policy: git config --global core.autocrlf false

Thank you, Adrian Vladu

pennpeng commented 6 years ago

@ader1990 hi, i found it's your mistake。 line 57 :

$configFilePath = Join-Path $scriptPath "Examples\config.ini

you miss the "

pennpeng commented 6 years ago

but also the same problem:

PS D:\git\windows-openstack-imaging-tools\Examples> .\create-windows-cloud-image.ps1

    目录: D:\git\windows-openstack-imaging-tools\Examples

Mode                LastWriteTime         Length Name                                                                                         
----                -------------         ------ ----                                                                                         
-a----        2017/9/21     20:15              0 config.ini                                                                                   
Image generation started at: 2017/9/21 20:15:18
Transform-Xml : 使用“3”个参数调用“AddParam”时发生异常:“值不能为 null。
参数名: parameter”
所在位置 D:\git\windows-openstack-imaging-tools\WinImageBuilder.psm1:306 字符: 5
+     Transform-Xml "$scriptPath\Unattend.xslt" $inUnattendXmlPath $out ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Transform-Xml], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentNullException,Transform-Xml
pennpeng commented 6 years ago

online also the problem:

PS D:\git\windows-openstack-imaging-tools\Examples> .\create-windows-online-cloud-image.ps1

    目录: D:\git\windows-openstack-imaging-tools\Examples

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        2017/9/21     20:32              0 config.ini
Windows online image generation started at: 2017/9/21 20:32:40
Image generation started at: 2017/9/21 20:32:49
使用“3”个参数调用“AddParam”时发生异常:“值不能为 null。
参数名: parameter”
Transform-Xml : 使用“3”个参数调用“AddParam”时发生异常:“值不能为 null。
参数名: parameter”
所在位置 D:\git\windows-openstack-imaging-tools\WinImageBuilder.psm1:306 字符: 5
+     Transform-Xml "$scriptPath\Unattend.xslt" $inUnattendXmlPath $out ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Transform-Xml], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentNullException,Transform-Xml

PS D:\git\windows-openstack-imaging-tools\Examples>
ader1990 commented 6 years ago

Hello again,

Please make sure that you run in a PowerShell elevated (and not PowerShell ISE) the generation command. Also, run "Set-PSDebug -Trace 1" before starting the generation, to provide us with more logs. Can you provide the obtained logs via a http://pastebin.com like site?

Thank you, Adrian Vladu

ader1990 commented 6 years ago

@pennpeng have you solved the issue?