Run the script inside the virtual machine the user when the user connects or reconnects

Hello

is it possible to detect the user that the user has connected or reconnected to his office inside the virtual machine and run a script?

It is also possible within the VM user to determine if the user is connected and how long?

One way to do this is via the following powershell command, but this only works if the user is connected through PCoIP Protocol.

Get-WmiObject-class Win32_PerfRawData_TeradiciPerf_PCoIPSessionGeneralStatistics - SessionDurationSeconds property

Best regards

> it is possible to detect the user that the user has connected either reconnected to his office inside the virtual machine and run a script?

You can run scripts as user on login and reconnect, this has been a feature since 3.0. See running commands on the desktop view.

> It is possible inside the VM user to determine if the user is connected and how long?

I don't think that we expose, but you should be able to query Windows for the connection time, or you could write the last time to connect with a script (maybe that is the reason for your first question?).

Mike

Tags: VMware

Similar Questions

  • Problem with script to clone virtual machines

    Hello

    I created a script to clone virtual machines on a regular basis around a method posted by LucD and Simon Long here or on their blogs.

    Here is the part that does the actual work:

    $VM = get - VM $Machine.MasterVM
    # Send Email of departure
    .\startmail.ps1
    # Create new snapshot clone
    $CloneSnap = $VM | New-Snapshot - name "Instant Test" - Quiesce
    # Get the managed object display
    $VmView = $VM | Get-View
    # Get the managed folder object reference
    $CloneFolder = $VmView.parent
    # Construction specification clone
    $CloneSpec = new-object Vmware.Vim.VirtualMachineCloneSpec
    $CloneSpec.Snapshot = $VmView.Snapshot.CurrentSnapshot
    # Make the linked disc specification
    $CloneSpec.Location = new-object Vmware.Vim.VirtualMachineRelocateSpec
    $CloneSpec.Location.Datastore = (get-Datastore-name $Machine.BackupDS). Extensiondata.MoRef
    $CloneSpec.Location.Host = (get-vmhost-name $Machine.BackupHost). Extensiondata.MoRef
    $CloneSpec.Location.Transform = [Vmware.Vim.VirtualMachineRelocateTransformation]: sparse
    $CloneName = "$vm - BU - $date"
    # Create clone
    $vmView.CloneVM ($cloneFolder, $cloneName, $cloneSpec)
    # Write newly created VM to stdout as confirmation
    Get - VM $CloneName
    # Remove snapshot created for clone
    $Snap = get-Snapshot - VM (VM-Get-name $Machine.MasterVM)-name $CloneSnap | Remove-Snapshot - confirm: $False
    #Send full email
    .\endmail.ps1

    I want to use in an environment composed of 3 servers ESXi 4.0 with a local data store each. This works well in my test environment, but not in that productive.

    Here, I get this error:

    Exception, calling 'CloneVM' with '3' or the arguments: "it was not correct to specified parameters.
    Spec.Location.pool ".
    C:\script\vm-backup\backup.ps1:98 char: 18
    + $vmView.CloneVM < < < < ($cloneFolder, $cloneName, $cloneSpec)
    + CategoryInfo: NotSpecified: (:)) [], MethodInvocationException)
    + FullyQualifiedErrorId: DotNetMethodException

    In a comment on his blog, made Simon refers to an error in the data store, but it seems very well here.

    By comparing the values of the characteristics to those of my testbed everything looks good, too.

    Does anyone of you can tell me where to look for the problem?

    Thanks in advance

    Christian

    That's correct, 1 by Server default resource pool.

    You can do

    Get-ResourcePool-name resources-site (Get - VMHost - name MyEsx)

    to get the default pool for a specific ESX Server

    CAB, you add a line in your original script

    $CloneSpec.Location.Pool = (get-ResourcePool-name resources-site (Get - VMHost - name MyEsx)). Extensiondata.MoRef

    This should be the correct MoRef

    The message seems to indicate that the target VM already partially exist.

    Remove it before you run your script once again.

  • Is no vmdk file, but the script says, all virtual machines backed up Ok!

    Hello everyone;

    Please excuse any lack of details because this is the first time that I write. I've scoured internet for days now trying to find no matter how much detail that could help me solve the problem. I'm new in the world of script ESXi and ghettoVCB.

    My intention is to run several tasks on a schedule. Each type of backup (quarterly, monthly, weekly, daily and multiple) runs at a specific time. The planning section works very well.

    I'm hoping to solve this urgent backup, I should be able to solve reboot.

    Here is the command I use:

    /vmfs/volumes/datastore1/ghettoVCB.sh w /tmp/ghettoVCB-work.multiple f/vmfs/volumes/datastore1/vmlist-Multiple g/vmfs/volumes/datastore1/vmconfig-DataSet1-multiple-l /vmfs/volumes/datastore1/ghettoVCB_logs/ghettoVCB.Multiple_Backup.log

    vmconfig-DataSet1-multiple contains:

    # Multiple backups - rotation County 6

    #

    VM_BACKUP_VOLUME = / vmfs/volumes/Vault2-DataSet1/URANUS/Multiple

    DISK_BACKUP_FORMAT = thin

    VM_BACKUP_ROTATION_COUNT = 6

    POWER_VM_DOWN_BEFORE_BACKUP = 0

    ENABLE_HARD_POWER_OFF = 0

    ITER_TO_WAIT_SHUTDOWN = 4

    POWER_DOWN_TIMEOUT = 5

    SNAPSHOT_TIMEOUT = 15

    ENABLE_COMPRESSION = 0

    VM_SNAPSHOT_MEMORY = 0

    VM_SNAPSHOT_QUIESCE = 0

    VMDK_FILES_TO_BACKUP =

    Vmlist-multiple contains 1 server is listed:

    # List all virtual machines that are backed up several times a day

    HEAT

    The log indicates that the backup was successful - but it has not been the case. Backup size should be approximately 8 GB. However, when you look at the output folder, only the following files are here:


    HEAT.vmx

    STATUS.ok

    Question is now - where are the vmdk files that should be present?

    Output (-d debug) can be found here: http://pastebin.com/hMGphTL3

    So, here is what I observed:

    When you run the script, the snapshot only takes a few seconds to create and delete then. I'm seeing happens on the list of the tasks of vSphere Rencent (screenshot attached).

    If I create a snapshot manually - it will take much more time to create and delete a snapshot. The difference here is 6 minutes, and 4 seconds using the script create a snapshot manually.

    So my presumption is that he is not actually create the snapshot, although vSphere said it is being created. So why is it the case?

    Help, please.

    ADDENDUM:

    If I run the following:

    ./ghettoVCB.sh m HEAT

    The backup is successful.

    Your said he clearly did not config file to back up all files hard.

    VMDK_FILES_TO_BACKUP =

    I expect to see something like this if you want all the hard files

    VMDK_FILES_TO_BACKUP = "all".

  • Modify the script for multiple virtual machines

    I'm working on the powercli user to change the CPU and the memory of several virtual machines.

    I found the perfect scenario created: http://ict-freak.nl/2010/05/07/powercli-script-to-schedule-memory-and-or-vcpu-updowngrade/comment-page-1/#comment-20336

    But it's only for 1 VM.

    Can someone tell me to change so do several virtual machines.  A text file would be ideal, but I'm ready for anything as this point, nothing I try does not work.

    Thank you.

    You could do

    foreach ($vm in Get-VM-name (Get-Content:\Powercli_scripts\servers.txt))

    I don't know why it's poweroffs randomly.

    You can add the - WhatIf parameter on this line, like that it will only say what he does, without actually running the cmdlet.

  • PowerCLI Script to migrate virtual machines with the same network Source for the new vCenter Server.

    Hi all

    I checked a few posts on the migration to the new vCenter Server virtual machine. But I'm not very good with Powercli and need some help here.

    We have a new vCenter server where we migrate virtual machines from one source vCenter server. Here are two things that I don't know how to connect together to make sure that bwfore we turn on the virtual machine to the virtual machine is connected to its source network.

    Part 1 - this script works well but do not get any network on the vCenter destination.

    cluster = Get-Cluster "clusterA.

    $inventory = get-Cluster $cluster | Get - VM | Add-Member - MemberType ScriptProperty-name "VMXPath" - value {$this.extensiondata.config.files.vmpathname}-Passthru-Force | Select-Object Name ResourcePool, folder, VMXPath |

    $inventory | Export-Csv c:\file.csv

    $inventory = import-csv c:\file.csv

    $cluster = get-group 'b '.

    {foreach ($vm to $inventory)

    $ESXHost = get-Cluster $cluster | Get-VMHost | Select - 1 first

    New-VM - VMFilePath $vm. VMXPath - VMHost $ESXHost - location $vm. Folder - ResourcePool (Get-Cluster $cluster |) Get-ResourcePool $vm. ResourcePool)

    }

    Part 2 - I want to preserve the Portgroup macaddress and the Ip of the virtual computers and connect them to the new vCenter. How can I do this with the script below. Or how can I combine them together?

    $vm_list = get-Cluster-name "clustera | Get - VM test * | Name sort

    $information = {foreach ($vm to $vm_list)

    $network_adapter_information = get-NetworkAdapter - VM $vm

    $vm | Select Name,PowerState,ResourcePool,@{N="Path; E=       {$_. ExtensionData.Summary.Config.VmPathName}},@{N="NetworkAdapter '; E = {[string]: join (":", ($network_adapter_information |))} %{$_. {{(Nom + "," + _.NetworkName $}))}}, @{N = "MacAddress"; E = {[string]: join (",", ($network_adapter_information | % {$_.}))} MacAddress}))}}

    }

    Step 2

    # Unsubscribe virtual machines

    Remove-VM - VM $vm_list-RunAsync Verbose - confirm: $false

    Step 3

    $cluster = get-group 'b '.

    {foreach ($vm to $inventory)

    $ESXHost = get-Cluster $cluster | Get-VMHost | Select - 1 first

    New-VM - VMFilePath $vm. VMXPath - VMHost $ESXHost - location $vm. Folder - ResourcePool (Get-Cluster $cluster |) Get-ResourcePool $vm. ResourcePool)

    }

    # Save virtual machines

    foreach ($info in $information)

    {

    $vmxpath = $info. Path

    $resource_pool = $info. ResourcePool.Name

    New-VM - ResourcePool (ResourcePool-Get-name $resource_pool) VMFilePath - $vmxpath - RunAsync-Verbose | Out-Null

    }

    Step 4

    # Put the network cards

    foreach ($info in $inventory)

    {

    foreach ($network_information in ($info.NetworkAdapter - split ":"))))

    {

    $virtual_machine = $info | %{$_. Name}

    $network_adapter = ($network_information-split ",") [0]

    $network_vlan = ($network_information-split ",") [1]

    Get-VM-name $virtual_machine | Get-NetworkAdapter-name $network_adapter | Together-NetworkAdapter - NetworkName $network_vlan-Verbose-RunAsync-confirm: $false | Out-Null

    }

    }

    # Start the virtual machines

    foreach ($vm to $vm_list)

    {

    Start-VM - VM $vm. Name-RunAsync Verbose - confirm: $false | Out-Null}

    }

    Thanks in advance for any help.

    Hi all

    I made some changes to the script and it worked for me. We have added a host on the destination with all exchanges and storage mapped vCenter.

    $vm_list = get-Cluster-name 'Site B - b | Get - VM | Name sort

    $information = {foreach ($vm to $vm_list)

    $network_adapter_information = get-NetworkAdapter - VM $vm

    $vm | Select Name,PowerState,ResourcePool,@{N="Path; E=       {$_. ExtensionData.Summary.Config.VmPathName}},@{N="NetworkAdapter '; E = {[string]: join (":", ($network_adapter_information |))} %{$_. {{(Nom + "," + _.NetworkName $}))}}, @{N = "MacAddress"; E = {[string]: join (",", ($network_adapter_information | % {$_.}))} MacAddress}))}}

    }

    # Unsubscribe virtual machines

    Remove-VM - VM $vm_list-Verbose - confirm: $false

    $cluster = get-Cluster "Site A - clustera.

    {foreach ($vm to $information)

    $ESXHost = get-Cluster $cluster | Get-VMHost | Select - 1 first

    New-VM - VMFilePath $vm.path - VMHost $ESXHost - location $vm. Folder - ResourcePool (Get-Cluster $cluster |) Get-ResourcePool $vm. ResourcePool)

    }

    # Save virtual machines

    foreach ($info in $information)

    {

    $vmxpath = $info. Path

    $resource_pool = $info. ResourcePool

    New-VM - ResourcePool (ResourcePool-Get-name "test1") VMFilePath - $vmxpath - RunAsync-Verbose | Out-Null

    }

    # Put the network cards

    .

    foreach ($info in $information)

    {

    foreach ($network_information in ($info.NetworkAdapter - split ":"))))

    {

    $virtual_machine = $info | %{$_. Name}

    $network_adapter = ($network_information-split ",") [0]

    $network_vlan = ($network_information-split ",") [1]

    Get-VM-name $virtual_machine | Get-NetworkAdapter-name $network_adapter | Together-NetworkAdapter - NetworkName $network_vlan-Verbose - confirm: $false | Out-Null

    }

    }

    # Start the virtual machines

    foreach ($vm to $vm_list)

    {

    Start-VM - VM $vm. Name-RunAsync Verbose - confirm: $false | Out-Null

    }

    Hope this will help many of you.

  • How to get the host name of the physical computer inside a virtual machine until the user logs in Windows?

    I don't know if this is the right place to post this question, I develop software to support VMWare PCoIP and need to know how to get the host name of the physical machine (which manages the virtual machine and View Client) within a virtual machine before the user logs in Windows of the virtual machine.

    I understand there are two ways to read the host name, via the HKEY_CURRENT_USER\Volatile Environment registry and environment variables, but they are available once the user is connected. I need info before the user connects.

    Is there a VMware API that can be called or asked the host name?

    Thank you.

    Not on the broker, but there are the startup scripts to log on to the computer virtual itself: http://pubs.vmware.com/view-52/topic/com.vmware.view.integration.doc/view_integration_startsession_script.9.2.html

    Note that these executed when a virtual desktop computer allocated connection, not to the point that the client connects - it is possible for the customer to not complete the connection (crash, cancel, network failure) and so any what solution you design must handle this.

    Mike

  • PowerCLI script to migrate virtual machines to the new vCenter environment

    Hello world

    in the next few weeks, we need about migrate 700 VMs (Windows/Linux) server to a new environment (new vCenter, new hosts, but VMs will remain on same data warehouses). VMs will be migrated not in one batch, but rather from time to time (which, however, can understand the need to migrate some 10s of virtual machines at the same time).

    Cluster names and folder structure will be identical to the old and the new vCenters. As host in the new vCenter names differ from those in the old vCenter, thought to provide a table of 'translation', which tells the script to save a given VM on host B (new vCenter) when having been registered in order to host a (old vCenter) and so on.

    I thought writing a PowerCLI script which, broadly speaking, can accomplish the following steps:

    • Connect to vCenterOld and vCenterNew
    • Correspondence table of host to read from a file (see step "register VM vCenterNew below)

    Then, in a loop:

    • Ask VM name
    • Get the settings of the virtual machine: Datastore/path, network/Portgroup, HA restart priority, host, folder, note
    • View the parameters and the VM name and request confirmation migrate the virtual machine
    • Turn off VM (closed OS gracefully, but force power off if power status is still not equal 'off' after a time given)
    • To unsubscribe from VM vCenterOld (removal of inventory)
    • Registry of the VM to the data store vCenterNew (assumptions: same folder as vCenterOld, host names are different, but for each source in vCenterOld host a host of destination in vCenterNew for you join the virtual machine to can be provided, that is, CSV)
    • The value of VM portgroup (same name as in vCenterOld)
    • Set VM HA restart priority
    • PowerON VM
    • Wait / check the VM (for example, ping) connectivity / continue immediately if the virtual machine is accessible or after a certain time if the virtual machine is still inaccessible
    • Confirm that the virtual machine has been migrated successfully, OR ask the user to check the connectivity of the virtual machine

    Now to my questions:

    • Is anyone know about an existing script that does something similar or contains parts that can be useful to compile a script like this?
    • How can vCenter two connections at the same time been managed within a PowerCLI script - or doesn't work at all and a connect/disconnect to/from the two vCenters must be completed for each virtual computer?

    Many thanks for any help.

    The following seems to work for me

    $vm = Get-VM -Name MyVM$nic = Get-NetworkAdapter -VM $vm $vdPG = $nic | select -ExpandProperty NetworkName
    
    Get-VDPortgroup -Name $vdPG
    
  • Script to create virtual machines fails when you try to add the disk to the cluster data store

    Hello

    Attached is the script that I used to create virtual machines and it works very well when virtual machines are created to warehouses of unique data, but do not have clustered data warehouses. I think that the reason is that it creates the virtual machine through the esx host (who does not know the cluter) and not via vCenter (who knows about it). Unfortunately I do not know how to fix.

    Thank you

    Astra

    Looks like he needs a store of data for this parameter object. So we need to do a get Datastore cluster I can try to test tomorrow, but try this:

    If ($datastore1 - only 'none') {}

    $drscluster = get-DatastoreCluster $datastore1

    $vmadddsk = new-disk-hard - VM $gstname CapacityKB - $datastore1size - data $drscluster store

    }

  • Error: Running VMware ESX in a virtual machine requires the external virtual machine

    We are running ESX Vmware 5 on a virtual test in ESX 4.x environment and machine unable to start the virtual machine on Vmware ESX 5. with the following error.

    Error: -.

    Running on a virtual machine VMware ESX requires the external virtual machine is configured to run a VMware ESX guest operating system. You can not power on a virtual machine until the external virtual machine is reconfigured.

    We found after KB

    http://KB.VMware.com/selfservice/microsites/search.do?language=en_US & cmd = displayKC & externalId = 1030283

    Howerver, I'm not able to find the option

    1. Select the virtual machine that is running ESX.
    2. Go in VM > Settings.
    3. Click the Options tab.
    4. Select the General settings.
    5. Under Guest operating system , select VMware ESX.
    6. Click OK.

    We are not able to find this option in ESX 4, so we can run this VM.

    Please help urgently...

    Kind regards

    The log file looks good now.  However, it seems that ESX 4.0 is older than I remembered.  Please, add the following line to your ESX VM configuration file and try again:

    monitor_control.restrict_backdoor = TRUE

  • Run Recovery Plan - turn off virtual machines to the protected Site?

    Hello

    Pretty silly question here...  I read that when you run the Recovery Plan SRM will equip all virtual machines protected on the protected site.  Is this the case?

    Thank you

    Dave

    Exactly.  In this case, workloads on the recovering site absolutely remains lit throughout the entire test or recovery.

  • How to set the vlan native on a virtual machine in vSphere when you use the 1000V?

    Using the General switch original vSphere, we put VLAN native by VM by setting the VLAN 0 d.

    How do we set VLAN native for a virtual machine, if the virtual computer is connected to a 1000V? I heard that is over, we can use VLAN ID 0?

    Same way as you would on any Cisco switch.

    Add this command to your profile of uplink port:

    switchport trunk vlan native X

    Keep in mind there is no VLAN 0.  VLAN '0' is just how vmware means the VLAN untagged.  There are valid in accordance with the standard 1-4095.

    Kind regards

    Robert

  • XEN running inside a virtual machine under ESX (i) 3.5?

    Hello world

    I'm still pretty new mV, so please bear with me if I ask is stupid. I have already searched the web, but I couldn't really find an answer to this:

    Let's say we have a VM-certified (for example from Dell) server running ESX 3.5 or ESXi 3.5. I understand that the following would be a typical scenario:

    -ESX 3.5

    -VM 1: Windows Server 2008

    -VM 2: Windows Server 2003

    -VM 3: Debian 4.0 (unofficially supported?)

    -Virtual MACHINE 4: Redhat Enterprise Linux 4

    Could I now install XEN in Debian of VMS 3 making 3 Xen's Dom0 of VM?

    So what I want is this:

    -ESX 3.5

    -VM 1: Windows Server 2008

    -VM 2: Windows Server 2003

    -VM 3: Debian 4.0 with XEN (= Dom0)

    -DomU 1: Debian 4.0

    -DomU 2: Debian 4.0

    -DomU 3: Debian 5.0

    -DomU 4: Debian 3.1

    -DomU 5: supported an another Linux system by XEN

    -Virtual MACHINE 4: Redhat Enterprise Linux 4

    Is this possible? If so, that requires any special parameters on the side of the virtual computer, Debian or Xen?

    Or, and this is what I hope, is the ESX service an fully transparent layer between whats running in the virtual machine (for example. Debian with XEN) and the actual hardware.

    In other words: is the installation of Debian in VM3 "knows" that he is not actually run directly on the hardware?

    Thank you very much in advance for any answers or advice in the right direction!

    Tom

    Depends on the mode of Xen.  If Xen tries to use the VT / SVM instructions, it will not work because these instructions are not virtualized.  If Xen is running a guest paravirtualise it could work - anyone I know has ever attempted.  (So, "no".)  If this does not work, we would like to hear about it.

    Re: Why Debian is not a client supported... it's a problem of bandwidth QA, invited taken in charge to be tested carefully so the number of guests that can be supported is limited.  Debian runs almost certainly - it is very similar to Ubuntu, which is supported - but VMware not QA, if we do not pretend that support.

  • VirtualBox 64-bit inside a virtual machine

    I need to configure a machine virtual 64 bit Windows 8.1 on my VMWare environment.  Inside, I need to run a virtual 64-bit with VirtualBox machine.  I installed Windows on the virtual machine and install VirtualBox, however, I can't show him 64-bit... Only 32-bit.  I added vhv.enable = "TRUE" in the VMX file (seen this somewhere) and assured of Hyper-V has not been installed on the machine Windows 8.1.  Any other suggestions as to what I'm missing?

    ESXi 6.0.0 3620759

    did you select the check box for "expose assisted hardware virtualization for the guest OS" under settings of the virtual computer processor?

    You can see this option using the new built-in host client or web client.

    Thank you

    Hentzien

    Virtual Admin

  • How to add a script to a virtual machine using vmwrae api?

    Hello

    I am trying to add a new disk to an existing VM (Linux).

    To do this.


    Now to use the new drive on a run a series of commands, like:

    -format the drive

    -mount the drive

    -put this information to disk in the file/etc/fstab


    My question is how we can automate this task without actually going inside the virtual machine?

    This is precisely what my advice is intended to accomplish. There are many examples available online to use Invoke-VMScript to automate actions in a Linux VM.

    http://www.Google.com/search?q=invoke-vmscript+examples

    This was done from my Windows using PowerCLI workstation to a virtual machine running SLES:

    PowerCLI C:\> Invoke-VMScript -vm $vm -HostCredential $hc -GuestCredential $gc -ScriptText "uptime"
    
    ScriptOutput
    ---------------------------------------------------------------------------------------------------
     08:32:52 up 88 days,  7:27,  0 users,  load average: 0.00, 0.00, 0.00
    |
    ---------------------------------------------------------------------------------------------------
    
  • Inside a virtual machine VMware

    Hello

    I would like to know if it is possible to install VMware Workstation 7.1 within a virtual machine (for example Microsoft Windows Server 2008 R2)

    Anyone have it?

    Thank you.

    inside a HyperV virtual machine?

    It work but performance will be...

    performance of the wells is the wrong term to crawl... ;-)

    _________________________

    VMX-settings- WS FAQ -[MOAcd | http://sanbarrow.com/moa241.html]- VMDK-manual

Maybe you are looking for