VMware Cloud Community
fixitchris
Hot Shot
Hot Shot
Jump to solution

What happens to session if Disconnect-ViServer is not called?

What happens to an active session if Disconnect-ViServer is not called and powershell exits?

The problem I am running into is with PowershellASP:

The code here works great:

But, if I add :

<% Disconnect-VIServer -server $host1  -confirm:$false %>

Then PoweshellASP gives this error on Disconnect-VIserver cmdlet:

 Cannot invoke this function because the current host does not implement it.

Any ideas?

Reply
0 Kudos
1 Solution

Accepted Solutions
admin
Immortal
Immortal
Jump to solution

The trouble is actually due to Disconnect-VIServer trying to change the window title, which PowerShellASP doesn't support (I surmise).

You can use this code to disconnect:

(get-view serviceinstance).Client.Logout()

View solution in original post

Reply
0 Kudos
7 Replies
admin
Immortal
Immortal
Jump to solution

The trouble is actually due to Disconnect-VIServer trying to change the window title, which PowerShellASP doesn't support (I surmise).

You can use this code to disconnect:

(get-view serviceinstance).Client.Logout()

Reply
0 Kudos
fixitchris
Hot Shot
Hot Shot
Jump to solution

That piece of code completed ok. Thanks.

Can you explain or point me tosome documentation for

(get-view serviceinstance).Client.Logout()

especially the

(get-view serviceinstance)

cmdlet reference, reflector?

Reply
0 Kudos
yboychev
Hot Shot
Hot Shot
Jump to solution

+"The ServiceInstance is a managed object. It is the

singleton root object of the inventory on both vCenter servers and servers

running on standalone host agents. The server creates the ServiceInstance automatically, and also

automatically creates the various manager entities that provide services in the

virtual environment."+ You can search for more info on the ServiceInstanse managed object in: http://www.vmware.com/support/developer/vc-sdk/visdk25pubs/ReferenceGuide

On the other hand the Get-View cmdlet retrieves the view of a managed object. A view is a static copy of a server-side managed object. It is not updated autoamticaly if you update the server-side object (you have to call the UpdateViewData() method of the view object) You can find more info and examples in AdminGuide document located in the instalation folder of the toolkit

fixitchris
Hot Shot
Hot Shot
Jump to solution

Thanks for the explanation...

$MyHost = Connect-VIServer -Server $creds.host -User $creds.User -Password $creds.Password;
$MyHostMO = Get-VMHost $MyHost | Get-View;

Why can't I do :

$MyHostMO = Get-View Get-VMhost  

Reply
0 Kudos
admin
Immortal
Immortal
Jump to solution

If you run "help get-view" you'll see that it has 3 signatures.

If you use:

Get-VMHost | Get-View

PowerShell will use the 3rd signature, since you're piping an object in and this is the only signature that accepts pipeline input. That means that the thing piped in is cast to a VIObject.

For tthe code

Get-View Get-VMHost

, Get-VMHost is just a string, which Get-View will try to treat as an ID. A similar bit of code that would work is:

Get-View -VIObject (Get-VMHost)

. Personally I like the pipeline way of doing it a lot better.

fixitchris
Hot Shot
Hot Shot
Jump to solution

I get it...

$MyDS = Get-Datastore -Name Datastore1 | Get-View;
$MyDS2 = Get-View -VIObject (Get-Datastore -Name Datastore1)
$MyDS3 = Get-View -VIObject (Get-Datastore)

And I am assuming that

$MyDS3 = Get-View -VIObject (Get-Datastore)

would return a collection of all datastores?

And VIOBJECT is just a Manged Object of Managed Entity abstract class?

So in Get-View can only be of Vim.ManagedObjectReference.

So...

$MySI = (Get-View ServiceInstance);
$MySI.Content.UserDirectory | Get-Member
TypeName   : VMware.Vim.ManagedObjectReference
Name       : Equals
MemberType : Method
Definition : System.Boolean Equals(Object obj)


