The CreatorCon Call for Content is officially open! Get started here.

Powershell script error with VMWare PowerCLI

jvianale
Giga Contributor

We are getting the below error with orchestration running powershell scripts using VMware   PowerCLI, believe the import module   Initialize-PowerCLIEnvironment_Custom.ps1 maybe causing the issue

Script (runs find from the command prompt)

import-module "C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1"

Connect-VIServer -Server xxxxxxxxx -User xxxxx -Password xxxxxx

Connect-VIServer -Server xxxxxxxxx -User xxxxx -Password xxxxxx

Connect-VIServer -Server xxxxxxxxx -User xxxxx -Password xxxxxx

Get-NetworkAdapter lab-obaapp2 | Set-NetworkAdapter -Connected:0 -Confirm:0

Output error

Windows PowerShell is in NonInteractive mode. Read and Prompt functionality is not available.Stack Trace:       at Microsoft.PowerShell.ConsoleHostUserInterface.PromptForChoice(String caption, String message, Collection`1 choices, Int32 defaultChoice)at System.Management.Automation.Internal.Host.InternalHostUserInterface.PromptForChoice(String caption, String message, Collection`1 choices, Int32 defaultChoice)at System.Management.Automation.MshCommandRuntime.InquireHelper(String inquireMessage, String inquireCaption, Boolean allowYesToAll, Boolean allowNoToAll, Boolean replaceNoWithHalt, Boolean hasSecurityImpact)at System.Management.Automation.MshCommandRuntime.DoShouldContinue(String query, String caption, Boolean hasSecurityImpact, Boolean supportsToAllOptions, Boolean& yesToAll, Boolean& noToAll)at System.Management.Automation.MshCommandRuntime.ShouldContinue(String query, String caption)at System.Management.Automation.Cmdlet.ShouldContinue(String query, String caption)at VMware.VimAutomation.ViCore.Cmdlets.Commands.ConnectVIServer.ProcessRecordErrorHandled()at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.ErrorCallbackCmdletBase.ProcessRecord()at System.Management.Automation.CommandProcessor.ProcessRecord()

1 ACCEPTED SOLUTION

jvianale
Giga Contributor

This thread should help Windows PowerShell is in NonInteractive mode


Example



import-module "C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1"


if (test-path env:\SNC_EXIHost1) {


  $EXIHost1=$env:SNC_EXIHost1;


  $User=$env:SNC_User;


  $Password=$env:SNC_Password;


  $NetworkAdapter=$env:SNC_NetworkAdapter;


Connect-VIServer -Server $EXIHost1 -User $User -Password $Password;


    };


Get-NetworkAdapter   $NetworkAdapter | Set-NetworkAdapter -Connected:0 -Confirm:0


View solution in original post

1 REPLY 1

jvianale
Giga Contributor

This thread should help Windows PowerShell is in NonInteractive mode


Example



import-module "C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1"


if (test-path env:\SNC_EXIHost1) {


  $EXIHost1=$env:SNC_EXIHost1;


  $User=$env:SNC_User;


  $Password=$env:SNC_Password;


  $NetworkAdapter=$env:SNC_NetworkAdapter;


Connect-VIServer -Server $EXIHost1 -User $User -Password $Password;


    };


Get-NetworkAdapter   $NetworkAdapter | Set-NetworkAdapter -Connected:0 -Confirm:0