Complete the VI Client with PowerCLI Script idle Sessions

Hello gurus PowerCLI

I searched the net for a script PowerCLI that would end all the VI client sessions that have been inactive for x period of time.  I found a post on the forums of VMware (http://communities.vmware.com/message/914858?z=zI0r8n) but had no luck with it.  I also found a script created by A.Mikkelsen, to http://www.amikkelsen.com/?p=384 , but that one does not work either.

Here's the actual script by A.Mikkelsen that is based on code by LucD in the forum mentioned previously.

BEGINNING

##################################################################################
# The script terminates all sessions if idle idle user for more than xx #.
#                             #
# Created by: Anders Mikkelsen, 2010 #.
##################################################################################
Claire
# Add - PSSnapin VMware.VimAutomation.Core

# $server = "vcenter server.
# $user = "vcenter username.
# $pwd = "password of vcenter.

# Add 1 extra hour when, due to the difference of timestamp between MSSQL and Windows.
# slow down time 5 hours = 360
# 10 hours slowed = 660
$intOlderThan = 60

# Connect-VIServer $server - user $user-password $pwd
# Connect-VIServer $server

$svcRef = new-object VMware.Vim.ManagedObjectReference
$svcRef.Type = 'ServiceInstance.
$svcRef.Value = 'ServiceInstance.
$serviceInstance = get-views $svcRef

$sessMgr = get-view $serviceInstance.Content.sessionManager
$oldSessions = @)
{foreach ($sess in $sessMgr.SessionList)}
If (($sess.)) (LastActiveTime) .addminutes ($intOlderThan) - lt (Get-Date)) {}
$oldSessions += $sess. Key
#write "$($sess.)". User name)'
}
}

# Session terminal that are inactive for more than approved ($intOlderThan)
$sessMgr.TerminateSession ($oldSessions)

Disconnect-VIServer *-confirm: $false

END

The error message I get is:

BEGINNING

Exception calling 'TerminateSession' with '1' or the arguments: "it was not correct to specified parameters.

"

D:\Scripts\vc_terminate_idle_sessions.ps1:36 char: 26

+ $sessMgr.TerminateSession < < < < ($oldSessions)

+ CategoryInfo: NotSpecified: (:)) [], MethodInvocationException)

+ FullyQualifiedErrorId: DotNetMethodException

END

I should mention that my knowledge of PowerCLI is almost nothing, so any help in tweaking this script to make it work with PowerCLI 5.1 Release 2 and VC 5 U2 would be much appreciated.

The error is caused by the fact that you are trying to kill your own session (if it was started long time ago).

Apparently in vSphere 5. they included a security mechanism integrated to avoid this.

You can take this by adding a simple test.

## max number of idle minutes for sessions to keep$intOlderThan = 60$serviceInstance = Get-View 'ServiceInstance'## get the session manager object$sessMgr = Get-View $serviceInstance.Content.sessionManager## array to hold info about stale sessions$oldSessions = @()foreach ($sess in $sessMgr.SessionList){    if (($sess.LastActiveTime).addminutes($intOlderThan) -lt (Get-Date) -and          $sess.Key -ne $sessMgr.CurrentSession.Key){        $oldSessions += $sess.Key    } ## end if} ## end foreach

## if there are any old sessions, terminate them; else, just write message to the Warning streamif (($oldSessions | Measure-Object).Count -gt 0) {    ## Terminate sessions than are idle for longer than approved ($intOlderThan)    $sessMgr.TerminateSession($oldSessions)} ## end ifelse {Write-Warning "No sessions that have been idle for more than '$intOlderThan' minutes; no action taken"}

Tags: VMware

