ARS PowerShell script - Session object

What is the equivalent of the following VBScript script snippet in PowerShell?

Set Session = Security.Sessions.Current
strUserADsPath = Session.UserPath
  • Try this:
      
    Security.Sessions.Refresh()       
    Set Session = Security.Sessions.Current               
    connectedUserDN = Session.UserPath

    Message was edited by: Reto Bachmann
  • Sorry, it's not the answer, but....

    Why not to use Request.WhoAmI() to get the connected user DN?
  • Niether syntax works in ARS PowerShell scripting policy...
    I tried:
    $Request.WhoAmI $strSan, $strDn
    and
    $Session = $Security.Sessions.Current

    I also noticed that $Request.class doesn't return the value.

    What am I missing here???
  • Hey Victoria,

    I finally got my 6.5 lab running over the holiday and ran some tests with the Request.Class and Request.WhoAmI objects. While the $Request.Class worked fine in the onPreCreate, I found that the $DirObj.Class ran better in other evt handlers. I had the same initial results as you described with WhoAmI - blank values.

    Seemed that Powershell needed some guidance in locating the return values for this sub so I ran the following and it worked fine (see image).

    [i]function onPreCreate($Request)
    {
    $UserClass = $request.Class
    $a = "SamAccountName"
    $b = "DN"
    $UserSession = $Request.WhoamI([ref]$a, [ref]$b)
    $UserName = $b

    throw "Test Error by $UserName with class of $UserClass"

    }[/i]

    All in all, it seems much easier to stick with VBScript when calling to this object. Otherwise I suppose you could drop this PoShell code into a library script and call to it as needed.

    From what I found, the values for $a and $b above can be anything but $null ... I just gave them friendly names for my own reference.

    I have had zero luck with referencing the security object, however. Let me know if you crack that one ;)
  • Not sure why my account didn't show up properly on the last response  ... time to check my IE settings again
  • Thanks for the clue.
    The following script snippet works:

    $Security.Sessions.Refresh()       
    $Session = $Security.Sessions.Current               
    $connectedUserDN = $Session.UserPath
  • Thanks for your post Greg. It works in my Lab as well.