Snow-Shell / servicenow-powershell

PowerShell module to automate ServiceNow service and asset management. This module can be used standalone, with Azure Automation, or Docker.
Apache License 2.0
361 stars 171 forks source link

New-ServiceNowIncident with Caller as "SamAccountName" ? #118

Closed Herlevsen9 closed 3 years ago

Herlevsen9 commented 3 years ago

Can a SerivceNowIncident be created by referencing the "SamAccountName" field instead of the "username" :question:

I have a environment, where username syntax changed a few years ago, so old users have "Lastname.Firstletter Of Firstname" as SamAccount, and their username/email cannot be pulled by powershell when creating a ticket. New users have "firstname.lastname" as SamAccountName and "firstname.lastname@domain.com" as username.

Thank for the great functions.

gdbarron commented 3 years ago

Hi @Herlevsen9. Which property/field are you referring to for samaccountname/username?

Herlevsen9 commented 3 years ago

We are trying to implement Avecto/BeyondTrust integration to ServiceNow, which uses this module to create ServiceNow incidents from powershell. BeyondTrust uses a function Get-PREnvironmentVariable -Name 'UserName' to get current user/caller, which is then parsed into

        $snUserQuerySplat = @{
            user_name = $dpUsername
        }
Get-ServiceNowUser -MatchExact $snUserQuerySplat

Your question made look at the documentation and code again, and I might have a solution. Can Get-ServiceNowUser take SamAccountName (ActiveDirectory) as input ? instead of email (being used as ServiceNow User ID) SNOW1 SNOW2

gdbarron commented 3 years ago

Sorry for the delay, I didn't see any notification come through. You should be able to use any field with -MatchExact or -MatchContains, just need to know the field name. If unsure of the field name, add it to the filter query in the SN GUI, then right click on the filter breadcrumb at the top and select copy query. That will give you the field name.

Herlevsen9 commented 3 years ago

Thank you for your input and help. I got it working now.