Get current UserID from Cireson API with powershell
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_Schulz Customer Adept IT Monkey ✭✭
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. :-)
0 -
Geoff_Ross Cireson Consultant O.G.
That solution you have in place seems fine but if you need something a little more performant you could use a Dashboard Query.
First, inject one into your ServiceManagement database:
INSERT INTO DataSource VALUES ( '7A03B8FE-9AA4-49D1-AAE3-67CA60FA79B9', 'Query for Getting UserId', NULL, 'SELECT @UserId AS UserId', 1 )
This creates a query with id '' that just selects the user's ID use the @UserId token.
You can then call this api to get the results
/api/v3/Dashboard/GetDashboardDataById/?queryId=7a03b8fe-9aa4-49d1-aae3-67ca60fa79b9
Geoff
6
Answers
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
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. :-)
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
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 :-)
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
@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.
Ohhhh I see... Well glad you have a workaround! I think my ideas are exhausted unless anyone else has any ideas!
@Jan_Schulz
That solution you have in place seems fine but if you need something a little more performant you could use a Dashboard Query.
First, inject one into your ServiceManagement database:
This creates a query with id '' that just selects the user's ID use the @UserId token.
You can then call this api to get the results
Geoff
@Geoff_Ross
thank you for this solution.
It works great :-)
And thank you @Shane_White for your information.
Its a great community here.