I wan to return the session objects longer than 7 days but cant figure out the format of the duration parameter.
Get-RemoteSession -Duration ?
help says:
-Duration [<string>]
Filter based on the duration of this session. Using the format: 'dd
day(s) hh hour(s) mm minute(s) ss second(s)'. Zero values will be
omitted.
Can someone show me an example? I want to then look up that user in AD, retrieve their email address and send them an smtp email.
Here is what I have so far:
add-pssnapin vm* $FromAddr="First_Last@domain.com" $FromName="First Last" $CCAddr="First_Last@domain.com" $CCName="First Last" $SMTPServer="smtp.mailserver.tld" $VDISessionObjectArray=(Get-RemoteSession -duration >7 days) foreach ($VDISessionObject in $VDISessionObjectArray) { $ADUserObject=get-aduser -filter 'samAccountName -like $(VDISessionObject).Username' -properties mail $ToAddr=($ADUserObject).mail $ToName=($ADUserObject).SurName+", "+($ADUserObject).GivenName send-mailmessage -to "$ToName <$ToAddr>" -from "$FromName <$FromAddr>" -cc "$CCName <$CCAddr>" -subject "Please Logout" -body "please logout body" -smtpServer $SMTPServer }