Giter VIP home page Giter VIP logo

servicenow-powershell's People

Contributors

alexrgreenwood avatar apraestegaard avatar avaines avatar bergmeister avatar catgwalker avatar davehope avatar elcooper avatar gdbarron avatar gdbarron-d avatar gilmondross avatar joseluislucio avatar natescherer avatar replicajunction avatar rick-2ca avatar sam-martin avatar waynehoggett avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

servicenow-powershell's Issues

Optional to add version to url

I am trying to use Get-ServiceNowTable -Query 'sys_updated_on>javascript:gs.minutesAgoStart(15)' which gives the following error:
Invoke-RestMethod : The remote server returned an error: (404) Not Found.

If i use Invoke-RestMethod directly and use the same uri but remove /v1 from it, it works.

https://github.com/Sam-Martin/servicenow-powershell/blob/59d06b7650402a9c2af28a7cad12c9180d89ed8a/ServiceNow/Public/Get-ServiceNowTable.ps1#L61

Maybe another parameter which skips /v1 or something can be an option?

Trying to change the "assigned to" field

Hello, I have been able to change every field in service now that I need, other then the "assigned to" field. I am passing this hash table to the command Update-ServiceNowIncident

$assigned = @{ assigned_to = "$assignedTo" }
where the $assignedTo variable contains a valid email address in our environment.

This is the command I am using, similar to updating the assignment group or impacted user field.

Update-ServiceNowIncident -SysId $sysid -Values $assigned -ServiceNowCredential $global:serviceNowCredentials -ServiceNowURL $global:url

Any thoughts on what I could be doing wrong?

Thanks!

Description variable

Hi, I'm trying to create a new incident and send a description (not the short) and it's not working. I'm the only one facing that?

Thanks

Alex

Add support for date values and operators in query URLs

I'd like to be able to add a date to a query - for example, query for items in a table created between two dates, or updated since a given date. PowerShell can do this after the fact using Where-Object, but that means I have to query for ALL the data first and filter it locally. It's the ServiceNow equivalent of running Get-ADComputer -Filter * | Where-Object { $_.ComputerName -like '*Test*' } instead of running Get-ADComputer -Filter "Name -like '*Test*'".

It looks like adding dates to a ServiceNow query URL is ta little hairy, but a forum post describes one way to do it:

/api/now/v1/table/task_ci?sys_parrn_query=active=true^sys_created_onBETWEENjavascript:gs.dateGenerate('2015-04-16','00:10:00')@javascript:gs.dateGenerate('2015-04-22','12:59:59')

Adding support for that isn't too difficult, but the bigger issue is how the parameter should look. How should the user provide the date, the field to filter on, and the operator (between, greater than, etc.)? This doesn't really fit in the existing definition for New-ServiceNowQuery, Get-ServiceNowTableEntry, or any of the convenience methods - since the operator in the query isn't "equals," a simple key = value syntax won't fly for this one using -MatchContains or -MatchExact. The only way to do this in the current state of the module is to manually create a query and pass it directly to the -Query parameter of Get-ServiceNowTable.

I'm not sure what the best way is to implement this feature. I'll create a second post with a few of my own ideas, but I want to be clear that I'm not suggesting a specific implementation yet - just trying to figure out what would work best.

Update-ServiceNowNumber Issue

When trying to update a service now sc_task with this function, it fails when trying to add the "assigned_to" field.

Cannot process argument transformation on parameter 'AssignedTo'. Cannot convert the %sysID of user% value of type "System.String" to type "System.Management.Automation.ParameterAttribute".

When using Update-ServiceNowTableEntry, I can pass the value assigned_to with no problems.

Create Change task

Thanks team on working on my last request (Create change request), I must be more demanding, if possible can you please create same for change tasks as well

Unable to convert date

I've just updated to the new "ServiceNow" module, but when calling Get-ServiceNowIncident it now throws the error:

Cannot convert value "15-01-2018 18:01:12" to type "System.DateTime". Error: "String was not recognized as a valid
DateTime."
At C:\Program Files\WindowsPowerShell\Modules\servicenow\1.0.0\Public\Get-ServiceNowTable.ps1:88 char:5
+ $SNResult.$Property = [datetime]$SNResult.$Property
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvalidCastParseTargetInvocationWithFormatProvider

I've pulled the code from Update Get-ServiceNowTable.ps1 and this is what I get returned:

PS > $CultureDateTimeFormat = (Get-Culture).DateTimeFormat
$DateFormat = $CultureDateTimeFormat.ShortDatePattern
$TimeFormat = $CultureDateTimeFormat.LongTimePattern
$DateTimeFormat = "$DateFormat $TimeFormat"

PS > $DateTimeFormat
dd/MM/yyyy HH:mm:ss

