VMware Cloud Community
Keuka
Contributor
Contributor

Unable to use New-VM

The attached script errrors out with the following:

New-VM : 7/23/2010 2:18:16 PM New-VM Permission to perform this operation was denied.

At P:\matt\tools\SandboxVM\CreateSandboxVM.ps1:27 char:7

+ New-VM <<<< -VMHost $VMHost -Name $NewVMName -ResourcePool $ResourcePool -Datastore $Datastore -Template $Template -OSCustomizationSpec $OSCustomizationSpec -Description $VMDescription

+ CategoryInfo : NotSpecified: (Smiley Happy , NoPermission

+ FullyQualifiedErrorId : Client20_VMServiceImpl_NewVM_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM

I'm running PowerCLI 4.1

Vitrual Center was just upgraded from 4.0 to 4.1 and my hosts are ESX 4.0 U2

I can log on to VC with the same account and create a new VM without any issues so I don't suspect an actual permissions issue with the account. This worked before upgrading VC.

Any suggestions welcome...

Thanks!

  1. Variables

$StartTime = Get-Date

$EmailAddress = Read-Host "Enter your email address"

$NewVMName = Read-Host "Enter desired Vitrual Machine host name"

$Template = "_TEMPLATE-Sandbox"

$ResourcePool = "Sandbox"

$Datastore = "OVMESX-SATA-Sandbox1"

$OSCustomizationSpec = "SandboxOSTemplate"

$VMHost = "esxhost.domain"

$CS = Gwmi Win32_ComputerSystem -Comp "."

$VMDescription = "Created on " + $StartTime + " by " + $CS.UserName

  1. Connect to the vSphere server

Connect-VIServer -Server vc.domain

  1. Create a new VM in the specified datacenter/host and resource pool using a preconfigured template and customization script.

New-VM -VMHost $VMHost -Name $NewVMName -ResourcePool $ResourcePool -Datastore $Datastore -Template $Template -OSCustomizationSpec $OSCustomizationSpec -Description $VMDescription

  1. Start the new VM to allow the customization script to be executed.

Start-VM $NewVMName

  1. Disconnect from the vShpere server

Disconnect-VIServer -Server vc.domain -Force -Confirm:$False

  1. Delay 15 minutes then eMail the requestor to notify that the VM is ready for use and include the name and local account credentials

$StopTime = Get-Date

Start-Sleep -Seconds 900

$emailFrom = "support@domain.com"

$subject = "New VM " + $NewVMName + " has been Created"

$body = "The new VM you requested is ready for use." + "`n" + "`n"

$body = $body + "Access it via RDP at " + $NewVMName + ".domain with the following credentials: xxx/yyy$" + "`n" + "`n"

$body = $body + "Start Time: " + $StartTime + "`n"

$body = $body + "Stop Time: " + $StopTime + "`n"

$smtpServer = "smtp.domain.com"

$smtp = new-object System.Net.Mail.SmtpClient($smtpServer)

$smtp.Send($emailFrom, $EmailAddress, $subject, $body)

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership

Can't see anything obviously wrong.

I would suggest you follow the procedure in the Dealing with the inevitable events in life – reporting problems with PowerCLI post.

Perhaps the logs can make someone a bit wiser.

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Keuka
Contributor
Contributor

Thanks

Reply
0 Kudos