Error says what do to but don't understand it.

This topic contains 2 replies, has 2 voices, and was last updated by  Thom Schumacher 5 months, 3 weeks ago.

  • Author
    Posts
  • #67675

    PeterKiers
    Participant

    Hi,

    I use Powershell to automate an application called ServiceNow. To access ServiceNow with PowerShell I have
    import a module called PSServiceNow. Now I have all the functions of Servicenow to my displossal.
    In the help-section I have even a great example "how to create a new ticket in ServiceNow". But when i run
    the code I get an error saying that i must authenticate first. It even gives me 3 steps to do this:
    Exception: You must do one of the following to authenticate:
    1. Call the Set-ServiceNowAuth cmdlet
    2. Pass in an Azure Automation connection object
    3. Pass in an endpoint and credential

    But I don't understand what it means. Does perhaps someone know what I have to do to make my code work:

    Import-Module PSServiceNow
    New-ServiceNowIncident -ShortDescription "Testing with Pester" -Description "Long description" -AssignmentGroup "e9e9a2406f4c35001855fa0dba3ee4f3"  -Category "Internal" -SubCategory "Task"  -Comment "Comment" -ConfigurationItem "bee8e0ed6f8475001855fa0dba3ee4ea" -Caller "Peter Kiers" 
    

    Thank you in advanced,

    Greetings, Peter Kiers

  • #67677

    PeterKiers
    Participant

    I think I have covered step 1. But I don't understand step 2 and 3:

    $uid = "xxxxxxx" 
    $pwd = "xxxxxxx"
    $secpasswd = ConvertTo-SecureString $pwd -AsPlainText -Force
    $creden = New-Object System.Management.Automation.PSCredential ($uid, $secpasswd)
    $mycredentials =  Set-ServiceNowAuth -url https://apgprd.service-now.com/nav_to.do?uri=%2Fhome.do -Credentials $creden
    
  • #67684

    Thom Schumacher
    Participant

    Give this a try for your credential object:

    $creden = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $uid, $secpasswd

    There are a few good articles on Credentials you could look at Warren Frame's article on this type of thing here:

You must be logged in to reply to this topic.