Powershell to create multiple ISO bootable images with custom kickstart file
Hi All, I'm using [this script](https://github.com/mikiorla/esxi-kickstart) to create ISOs to automate the ESXi Install. I have modified the relevant parts of the script and it runs and creates the ISOs but they fail. It's giving an error saying it can't locate the KS.CFG file. Upon further digging, I found that it is failing on this section of code:
\--------------------------------------------------------------------------------------------------------
\#Get-ChildItem $copyDestination
Get-ChildItem $copyDestination -Recurse | Set-ItemProperty -Name isReadOnly -Value $false -ErrorAction SilentlyContinue
$bootFile = "$copyDestination\\BOOT.CFG"
$bootFileEFI = "$copyDestination\\EFI\\BOOT\\BOOT.CFG"
$bootFileTitle = Get-Content $bootFile | Select-String "title"
$time = (Get-Date -f "HHmmss")
$newBootFileContent = (Get-Content $bootFile).Replace($bootFileTitle, "title=Loading ESXi installer using kickstart file $time").Replace("kernelopt=cdromBoot runweasel", "kernelopt=cdromBoot runweasel ks=cdrom:/KS\_MILAN.CFG")
Set-Content $bootFile -Value $newBootFileContent -Force
Set-Content $bootFileEFI -Value $newBootFileContent -Force
New-Item -ItemType File -Path $copyDestination -Name "ks\_milan.cfg" -Value ($KS\_CUSTOM | Out-String)
\----------------------------------------------------------------------------------------------------------------------------------
It's this line>
$newBootFileContent = (Get-Content $bootFile).Replace($bootFileTitle, "title=Loading ESXi installer using kickstart file $time").Replace("kernelopt=cdromBoot runweasel", "kernelopt=cdromBoot runweasel ks=cdrom:/KS\_MILAN.CFG")
It changed the Title but not the kernelopt part. It should change it to "kernelopt=cdromBoot runweasel ks=cdrom:/KS\_MILAN.CFG", but it stays as: "kernelopt=runweasel cdromBoot"
Powershell does not give me an error though and I can't figure out why.
Any help is greatly appreciated. Even if I need to create the ISOs for different hosts separately I can do that, we only have 6 in our lab environment and 4 in production. I'm open to different scripts/methods as long as I can get it to work.