If I revert back to the previous psservicenow module (v0.1.15) I can successfully return the tickets using the same command:
PS > get-module "servicenow"

ModuleType Version Name ExportedCommands


Script 0.1.15 psservicenow {Get-ServiceNowChangeRequest, Get-ServiceNowConfigurationI...

PS > $OpenTickets | select -first 1

number short_description opened_at


TEST001 Test...1...2...3 12-01-2018 13:13:29

UPDATE
Just read the updated read me - I think it's due to the implementation of returning date/time #22

Creating CI records

I see there's a Get-ServiceNowConfigurationItem cmdlet, but no New-ServiceNowConfigurationItem cmdlet. Any chance it's on the ToDo list? Would be quite helpful. Thanks!

Get-ServiceNowTable suggestion

Hey Sam,

Excellent Module by the way. I just wanted to suggest you add the sysparm_fields parameter to your Get-ServiceNowTable.

I have added it to my own copy of this module. In param:
[parameter(ParameterSetName = 'SpecifyConnectionFields')] [parameter(ParameterSetName = 'UseConnectionObject')] [parameter(ParameterSetName = 'SetGlobalAuth')] [array]$FieldsArray,

Then, just below "if ($Query)" statement I have added:
if ($FieldsArray) { $Body.sysparm_fields = $FieldsArray -join "," }

Now, I can select the fields returned in the response. I'll leave it to you to decide and variable names and whatnot, just wanted to add a quick suggestion.

Module Rename

Work has been staged for a module rename to fall into accordance with module naming standards as communicated with Issue #1. This brings up a challenge:

The PowerShell Gallery works by module name. A module rename means a new gallery entry. Microsoft recommends uploading under the new name and then unlisting the versions under the old name. There is no method of redirection available. Removing the listings has more to do with trying to get people onto the latest supported version instead of the older code than anything.

I worry a little about abandoning people that may rely upon updating via the console only. I have plenty of modules where I only update when I see a new version with Find-Module. To aid on this topic I've considered an update under the old name that would stay listed on the Gallery (for a period of time?) that would add a message to the console advertising the new name/version.

Any thoughts on those steps?

I cant find New-ServiceNowRequest

I can not find Get-ServiceNowRequest there is Update-ServiceNowRequestItem Get-ServiceNowRequest.
Is this just a feature that is missing?

Attachment Management

I've put together some functions for attachment management via the ServiceNow Attachment API. We're looking at the following functions:

  • Get-ServiceNowAttachment - Lists attachments associated with a ticket number in a specified table. Allows for filtering attachments by name making it more useful for piping into Remove or Save.
  • Add-ServiceNowAttachment - Adds an attachment associated with a ticket number in a specified table.
  • Remove-ServiceNowAttachment - Removes an attachment by its sys_id. Easiest to use the Get function to pipe into Remove.
  • Save-ServiceNowAttachment - Saves an attachment by its sys_id to destination path.

Since the unique requirement is the sys_id ServiceNow allows for attaching more than one file with the same name. There isn't a great way to update an attachment without removing and then adding it back.

Anyone else have any input as to how they deal with attachments that I should consider when I go to integrate and test these?

New-ServiceNowIncident with Caller as "SamAccountName" ?

Can a SerivceNowIncident be created by referencing the "SamAccountName" field instead of the "username" โ“

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 "[email protected]" as username.

Thank for the great functions.

Supplying Servicenow API key along with Set-ServiceNowAuth

Great work and I'm looking at using this in my environment for incident automation especially. In order to interface with Servicenow in my environment an API key in the header info is required.

Would it be possible to provide a way to input this as an optional parameter/argument as part of the Set-ServiceNowAuth?

/api/now/v1 doesn't work for me

Heya,

Just wanted to let you know that for some reason on my SNOW instance having the /v1 at the end of the PSServiceNow.psm1 Set-ServiceNowAuth stops it from working. Removing the /v1 makes it work.

Cheers

Match arguments seem to be ignored

Have tried:

Get-ServiceNowIncident -ServiceNowCredential $Creds -ServiceNowURL xxxxxxxxxxxxxxxxx.service-now.com -MatchExact @{Number="INC9999999"}

and

Get-ServiceNowConfigurationItem -ServiceNowCredential $Creds -ServiceNowURL xxxxxxxxxxxxxxxxxxx.service-now.com -MatchExact @{Name="anynameyouwanttotry"}

but all I ever get back is last 10 created items (in this case, incident and CI). It does not care about -MatchExact or -MatchContains

Anyone else run into this?

Create Change request

Hello team,
thanks for your hard work, can you please create a new function to create new change request, it should allow us to search and add approval groups.
The best i can propose is to clone a change template and ask required parameters

URL value for set-servicenowauth

You might want to provide some more clarity in the msg response. I initially assumed you wanted the full URL "https://xxxxx.service-now.com/" and ultimately it was just the DNS. Not trying to nit-pick, but I know I would have found it useful. I parsed through the modules to find the use of the $url variable and figured it out, so its not anything major. Hopefully this is useful feedback.

I love the module btw, its really useful!

Get-ServiceNowIncident with sys_created_on

Is there a way to request only incidents created on or after a certain date?

Was thinking that -MatchExact could be used with some sort of greater than or equal to thing.

Date/Time Accomodations

I've rolled back PR #36 in the development branch after testing and discussing the changes with the submitter. As a result of the discussion we should consider the following two accommodations:

  • Query for the current user's date/time format in their user profile. Depending on performance this may only be enabled when Set-ServiceNowAuth is utilized.
  • Enable a configuration setting for customizing the date/time format. In cases where the glide.sys.date format doesn't match any of the assumptions the module may make a configuration would allow a user to force a match that results in a DateTime object instead of the default string.

Any tips on paging result sets?

I can get the next URL by modifying the end of Get-ServiceNowTable and replaced Invoke-RestMethod with this:

    $data = Invoke-WebRequest -Uri $Uri -Credential $ServiceNowCredential -Body $Body -ContentType "application/json"
    if ($data.Headers.Link -match ".*\<(.*?)\>;rel=`"next`"") {
	$next_url = $Matches[1]
    } else {
	$next_url = $null
    }

    (ConvertFrom-Json $data.Content).result | Add-Member -MemberType NoteProperty -Name next_url -Value $next_url -PassThru

But then I have to write more code to make it so that Get-ServiceNow can accept the URL and similarly retrieve the next page of results.

Warning when using -Limit in Get-ServiceNowTable

First, thanks for putting this together as it has been immensely helpful.

When calling Get-ServiceNowTable I want to get all records in the table so am using -Limit with a high number. But when I do that I get a warning about it being deprecated and to use -First instead, however that parameter is not yet available. Has it just not yet been implemented?

Thanks, Bruce...

New Request Tickets

There was a submission for #98 to add New-ServiceNowRequest to the module. This seemed straight forward enough and I pushed it to dev, but after looking through it I'm not sure that addition does what's expected. In my environment a REQ means RITMs which means workflows. My developers tell me that's what they expect from those tickets as well. Are people utilizing REQ tickets in another way? Please share some user stories on how your environment uses REQs so I can ensure the command is useful.

Auth via ADFS?

Hello,

I was trying to use your module and it seems I fail to authenticate with credentials via ADFS. Is it coded in because it's unclear?
And -Debug switches do not get much out.

PS C:\Windows\system32> Get-ServiceNowUser -Credential $cred2 -ServiceNowURL OBFUSCATEDl.service-now.com -Verbose -Debug
VERBOSE: Testing url: OBFUSCATED.service-now.com
VERBOSE: GET
https://OBFUSCATED.service-now.com/api/now/v1/table/sys_user?sysparm_display_value=true&sysparm_query=ORDERBYDESCname&s
ysparm_limit=10 with 0-byte payload
Invoke-RestMethod : The remote server returned an error: (401) Unauthorized.
At C:\Program Files\WindowsPowerShell\Modules\servicenow\1.8.0\Public\Get-ServiceNowTable.ps1:132 char:16

  • ... $Result = (Invoke-RestMethod -Uri $Uri -Credential $Credential -Body ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
      eption
    • FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

You cannot call a method on a null-valued expression.
At C:\Program Files\WindowsPowerShell\Modules\servicenow\1.8.0\Public\Get-ServiceNowUser.ps1:90 char:34

  • ... Each-Object{$_.PSObject.TypeNames.Insert(0,"ServiceNow.UserAndUserGro ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (:) [], RuntimeException
    • FullyQualifiedErrorId : InvokeMethodOnNull

It is even more complicated in my case because the company I work for offers only complicated options in the ADFS. That is PKI, SMS or OTP.

Allow 'Get-ServiceNowTableEntry' to propagate Exception (and in all other functions)

We routinely call 'Get-ServiceNowTableEntry' to call a custom table to determine if a record exists, so we can choose to either create or update the record. If the record does not exist 'Get-ServiceNowTableEntry' writes out the exception ($PSItem) to the console. I would prefer that the exception is simply propagated. Propagating the exception will allow me to choose what to do.
Since this is an automated process, this exception would be valuable to add to our exception logs so that is is tracked and ultimately corrected.

Currently I get a ugly console experience and $null return.

This is what exists today
Try {...} Catch { Write-Error $PSItem } }

Would like to see Try/Catch removed or change to the equivalent to this
Try {...} Catch { throw } }

CMDB

Hello Team,
Can you please add support for new/get/set for servicenow CMDB as well.

Make New-ServiceNowQuery Private

New-ServiceNowQuery is a candidate for being made private in the module. Looking for feedback from people that are utilizing it for their own functions outside of the module that may be impacted. Otherwise as far as the module is concerned it's nothing but a support function and can be hidden.

multiple variable search

Is it possible to search two attributes at the same time.

aka Get-ServiceNowIncident -MatchContains @{assignment_group='Corporate' -and location='texas' -and active='true'}

I would like to get specific tickets using multiple hashtables

Create Service Requests

Hello Team
You have a great repo here .

Please guide How can I create Service Requests using the Wrapper . - tickets which are like REQ0012958
Requesting to please help ASAP - I'm stuck and im new here
any guidance will be greatly appreciable .
Kind regards
Arun
[email protected]

Getting the Sys_Id information on an already existing service now incident

Hello, is there an existing way to grab the sys_id for an already existing ticket/incident number in service now? What I am trying to do is update an incident which wasn't created by the service now module, but I can't find a way to grab the sys_id without actually creating a ticket using your module.

Avoid using $Global variables

The $Global variables defined in Set-ServiceNowAuth should be changed to script scoped variables to avoid polluting the global scope but also stops PSSA alerts triggering.

Support using Proxy for ServiceNow URL

Hi ,

i just want to query the Status i see an already open "fork" #7 for my Question but it was never commited since ~ 1 year.
Any Chance this feature will be inserted ?
I have to provide a Proxy with credentials or at least Parameter DefaultCredentials to Invoke-RestMethod.

Cheers

Markus

Filter on multiple fields, including state

Hi, I'm using these cmdlets to pull ServiceNow Incidents and Changes for my organization. I'm able to filter on multiple fields, however cannot filter on state. Below are shown the 2 calls I used to try and filter on the state field, for both Incidents and Changes. Although I can see there is a state property returned on each line of the array ( $SNIncidents or $SNChanges), when trying to filter on it using the "state=" filter shown below, I receive the error: "You cannot call a method on a null-valued expression"

The call works fine, if I don't try to filter on state

$SNIncidents = Get-ServiceNowIncident -MatchContains @{assignment_group='My Group'; opened_at='2018'; state='New'}

$SNChanges = Get-ServiceNowChangeRequest -MatchContains @{cmdb_ci='AD Change'; assignment_group='My Group'; state='New'}

Invoke-RestMethod : The remote server returned an error: (404) Not Found.
At C:\Mypath\ServiceNow\Public\Get-ServiceNowTable.ps1:81 char:16

  • ... $Result = (Invoke-RestMethod -Uri $Uri -Credential $ServiceNowCreden ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
      eption
    • FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

You cannot call a method on a null-valued expression.
At C:\Mypath\ServiceNow\Public\Get-ServiceNowIncident.ps1:96 char:30

  • ... ForEach-Object{$_.PSObject.TypeNames.Insert(0,"ServiceNow.Incident")}
  •                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (:) [], RuntimeException
    • FullyQualifiedErrorId : InvokeMethodOnNull

Domain name set to https

I use Set-ServiceNowAuth and use example.com (without http or https). When I call Get-ServiceNowIncident I get error domain not resolved 'https'.
I had to remove 'https://' from below line in Get-ServiceNowTable.ps1
$ServiceNowURL = 'https://' + $ServiceNowURL + '/api/now/v1'

Failure When Calling Credential & ServiceNowURL Parameters

When using -Credential and -ServiceNowUrl parameters the function fails or default to the global variables. This issue is due to renaming the PSCredential parameter to Credential.

The following functions are impacted:

  • Get-ServiceNowChangeRequest
  • Get-ServiceNowConfigurationItem
  • Get-ServiceNowIncident
  • Get-ServiceNowRequest
  • Get-ServiceNowRequestItem
  • Get-ServiceNowUser
  • Get-ServiceNowUserGroup

Each of the functions should have the line $getServiceNowTableSplat.Add('ServiceNowCredential', $ServiceNowCredential) changed to $getServiceNowTableSplat.Add('Credential', $Credential) (the important part being the variable name, although while we're at it the parameter name we pass can be updated as well).

Additionally in Get-ServiceNowTable all instances of $ServiceNowCredential need changed to $Credential.

Columns returned in Get-ServiceNowTable not returned in the order requested

When I call Get-ServiceNowTable and specify -Query with the set of column names the columns do not return in the order I specified. So I have to then do a Select to get them in the order I want. Is this a limitation of the API itself?

Get-ServiceNowTable -Table $snowTableName -Limit 10000 -Properties $cols | select $cols | Export-Csv -Path $csvFileName

Thanks, Bruce...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.