TypeName   : VMware.Vim.ManagedObjectReference
Name       : GetHashCode
MemberType : Method
Definition : System.Int32 GetHashCode()


TypeName   : VMware.Vim.ManagedObjectReference
Name       : GetType
MemberType : Method
Definition : System.Type GetType()


TypeName   : VMware.Vim.ManagedObjectReference
Name       : get_Type
MemberType : Method
Definition : System.String get_Type()


TypeName   : VMware.Vim.ManagedObjectReference
Name       : get_Value
MemberType : Method
Definition : System.String get_Value()


TypeName   : VMware.Vim.ManagedObjectReference
Name       : set_Type
MemberType : Method
Definition : System.Void set_Type(String value)


TypeName   : VMware.Vim.ManagedObjectReference
Name       : set_Value
MemberType : Method
Definition : System.Void set_Value(String value)


TypeName   : VMware.Vim.ManagedObjectReference
Name       : ToString
MemberType : Method
Definition : System.String ToString()


TypeName   : VMware.Vim.ManagedObjectReference
Name       : Type
MemberType : Property
Definition : System.String Type {get;set;}


TypeName   : VMware.Vim.ManagedObjectReference
Name       : Value
MemberType : Property
Definition : System.String Value {get;set;}

$MySI = (Get-View ServiceInstance);
(Get-View $MySI.Content.UserDirectory) | Get-Member
TypeName   : VMware.Vim.UserDirectory
Name       : Equals
MemberType : Method
Definition : System.Boolean Equals(Object obj)


TypeName   : VMware.Vim.UserDirectory
Name       : GetHashCode
MemberType : Method
Definition : System.Int32 GetHashCode()


TypeName   : VMware.Vim.UserDirectory
Name       : GetType
MemberType : Method
Definition : System.Type GetType()


TypeName   : VMware.Vim.UserDirectory
Name       : get_Client
MemberType : Method
Definition : VMware.Vim.VimClient get_Client()


TypeName   : VMware.Vim.UserDirectory
Name       : get_DomainList
MemberType : Method
Definition : System.String[] get_DomainList()


TypeName   : VMware.Vim.UserDirectory
Name       : get_MoRef
MemberType : Method
Definition : VMware.Vim.ManagedObjectReference get_MoRef()


TypeName   : VMware.Vim.UserDirectory
Name       : RetrieveUserGroups
MemberType : Method
Definition : VMware.Vim.UserSearchResult[] RetrieveUserGroups(String domain, String 
             searchStr, String belongsToGroup, String belongsToUser, Boolean exactMa
             tch, Boolean findUsers, Boolean findGroups)


TypeName   : VMware.Vim.UserDirectory
Name       : SetViewData
MemberType : Method
Definition : System.Void SetViewData(ObjectContent objectContent, String[] propertie
             s)


TypeName   : VMware.Vim.UserDirectory
Name       : ToString
MemberType : Method
Definition : System.String ToString()


TypeName   : VMware.Vim.UserDirectory
Name       : UpdateViewData
MemberType : Method
Definition : System.Void UpdateViewData(String[] properties), System.Void UpdateView
             Data()


TypeName   : VMware.Vim.UserDirectory
Name       : WaitForTask
MemberType : Method
Definition : System.Object WaitForTask(ManagedObjectReference taskReference)


TypeName   : VMware.Vim.UserDirectory
Name       : Client
MemberType : Property
Definition : VMware.Vim.VimClient Client {get;}


TypeName   : VMware.Vim.UserDirectory
Name       : DomainList
MemberType : Property
Definition : System.String[] DomainList {get;}


TypeName   : VMware.Vim.UserDirectory
Name       : MoRef
MemberType : Property
Definition : VMware.Vim.ManagedObjectReference MoRef {get;}

Reply
0 Kudos
fixitchris
Hot Shot
Hot Shot
Jump to solution

Trying to use reflector to dig deeper and for some items it asks for VimService20 and VimService25. Are those DLLs available?

Reply
0 Kudos