Kaseya Community

get logged on username and Active Directory data for use in script

This question is answered

I would like to do the following in a Kaseya script:

  • get logged on username
  • get AD info about that username, specifically e-mail address.
  • set the email address as a variable to be used in another line in the script

The end result would be:  executeShellCommand ("file.exe /user.email@address", "Execute as User", All Windows Operating Systems", "Halt on Fail")

anyone know how to do this?

Verified Answer
  • get logged on username

    You can get this from Kaseya, #vAgentConfiguration.currentUser#

    But if the goal is just to get email address, and the user is logged in, you dont need this

    get AD info about that username, specifically e-mail address.

    ExecuteshellCommandtoVariable 

    whoami /upn

    now email is in the Variable 

    #global:cmdresults#

    set the email address as a variable to be used in another line in the script

    already ready already;
    #global:cmdresults#

    If the user is not logged in, its a bit more complicated... but you can see "last logged in user
    #vAgentConfiguration.lastLoginName#

    Then you need to query AD... Google is your friend.  Most likely a powershell script... but not likely a one liner

    Hope this helps.

    Kirk...

All Replies
  • get logged on username

    You can get this from Kaseya, #vAgentConfiguration.currentUser#

    But if the goal is just to get email address, and the user is logged in, you dont need this

    get AD info about that username, specifically e-mail address.

    ExecuteshellCommandtoVariable 

    whoami /upn

    now email is in the Variable 

    #global:cmdresults#

    set the email address as a variable to be used in another line in the script

    already ready already;
    #global:cmdresults#

    If the user is not logged in, its a bit more complicated... but you can see "last logged in user
    #vAgentConfiguration.lastLoginName#

    Then you need to query AD... Google is your friend.  Most likely a powershell script... but not likely a one liner

    Hope this helps.

    Kirk...

  • Thanks!

  • It's launching odopen, but not entering the email address.  What have I done wrong here?
    I've tried executeShellCommandToVariable as "system" and as "user", but odopen will only work to launch if run as user.
    This opens the GUI, without the variable entered:

    odopen command obtained here:  https://docs.microsoft.com/en-us/onedrive/deploy-on-windows

  • as it turns out, it wants to be opened by iexplore.exe , not explorer.exe