Quantcast
Channel: VMware Communities : All Content - VMware PowerCLI
Viewing all articles
Browse latest Browse all 16717

Duplicate Sessions Report

$
0
0

Disclaimer: Powershell novice - be gentle and speak slowly in short words.

 

We have a problem with duplicate sessions (don't ask - long story; not getting corrected for a while so this band-aid is being enacted instead and I can't change that).

 

One of my daily tasks is to compile a list of said duplicates to management.  So I login to each of our 3 pods, grab a session list csv, manually cut and paste them into a single Excel spreadsheet, find duplicates on the user name column, and then filter it, giving a list of duplicate users and all of the information (like duration, connection state, machine name, etc).  I'm not saying this isn't the most exciting way to spend 15 minutes of my day, but if I could automate it and learn some more Powershell in the process, that would be swell.

 

Currently, I'm just stuck on the list generation.

 

Previously, I created a little script that pulls all disconnected machines of a certain duration and does a restart-vm on them.  However, for that, I do the filtering in the ScriptBlock and just need the machine name:

$cred = Get-Credential

$vdipod1 = Invoke-Command -ComputerName SERVER_NAME -Credential $cred -ScriptBlock {Add-PSSnapin vmware.view.broker;(get-remotesession|Where-Object {($_.pool_id -match "POOL-NAME") -and ($_.state -notlike "CONNECTED") -and (($_.duration -match "day") -or ($_.duration -match "days"))}|select -ExpandProperty dnsname -Property dnsname).trimend("DOMAIN")|sort}

Pretty straightforward right?  Look for non-CONNECTED machines with duration name of "day" or "days", meaning it's older than 24 hours.  Then I just get the machine name, trim the domain name, and I have my list of VMs to feed into vSphere and restart-VM. 

 

And if you output vdipod, you get a list of machine names:

echo "**VDI Pod1 : $vdipod1" 

 

**VDI Pod1: VM01, VM03, VM07, ...

 

However, in this case, I need more than just the machine name for my reporting purposes.  I try to use the same code (removing the conditions as I need all machines, not just aged and disconnected ones) and just select * and I get nothing (same if I replace * and enumerate "username,dnsname,state,duration").

$cred = Get-Credential
$vdipod1 = Invoke-Command -ComputerName SERVER_NAME -Credential $cred -ScriptBlock {Add-PSSnapin vmware.view.broker;(get-remotesession|Where-Object {($_.pool_id -match "POOL-NAME")}|select *)}

It doesn't error - it just doesn't give me anything.  Though, if I toss the -ExpandProperty flag on there, it errors due to having more than one argument.

 

I know - I'm still a long way down the road.  In my mind, I need to make multiple lists, combine lists, find duplicates, and separate them out.  But I'd just like to get over this little hump and then start on the next part.

 

Thanks in advance for any help!

 

FYI: I expect that at some point, I'll probably be tasked with adding some basic logic to this and then kill off the extra sessions (i.e. kill disconnected sessions and then kill off the oldest duplicated sessions or just kill all; who knows).  But we'll cross that bridge once we get to it.


Viewing all articles
Browse latest Browse all 16717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>