VMware Cloud Community
internetrush1
Contributor
Contributor
Jump to solution

PowerCLI and WinRM

$admin = Get-Credential

invoke-command -ComputerName 'server.domain.com

' -Credential $Admin -ArgumentList @($admin) -ScriptBlock {

$cred = $args[0]

if ( -not (Get-PSSnapIn | where {$_.Name -eq "VMware.VimAutomation.Core"}))

{

     Add-PSSnapin -Name "VMware.VimAutomation.Core"

}

if ( -not (Get-PSSnapIn | where {$_.Name -eq "VMware.VimAutomation.Core"}))

{

  Write-Host "ERROR: Could not get snappin, please confirm you have PowerCLI installed"

     break

}

Connect-VIServer -Server @('vcenter1','vcenter2') -Credential $cred -ErrorAction 'Stop'

}

The above code does not work via any box. If i run this on the box it works just fine:

     $admin = Get-Credential

if ( -not (Get-PSSnapIn | where {$_.Name -eq "VMware.VimAutomation.Core"}))

{

     Add-PSSnapin -Name "VMware.VimAutomation.Core"

}

if ( -not (Get-PSSnapIn | where {$_.Name -eq "VMware.VimAutomation.Core"}))

{

  Write-Host "ERROR: Could not get snappin, please confirm you have PowerCLI installed"

     break

}

Connect-VIServer -Server @('vcenter1','vcenter2') -Credential $cred -ErrorAction 'Stop'

Here is the error:

10/24/2013 4:01:00 PM    Connect-VIServer        Exception of type 'System.OutOfMemoryException' was thrown.

    + CategoryInfo          : NotSpecified: (:) [Connect-VIServer], ViError

    + FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_Reconnect_Exception,VMware.VimAutomation.ViCore.Cmdlets.Commands.ConnectVIServer

Can anyone tell me how i can remote into a machine and log into vcenter to run powercli commands?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

I know that MSFT adapted the default memory limits for remote sessions in subsequent releases.

You can try to increase the session memory limit on the destination server with

Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB 1024


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

View solution in original post

0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

Which WINRM version are you running on those servers ?

In WinRM the default memory per session on older Windows versions (WinRM 2) is only 150 MB.

Since you are loading the PowerCLI snapins I would guess you need more.

That would also explain the OutOfMemoryException you are getting.

Have a look at Learn How to Configure PowerShell Memory to see how you can change this default


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

internetrush1
Contributor
Contributor
Jump to solution

The machines im attempting to invoke into are Win2k8 R2 Sp1 standard boxes. Not sure what WINRM version they are running but im guessing WinRM 2 ?

I know we are only on Powershell 2.0.

While that was helpful, ill ask a bit more precise question, what do you recommend? Would 3.0 help? Would the article you sent me alleviate this? Is this solvable without just running PowerCLI on the localhost?    

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I know that MSFT adapted the default memory limits for remote sessions in subsequent releases.

You can try to increase the session memory limit on the destination server with

Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB 1024


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

0 Kudos