Hi Everyone,
I need to use powershell to do New-OSCustomizationSpec with LINUX OS type script.
The operation on the web page is normal.
But I can't find POWERSHEll related API or command.
Can this be done with powershell or Powercli?
Thank you very much!
Yes, on the New-OSCustomizationSpec cmdlet the OStype parameter can be set to Linux.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc.
But I don't want to set the OS-type parameter.
I wish to set customization script in powershell script,like this.
Hope to give advice,
Thank you!
I have got the content of this script by powershell command.
I wished to modify it but failed.
Can you offer some advice?
Thank you very much!
can you tell me what exact modification you want to make?
How did you make that change?
First, a call to GetCustomizationSpec, followed by a call to OverwriteCustomizationSpec?
In the CustomizationSpecItem you have to update Spec.Identity.ScriptText
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Nice to meet you!
Yes,I want to change the password of the operating system in this way.
Windows virtual machines can set different passwords through custom specifications.
But LINUX does not seem to have this parameter.
So I found this way with script.
The script has been written and the test passed, the content is as follows:
Tested by creating a virtual machine from the template, it succeeded, the password for the OS was changed, and the "zjy.out" file was also generated in the root directory.
Up to now, the operation is carried out on the website.
I want to be able to pass in this script when creating a new virtual machine customization specification through powershell.
I can't find the relevant parameters to pass this script when generating the virtual machine customization spec.Like this
I know that there is a way to change the password of the virtual machine through Invoke-VMScript, but I don't know the original password of the virtual machine.
So I hope to modify it through powershell, not through the web page.
thank you for your reply!
Hi Luc!
I want to be able to do it via powershell.
Could you please help write a sample? thank you very much!
The New-OSCustomizatonSpec cmdlet does not have the option to add a script.
But you can combine the New-OSCustomizationSpec cmdlet with a call to the API method to add the script.
Something like this for example.
$script = @'
#!/bin/sh
if [ x$1 == x"precustomization" ]; then
echo 'root:zjy@123' | chpasswd
elif [ x$1 == x"postcustomization" ]; then
echo test >> zjy.out
fi
'@
$osCustName = 'LinuxCust'
# Cleanup
Get-OSCustomizationSpec -Name $osCustName -ErrorAction SilentlyContinue | Remove-OSCustomizationSpec -Confirm:$false -ErrorAction SilentlyContinue
# Create new Spec
New-OSCustomizationSpec -Name $osCustName -OSType 'Linux' -Domain 'domain.com' -NamingScheme 'vm' | Out-Null
$custMgr = Get-View CustomizationSpecManager
# Add script to Spec
$p = $custMgr.GetCustomizationSpec($osCustName)
$p.Spec.Identity.ScriptText = $script
$custMgr.OverwriteCustomizationSpec($p)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This is all I need, thanks a lot!