VMware Cloud Community
nmdhussain
Contributor
Contributor

force 32 bit powershell in windows server

HI,

Am trying to create vm from templete using new-vm cmdlet but unfortunately it works only in 32 bit os, Am using windows server2008 which have two powershells 32 bit and 64 bit. I want to call powershell script from C# and by default 64 bit version is called and failing. Am compiling my C# exe targetting to x86 platform. The powershell code am trying with is below. Error is shown at new-vm line. Any help will be appreciated. Thanks

Add-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue
$server=$args[0]
$user=$args[1]
$password=$args[2]
$templateName=$args[3]
$vmName=$args[4]
$vmHost=$args[5]
$dataStore=$args[6]
#$folderName=$args[7]
if ($args.count -lt 7)
{
    #Write-Host "Error:Insufficient parameters passed" -foregroundcolor red
    return -1
}
else
{
    #connect to vcenter server
    $ServerObj=Connect-VIServer -Server $server -User $user -Password $password -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
  
    if($ServerObj -eq $null)
    {
        #Write-Host "Error:Could not connect to the vcenter server" -foregroundcolor red
        return -2
    }
    else
    {
        $VmExists = Get-VM -Name $vmname -ErrorAction SilentlyContinue
        if ($VmExists)
        {
            #Write-Host "Error:Vm with the same name exists" -foregroundcolor red
            Disconnect-VIServer -Server $ServerObj -Confirm:$false
            return -3
        }
        else
        {
           #new-vm -Location $folderName -vmhost $vmHost -Name $vmName -Template $templateName -Datastore $dataStore
           new-vm -vmhost $vmHost -Name $vmName -Template $templateName -Datastore $dataStore
        }
    }
    #disconnect from vcenter server
    Disconnect-VIServer -Server $ServerObj -Confirm:$false
    return 0
}
Reply
0 Kudos
0 Replies