Home Analyst Portal

Get current UserID from Cireson API with powershell

Jan_SchulzJan_Schulz Customer Adept IT Monkey ✭✭

Hi,

how is it possible to get the current userid (the logged on windows user) from the cireson API. Because in some of the queries we need a user id. With invoke-webrequest we can use -usedefaultcredentails but with wich query we can get the logged on userid? We dont want to use the smlets for this.

best regards,

Jan

Best Answers

  • Jan_SchulzJan_Schulz Customer Adept IT Monkey ✭✭
    Answer ✓

    Hi @Shane_White ,

    yeah, thank you. But i need to get the userid wihtout using the browser.

    But i have already helped me out.

    I use the Method api/V3/User/GetUserList and filter the user fullname. I get the fullname with:

    $dom = $env:userdomain

     $usr = $env:username

     return ([adsi]"WinNT://$dom/$usr,user").fullname

    But it would be nice to get the currentuserID directly through the API.

    Anyway i have a workaround. :-)

Answers

  • Shane_WhiteShane_White Cireson Support Super IT Monkey ✭✭✭✭✭

    Hi @Jan_Schulz

    Do you have to use PowerShell?

    I would just do session.user.Id in the Dev tools, if this is what you are after!

    You can use this in the Javascript for your API too!


    Thanks,

    Shane

  • Jan_SchulzJan_Schulz Customer Adept IT Monkey ✭✭
    Answer ✓

    Hi @Shane_White ,

    yeah, thank you. But i need to get the userid wihtout using the browser.

    But i have already helped me out.

    I use the Method api/V3/User/GetUserList and filter the user fullname. I get the fullname with:

    $dom = $env:userdomain

     $usr = $env:username

     return ([adsi]"WinNT://$dom/$usr,user").fullname

    But it would be nice to get the currentuserID directly through the API.

    Anyway i have a workaround. :-)

  • Shane_WhiteShane_White Cireson Support Super IT Monkey ✭✭✭✭✭

    Well you can parse session.user.Id anywhere you want! As long as the session exists :-)

    So you could pass that into the API for example (off the top of my head):

    api/V3/User/GetUserRelatedInfoByUserId?userId={userId}

    Would be

    api/V3/User/GetUserRelatedInfoByUserId?userId=session.user.Id

    Would this work in your scenario?

    Thanks,

    Shane

  • Jan_SchulzJan_Schulz Customer Adept IT Monkey ✭✭

    My problem is i have no session and no browser. I need a dynamic in the script because multiple users could use this script.

    Powershell needs to get the userid from the cireson api, but where can i get this without a session?

    I think my workaround is good enough.

    thank you Shane for take the time to help me :-)

  • Shane_WhiteShane_White Cireson Support Super IT Monkey ✭✭✭✭✭

    No worries Jan, it would probably be a little bit fiddly, you'd probably need to save some additional parameters in PowerShell, and use that with Get-SCSMObject of the user, grab their Id and pass that into the API?

    Take care!

    Shane

  • Jan_SchulzJan_Schulz Customer Adept IT Monkey ✭✭

    @Shane_White sorry i dont write that i cant use a powershell module, because we cannot know if the module is on the target client. So its better for us to only use plain powershell cmdlets and cireson Webservice.

  • Shane_WhiteShane_White Cireson Support Super IT Monkey ✭✭✭✭✭

    Ohhhh I see... Well glad you have a workaround! I think my ideas are exhausted unless anyone else has any ideas!

  • Jan_SchulzJan_Schulz Customer Adept IT Monkey ✭✭

    @Geoff_Ross

    thank you for this solution.

    It works great :-)

    And thank you @Shane_White for your information.

    Its a great community here.

Sign In or Register to comment.