Similar Questions

  • The dynamic firewall application on the VPN Clients with ASA

    Hello

    I'll put up a Cisco ASA to complete the remote VPN client connections, but I want to assure you that the dynamic firewall is enabled on the client.

    I know it's possible with the VPN concentrator, but cannot see any documentation detailing that can be performed on an ASA.

    Anyone encountered this?

    Thank you

    James

    I believe you can use Group Policy settings to configure the firewall client.

    You can find more information about this feature in the migration to http://www.cisco.com/en/US/docs/security/asa/asa72/vpn3000_upgrade/upgrade/guide/migrate.htmlguide.

    Hope this helps.

    Andrea.

    Step 1 under Configuration > VPN > General > Group Policy Panel, select group policy in the table and

    Click on change. ASDM displays the Edit Group Policy dialog box.

    Step 2: click on the customer Firewall tab Figure 5-6 shows the firewall client options configured for this example:

    • Inherit-disabled (disabled)

    • The required Firewall Firewall setting

    • Type firewall Cisco Integrated Client Firewall

    Firewall policy-policy (CPP) pushed •

  • How to remove the selected area with a script that would ignore the fact if the selected area is transparent or the fact that it has no selection?

    Hello

    My friend works on an action, who would edit images by removing the white background color. However, there are a lot of images with transparent background or after some other actions have no selection who had to be removed. And now he is facing simple problem, simple remove this feature brings a lot of table and the error Stops.

    The ideal solution to this problem would be if it would ba a script who could remove the selection and ignore stops as no selection and transparent.

    Can anyone help with this one?

    Settle into the Photoshop scripts forum.

    With a script, you would just put your code in a try/catch block. This intercept errors such as the selection of a transparent area and do not stop your script:

    try{
         //your code here
         }
    catch(e){
         //either no code, or code to do something if you get an error.
    }
    
  • The requested operation is not implemented by the server when you try to access the VI Client with ESX hosts

    Hello

    We have problems with the VirtualCenter (which someone else works).  I need to access some of the virtual machines and tried to connect through the VI client to all ESX hosts.  I get this error after I give him password, username, and hostname:

    The requested operation is not implemented by the server.

    I'm sure I got this race last year.

    A reflection as to why it does not work?

    Thank you!

    Hello.

    How you launch the client?  Is it a shortcut with possibly a few settings in there?  If so, try running it without parameters.

    Good luck!

  • Problems with PowerCLI script variables

    Hello

    I hope that someone in the community can tell me where I was wrong in the script below. I have a few other PowerCLI scripts that work in a way similar to this work and these, but this one has a problem. The script is intended to collect information on a number of ESX objects in an array of arrays, $reportfinal, which can then be written to a CSV file that will have the column names for the objects, and each line will yield the values for RDM related objects for each virtual computer. The problem is that, rather than add the results to the table of $reportfinal, the results are crushed, and worse still, the values repeat themselves (for example the size of the various disks is reported as the same value).

    $report = @)

    $reportfinal = @)

    $VMs = get-VMHost | Get - VM | Get-View

    $rowcoll = "" | Select the virtual machine, VMController, SCSIBusShare, SCSIBusNumber, SCSIUnitNo, DeviceLabel, SCSISummary, DeviceFilename, DeviceCapKB, DeviceDiskMode, DeviceDiskUUID

    {ForEach ($VM to $VMs)

    #Clear table report for each virtual computer

    $report = @)

    Foreach ($SCSI_Controller in ($VM. Config.Hardware.Device | where {$_.} (({DeviceInfo.Label - like "SCSI *"})) {}

    $rowcoll. VM = $VM. Name

    $rowcoll. VMController = $SCSI_Controller.DeviceInfo.Label

    {Foreach ($Disk_Key to $SCSI_Controller.Device)}

    Foreach ($Disk_Device in ($VM. Config.Hardware.Device | where {$_.key - eq $Disk_Key})) {}

    $rowcoll. SCSIBusShare = $SCSI_Controller.SharedBus

    $rowcoll. SCSIBusNumber = $SCSI_Controller.BusNumber

    $rowcoll. SCSIUnitNo = $Disk_Device.UnitNumber

    $rowcoll. DeviceLabel = $Disk_Device.DeviceInfo.Label

    $rowcoll. SCSISummary = $SCSI_Controller.DeviceInfo.Summary

    $rowcoll. DeviceFilename = $Disk_Device.Backing.Filename

    $rowcoll. DeviceCapKB = $Disk_Device.CapacityInKB

    $rowcoll. DeviceDiskMode = $Disk_Device.Backing.DiskMode

    $rowcoll. DeviceDiskUUID = $Disk_Device.Backing.UUID

    }

    }

    }

    #Append the next line of the report data collection

    $report += $rowcoll

    #Append the next report to the final report data collection

    $reportfinal += $report

    }

    $reportfinal | Export-Csv-path D:\temp\SAP_Report_Disks_RDM_Mappings.csv - NoTypeInformation

    Note: Some parts of the script came another announcement on this forum about a script to display the ROW information for the list of virtual machines.

    See you soon,.

    Ed

    My mistake, I deleted the line wrong $report.

    Try this one

    $reportfinal = @()
    
    $VMs = Get-View -ViewType VirtualMachine
    
    foreach ($VM in $VMs) {
    
         #Clear report array for each VM
    
         foreach ($SCSI_Controller in ($VM.Config.Hardware.Device | where {$_.DeviceInfo.Label -like "SCSI*" } )) {
    
              foreach ($Disk_Key in $SCSI_Controller.Device) {
                   foreach ($Disk_Device in ($VM.Config.Hardware.Device | where {$_.key -eq $Disk_Key } )) {
                        $rowcoll = "" | select VM, VMController, SCSIBusShare, SCSIBusNumber, SCSIUnitNo, DeviceLabel, SCSISummary, DeviceFilename, DeviceCapKB, DeviceDiskMode,DeviceDiskUUID
                      $rowcoll.VM = $VM.Name
                      $rowcoll.VMController = $SCSI_Controller.DeviceInfo.Label
                        $rowcoll.SCSIBusShare = $SCSI_Controller.SharedBus
                        $rowcoll.SCSIBusNumber = $SCSI_Controller.BusNumber
                        $rowcoll.SCSIUnitNo = $Disk_Device.UnitNumber
                        $rowcoll.DeviceLabel = $Disk_Device.DeviceInfo.Label
                        $rowcoll.SCSISummary = $SCSI_Controller.DeviceInfo.Summary
                        $rowcoll.DeviceFilename = $Disk_Device.Backing.Filename
                        $rowcoll.DeviceCapKB = $Disk_Device.CapacityInKB
                        $rowcoll.DeviceDiskMode = $Disk_Device.Backing.DiskMode
                        $rowcoll.DeviceDiskUUID = $Disk_Device.Backing.UUID
                        $reportfinal += $rowcoll
                   }
              }
         }
    
    }
    
    $reportfinal | Export-Csv -path C:\SAP_Report_Disks_RDM_Mappings.csv -NoTypeInformation
    
  • the problems associated with writing script

    Hi all

    I use DIAdem 10.2

    (1) I write the Script for the declaration of my scada system. In my report model, there are some common text as user field, period reoprt, designation, report, etc. etc... I designed the dialog box to ask these details in starting, and now I wanted to transfer these details on each page of the report. Is it possible to connect these details with the report model?

    (2) I am facing problem in the allocation of train paths within the script... Is it possible to get rid of problems that arise due to movement of files from file *.sud or *.tdr. It will be great if diadem automatiocally search inside the folder in which the script is saved... so whenever we are going to move the complete file of any statement. It won't create any problem condition save us all files in a folder.

    (3) I crushed my script different system or sometimes need to distribute it. Is it possible to make my script running on another system where tiara is not installed... sort of it, even making available using any platform of programming such as LabVIEW, Measurement studio, CVI etc. etc.

    Thank you very much!

    HS

    HS Hello!

    (1) you can use global variables to solve this task. There are some predefined as "T1" or - I prefer - assign them in the Script with the command GlobalDim and fill them in your data. In the report, you can use the expression '@T1 @' or ' @@MyGlobalDimVar @ ' in the text fields to display the content.

    (2) you can use the AutoActPath variable to all access to the files compared to the running script. If you put all your files next to the script, you can move the package wherever you want in the file system. In all commands of loading like PicFileLoad you must use AutoActPath.

    (3) you can run Scripts DIAdem and dialogs only in DIAdem.

    Matthias

  • How to perform a task planned with PowerCli Script?

    I have a script which is of cousre ps1 but I don' t know how do work cause the powercli vShpere is not a powerhsell exe is just the environment variables.

    Please help me how to operate

    Have you ever seen my blog post?

    http://www.virtu-al.NET/2009/07/10/running-a-PowerCLI-scheduled-task/

    If you found this information useful, please consider the allocation of points for correct or helpful.

    Alan Renouf

    http://Virtu-al.NET

  • Change the source file of the insert text with a script

    I'm looking for a way to replace existing-insert text in a document with the contents of another file (by reference), using scripts. I have a document c:\referer.fm, in which there is an insert text which the source file is: c:\A.fm

    I also have c:\B.fm, and now I want to change referer.fm so that is no longer the overlay of text contains the text of A.fm, but the B.fm.

    I tried this:

    var doc is app. ActiveDoc;

    var textinset is doc. FirstTiInDoc;

    var pathtosource is textinset. TiFile;

    pathtosource = "c:\B.fm";

    textinset. UpdateTextInset();

    But it does not work. I guess that the "pathtosource" parameter can be done this way. If someone knows a way to do it, I would greatly appreciate your help!

    David

    Hello David,.

    You do not manipulate the text overlay, but a copy of the file in the text box. Your "pathtosource" parameter is a local copy of the property that you read from the actual text insert.

    Try this code instead:

    var doc is app. ActiveDoc;

    var textinset is doc. FirstTiInDoc;

    textinset. TiFile "c:\\B.fm".

    Note that the backslash must be escaped with the backslash to make it work in a JavaScript string. To make your script Fail-Safe, test the name of file textinset before changing. You do not have the textinset that you expect to have, as might also be INSET text on master pages and reference. All inserts text are in a single linked list.

    Also, update the text tagging along after that changing the path may not always work, as compared to FM, last changed the file date text inset with the last time that the textinset has been updated. To force the FM to update the textinset, you must include the following line of code after changing the filename text inset:

    textinset. LastUpdate = 0;

    Then, you can call the UpdateTextInset() method and it will work.

    Good luck.

    Jang

  • The VMware Client with VDR plugin installed error

    Error in Client.JPG

    I initially just uninstalled the client and reinstalled, does not resolve the issue.

    Then I uninstalled client and all the plugins and started to install one by one until I found the vdr plugin is causing this problem. To confirm that I uninstalled vdr plugin... no error... reinstalled vdr plugin... error.

    Versions:

    VDR 2.0

    vCenter Server 4.1

    Client VMware 4.1

    Anyone seen this before? I couldn't really find much research...

    I've heard of support: this is a known bug and a patch is being developed.  There is currently no work around for this problem (other than uninstalling the plug).

    See you soon,.

    Sean

  • Run the plug-in with a script?

    Does anyone know if it is possible to run a plug-in by using a script? For example, if I click on a button in the user interface, the script will run a plug-in?

    Quentin

    Please clarify then. Are you talking to a menu command in the drop-down menus? If so, you can also use:

    app.executeCommand (app.findMenuCommandId ("the MENU COMMAND NAME"));

    This will run a menu command, but keep in mind that it is not always stable. Simply place the name of the menu item that is case-sensitive in double quotes.

  • What happens to the volume clients with plans to upgrade?

    We are a TLP customer nonprofit with a few dozen licenses for the Creative Suite, InDesign autonomous, things like that. When we buy new licenses, we always buy plan upgrade. And keep us abreast of upgrade plans - management like the fact that we can predict costs for Adobe software two years to come.

    Related PDF says:

    Make your software more predictable budget

    Anticipate delays and updates of your software licenses current prices can be difficult, but Adobe updates budgeting doesn't have to be. By investing in Upgrade Plan, your organization can lock a price fixed for all licenses for future upgrade which are released during the term of your coverage period.* Upgrade Plan that takes the guesswork out of budgeting software and you buy software of tomorrow at today's prices. A percentage of the cost of the license, your organization gets access to the latest products of Adobe, which simplifies software management and stabilizing the budget forecasts. In addition, upgrade Plan costs can be paid in advance or by means of annual payments, allowing flexibility in the buying process.

    I could not find any information on what is happening to our upgrade plan. (And when I called Adobe CS, I was disconnected after only 70 minutes to hold. "And when I tried the CS chat, they told me to call). Something has been posted or said about the institutions with upgrade plan coverage?

    Joel, I have been informed that we will need to look at your specificities, to advise on the best option for you.  Contact our team of Volume Licensing at http://helpx.adobe.com/x-productkb/policy-pricing/avl-help.html.

  • Integrate the VI Client with NTLM or Kerberos

    When I connect to Virtual Center via VI Client I have to re - enter my domain credentials. Is there anyway that I can configure VI Client to use the credentials of the current users?

    TIA

    Mike

    Hi Mike,.

    You can use epass th by authentication for your CV, you simply Add - passthroughAuth-s vchostname at the end of the shortcut used to launch the VI 2.5 client.

    Example - "C:\Program Files\VMware\Infrastructure\Virtual Infrastructure Client\Launcher\VpxClient.exe" - passthroughAuth s virtualcenter.domain.com

    Kind regards

    Vijay

  • How to complete the data sorted with Model Driven Development

    Hello

    I use a model based development. I use count with all the Fill method. But the results are not be returned sorted by a field that interests me. How can I tell the filling to sort by a field. Is there an annotation that I provided in the model...

    Thank you

    RK

    You should be able to achieve what you want with a filter of explicit criteria on your entity.

    In the Design of Modeler view, select your entity and add a filter. You will see that there is an "Order By" field in the properties view.

    Enter the value that you want there, and then save and transfer your model. When you do not enter anything in the 'Criteria' field, you create a fill count with all.

    Here is an example of an entity created with this type of filter. they are sorted by price in ascending order:

     

  • RETCODE = 2 does not complete the concurrent program with the error.

    Hi all

    I have a custom Package and a procedure with a parameter that accepts the item number.

    Here is my Code:

    CREATE OR REPLACE PACKAGE BODY CUSTOM_TEST_PKG
    PROCEDURE MAIN (P_INVENTORY_NAME IN VARCHAR2, ERRBUFF OUT VARCHAR2, OUT VARCHAR2 RETCODE)
    IS
    V_ITEM_ID NUMBER;
    BEGIN
    FND_FILE. PUT_LINE (FND_FILE. EXIT 'before the subprogram");

    / * Start of subprogramme * /.
    BEGIN
    FND_FILE. PUT_LINE (FND_FILE. EXIT 'before the Select query");
    SELECT INVENTORY_ITEM_ID IN THE V_ITEM_ID MTL_SYSTEM_ITEMS_B WHERE SEGMENT1 = P_INVENTORY_NAME
    AND ORGANIZATION_ID = 204;
    FND_FILE. PUT_LINE (FND_FILE. EXIT "after the Select query");
    FND_FILE. PUT_LINE (FND_FILE. OUT,' the name of the element passed as parameter IN :'|| p_inventory_name);
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    RETCODE: = 2;
    ERRBUFF: = 'no items exist. "
    FND_FILE. PUT_LINE (FND_FILE. JOURNAL, ERRBUFF);
    END;
    / * End of subprogramme * /.

    FND_FILE. PUT_LINE (FND_FILE. EXIT "after the subprogram");

    END MAIN;
    END CUSTOM_TEST_PKG;
    /


    Could someone help me on this.

    errbuf and retcode must be parameters of 1st and 2nd respectively. 3rd onward are the order of simultaneous program settings. Change your code.

    Kind regards
    Gareth

  • Trying to set up the VPN Client with crossed on ASA5510

    Hello

    I'm putting in place our ASA5510 so that users can connect to our LAN to work and surf the Internet as well.

    I followed the guide from Cisco, I connect and I give myself a 192.168.10.x necessary address but I can't connect what on our network of 10.0.0.0/24 or surf the Internet work.

    Could someone please check my config and see what's wrong, there's also a vpn L2L here in a 192.168.3.0 network, but that works without problems

    Thank you very much

    Chris

    Hello Chris,

    Add after access list statement.

    INSIDE_nat0_outbound to access ip 10.0.0.0 scope list allow 255.255.255.0 192.168.10.0 255.255.255.0

    And for the aggregation of internet traffic add following command:

    permit same-security-traffic intra-interface

    Verify and validate the results.

    HTH

    Sangaré

    pls rate helpful messages

Maybe you are looking for

  • Persistent problems with the Magic Mouse

    I have persistent problems with my Magic Mouse. He often stops followed (i.e. the cursor on the screen does not move when I move the mouse), or the input button on malfunctions (i.e. I don't click and drag, or cannot right click, or when I click on s

  • What is now updated?

    does anyone know which did not appear in the update today?

  • What is the impact of the use of a variant on the performance data type, speed memory applications etc.?

    This is one of my sons "allows to get this settled once for all". I avoided data types variant when it is possible to track the performance of my apps. Some observatsions, I made over the years, I believe that; (1) operations in place cannot carry on

  • How to detect what causing my hard drive space increase?

    Hello My space on the hard disk increases daily 100 MB how to detect the causes of this increase in my hard drive. Thanks for your help

  • demand equations

    I change the operating system Windows 8 OS to remove mounting...           Pls... One tell what is the problem to install Window 7 OS "windows can not installed to the Selected Disk.The Disk is the GPT partition style" Pls any one help me how to clea