Hi Guyz,
do you guyz have any powershell script for ESXI which create VMs with static ip and add them into domain.
Any help will be appreciated
TIA
Have you done any Internet searching yourself? How about any attempts at beginning a script yourself? Generally speaking, going to a forum and asking people to hand things over to you isn't appropriate. Read the first post in my signature.
$fileName = 'whatever.csv'
foreach($vmLine in (Import-Csv -Path $fileName -UseCulture)){
# Create VM
$vm = New-VM -Name $vmLine.Server -VMHost $vmLine.EsxHost -Datastore $vmLine.Datastore -Template $vmLine.Template
Get-NetworkAdapter -VM $vm | Set-NetworkAdapter -NetworkName $vmLine.Network -StartConnected -Confirm:$false
# Wait till VM is running
Start-VM -VM $vm
while($vm.Guest.State -ne 'running'){
$vm = Get-VM -Name $vm.Name
sleep 5
}
# Configure guest OS network
$netsh = "c:\windows\system32\netsh.exe interface ip set address ""Local Area Connection"" static $($vmLine.IPAddress) $($vmLine.NetMask) $($vmLine.Gateway) 1"
Invoke-VMScript -VM $VM -ScriptType bat -ScriptText $netsh
$netsh = "c:\windows\system32\netsh.exe interface ip set dns ""Local Area Connection"" static $($vmLine.FirstDNS) $($vmLine.SecondDns)"
Invoke-VMScript -VM $VM -ScriptType bat -ScriptText $netsh
}
i have tried this above script but it is showing below error
New-VM : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and
then try the command again.
At line:13 char:24
+ $vm = New-VM -Name
What is in the CSV you are using?
Is there a column Server in there?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Name | EsxHost | Datastore | Template | IPAddress | Gateway | FirstDNS | SecondDNS |
this is my csv file
I suspect you used Name while the script uses Server.
Change that column name.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Man now i am able to create the VMs but after that it is showing below error
Set-NetworkAdapter : Missing an argument for parameter 'StartConnected'. Specify a parameter of type 'System.Boolean' and try again.
At line:9 char:82
+ ... vmLine.Network -StartConnected -Confirm:$false
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-NetworkAdapter], ParameterBindingException
+ FullyQualifiedErrorId : MissingArgument,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.SetNetworkAdapter
You need to provide a Boolean value to that parameter.
Set-NetworkAdapter -NetworkName $vmLine.Network -StartConnected:$true -Confirm:$false
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
now it is showing this below error
Set-NetworkAdapter : Cannot validate argument on parameter 'NetworkName'. The argument is null. Provide a valid value for the argument, and then try running
the command again.
At line:1 char:66
+ Get-NetworkAdapter -VM $vm | Set-NetworkAdapter -NetworkName $vmLine.Network ...
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Set-NetworkAdapter], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.SetNetworkAdapter
fixed the above issue now facing the below issue
Invoke-VMScript : 17-05-2020 22:03:24 Invoke-VMScript Failed to authenticate with the guest operating system using the supplied credentials.
At line:3 char:5
+ Invoke-VMScript -VM $VM -ScriptType bat -ScriptText $netsh
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Invoke-VMScript], InvalidGuestLogin
+ FullyQualifiedErrorId : Client20_VmGuestServiceImpl_GetGuestAuthentication_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.InvokeVmScript
You have to provide credentials to logon/run in the Guest OS
Invoke-VMScript -VM $VM -ScriptType bat -ScriptText $netsh -GuestCredential (Get-Credential)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference