@@ -15,6 +15,11 @@ function Get-ServiceNowUser{
1515 [Parameter (Mandatory = $false )]
1616 [int ]$Limit = 10 ,
1717
18+ # Fields to return
19+ [Parameter (Mandatory = $false )]
20+ [Alias (' Fields' )]
21+ [string []]$Properties ,
22+
1823 # Hashtable containing machine field names and values returned must match exactly (will be combined with AND)
1924 [Parameter (Mandatory = $false )]
2025 [hashtable ]$MatchExact = @ {},
@@ -45,34 +50,35 @@ function Get-ServiceNowUser{
4550
4651 # Query Splat
4752 $newServiceNowQuerySplat = @ {
48- OrderBy = $OrderBy
53+ OrderBy = $OrderBy
4954 OrderDirection = $OrderDirection
50- MatchExact = $MatchExact
51- MatchContains = $MatchContains
55+ MatchExact = $MatchExact
56+ MatchContains = $MatchContains
5257 }
5358 $Query = New-ServiceNowQuery @newServiceNowQuerySplat
5459
5560 # Table Splat
5661 $getServiceNowTableSplat = @ {
57- Table = ' sys_user'
58- Query = $Query
59- Limit = $Limit
62+ Table = ' sys_user'
63+ Query = $Query
64+ Limit = $Limit
65+ Fields = $Properties
6066 DisplayValues = $DisplayValues
6167 }
6268
6369 # Update the splat if the parameters have values
64- if ($null -ne $PSBoundParameters.Connection )
65- {
70+ if ($null -ne $PSBoundParameters.Connection ) {
6671 $getServiceNowTableSplat.Add (' Connection' , $Connection )
6772 }
68- elseif ($null -ne $PSBoundParameters.ServiceNowCredential -and $null -ne $PSBoundParameters.ServiceNowURL )
69- {
70- $getServiceNowTableSplat.Add (' ServiceNowCredential' , $ServiceNowCredential )
71- $getServiceNowTableSplat.Add (' ServiceNowURL' , $ServiceNowURL )
73+ elseif ($null -ne $PSBoundParameters.ServiceNowCredential -and $null -ne $PSBoundParameters.ServiceNowURL ) {
74+ $getServiceNowTableSplat.Add (' ServiceNowCredential' , $ServiceNowCredential )
75+ $getServiceNowTableSplat.Add (' ServiceNowURL' , $ServiceNowURL )
7276 }
7377
7478 # Perform query and return each object in the format.ps1xml format
7579 $Result = Get-ServiceNowTable @getServiceNowTableSplat
76- $Result | ForEach-Object {$_.PSObject.TypeNames.Insert (0 , " ServiceNow.UserAndUserGroup" )}
80+ If (-not $Properties ) {
81+ $Result | ForEach-Object {$_.PSObject.TypeNames.Insert (0 , " ServiceNow.UserAndUserGroup" )}
82+ }
7783 $Result
7884}
0 commit comments