Home Community Uploads
image

Cireson Partners, Customers and Community members share your customizations and examples here to help benefit the community as a whole to earn Kudos and badges.

DISCLAIMER

All files and projects located here are provided and come "as-is" and without any warranty or support. Use at your own risk. Your use of Community Uploads is subject to our Terms of Use.

Cireson does not and will not support or maintain these enhancements, extensions, and scripts.

For Team Cireson uploads click here.

PowerShell module to query the Cireson Portal (CiresonPortalPS)

LazyWinAdminLazyWinAdmin Member IT Monkey ✭
edited July 2016 in Community Uploads
This PowerShell module allows you to interact with the Cireson Portal API.
You can retrieve information from SCSM without the need to have the Smlets module or the Cireson Portal.
Hope you find it useful!

https://github.com/lazywinadmin/CiresonPortalPS

Unfortunately I changed of employers so I don't have access to the Cireson Portal anymore and can't develop further. Contributions are more than welcome!

Comments

  • Thanks for Sharing this! Moving to the new "Community Uploads" Category for better viability and to help anyone else wanting to implement \ learn 
  • Geoff_RossGeoff_Ross Cireson Consultant O.G.
    Wow, amazing. Any chance of getting this into the PowerShell Gallery.
  • LazyWinAdminLazyWinAdmin Member IT Monkey ✭
    Sounds good, I will add this to the Gallery
  • Geoff_RossGeoff_Ross Cireson Consultant O.G.
    Great, that will make I can build scripts that use it and run them anywhere without having to install the module first.
  • LazyWinAdminLazyWinAdmin Member IT Monkey ✭
    It's now on the PowerShell gallery

    Install-Module CiresonPortalPS
  • Mike_RistonMike_Riston Customer IT Monkey ✭
    Anyone else able to get this to work? I'm trying to get this up and running but am have an issue with being not authenticated. I see that the API documentation & examples say that an Authentication Token must be obtained and send along with all future requests to the API. I've been able to get a JSON object retrieved from api/V3/Authorization/GetToken, but am unsure what to do now.
  • Adrian_PaechAdrian_Paech Customer Advanced IT Monkey ✭✭✭

    Works fine for me.

    I gather you ran Set-CiresonPortalPSConfiguration first?

    Love this PS gallery offering.

    I would really like to see it extended at some point to include getting and updating Type Projections at some point if possible. :)

  • Adrian_PaechAdrian_Paech Customer Advanced IT Monkey ✭✭✭
    edited July 2017

    Using your module as an example, I just wrote "Get-CiresonPortalProjection.ps1" to pull projection data,

    and "Commit-CiresonPortalProjection.ps1" which essentially enables us to update projections via 'api/V3/Projection/Commit'.

    I have attached them to this post.

    Notice that "Get-CiresonPortalProjection.ps1" contains a parameter called: 'ReturnDuplicateCopy'. When set to true, this will force the function to return the same result, but instead of only returning one PSCutomObject with all related JSON data, it returns two copies as part of an array object. The main reason I did this is because it can be quite tricky in powershell to copy one PSCutomObject over to another without bringing over references from the original object.

    The main purpose of copying / duplicating the JSON object is to be used with Commit-CiresonPortalProjection.ps1, which compares the two objects to figure out what the differences are, so that the required changes can be applied.

    The '$($result | ConvertTo-Json -depth 100 | ConvertFrom-Json)' command successfully gets around this issue, but this wouldn't be an obvious solution to most.

    Both functions seem to work pretty well. please check them out and if you happy, please add them into the gallery.

    Cheers :)

    Adrian

  • Adrian_PaechAdrian_Paech Customer Advanced IT Monkey ✭✭✭
    Fixed a bug in Commit-CiresonPortalProjection.js ( attached )

    There was an issue where the JSON string was being truncated, so I had to change | ConvertTo-JSON to | ConvertTo-JSON -depth 100

    This ensures you can apply changes right down through the hierarchy of relationships.

    Also a reminder to people who happen to use this, if you want to add a relationship that does not already exist (not just change an existing relationship), you need to update the "NameRelationships" field... something like this..
    $SRTypeProj = !! Type Projection ID !!
    $user = !! PSCustomObject containing user details !!
    
    $dupTPs = get-CiresonPortalProjection -Id "SR11499" -TypeProjectionId $SRTypeProj -ReturnDuplicateCopy $true 
    $orig = $dupTPs[0]
    $new = $dupTPs[1]
    
    $rel = [PSCustomObject]@{Name = "AssignedWorkItem"; RelationshipId = "15e577a3-6bf9-6713-4eac-ba5a5b7c4722"}
    $new.NameRelationship += $rel
    $new | add-member -Name AssignedWorkItem -MemberType NoteProperty -Value $user
    
    Commit-CiresonPortalProjection -OrigionalData $orig -CurrentData $new
    
  • LazyWinAdminLazyWinAdmin Member IT Monkey ✭
    edited July 2017
    Thanks @Adrian_Paech !
    Unfortunately I changed work and don't have access to Cireson Portal anymore.

    Do you want me to add your functions to the module on github ? or do you want to take care of it  and make a Pull request ?
    https://github.com/lazywinadmin/CiresonPortalPS

    I can then publish a new version onto the PowerShell Gallery
  • Adrian_PaechAdrian_Paech Customer Advanced IT Monkey ✭✭✭

    That would be great!
    I Just tried to add a pull request, but I cant seem to do it for some reason, the button to create one is greyed out.

    I am happy to upload the changes, but don't have access. my GitHub username is axpae.

    Otherwise, I am happy if you want to upload the changes.

    Regards,

    Adrian

  • LazyWinAdminLazyWinAdmin Member IT Monkey ✭
    Hey @Adrian_Paech
    In order to contribute, you need to fork the repo under you user, then update the code. Once this is done you can create a Pull request.

    If you are not familiar with this process, I will take care of it this week-end :smile:

    Thanks again for your help
  • LazyWinAdminLazyWinAdmin Member IT Monkey ✭
    Hey @Adrian_Paech
    I updated the branch 'dev' of the repository: https://github.com/lazywinadmin/CiresonPortalPS/tree/dev/CiresonPortalPS

    Note that I changed the name of Commit-CiresonPortalProjection to Update-CiresonPortalProjection and gave you credits to in the .NOTES of each functions.

    Question/request for you:
    For Get-CiresonPortalProjection
    -Where and How can a user retrieve a TypeProjectionId ? Is there a way to retrieve all the types ?

    For Update-CiresonPortalProjection
    -Can you give an example of usage ? I see in the Comment Based help of the function you provided the following example: Update-CiresonPortalProjection -OrigionalData $orig -CurrentData $new

    How would you get $Orig and $new ? (just need the syntax to put it in the example)

  • Adrian_PaechAdrian_Paech Customer Advanced IT Monkey ✭✭✭

    Ive just made some other minor updates.

    I have figured out how to create a fork now, so I will do that.
    I will add in the comments as requested.
    I also added in additional parameter in 'Update-CiresonPortalProjection' called runConcurrencyCheck

    Also,

    Where you have the following code in the various functions...

      TRY{
       Write-Verbose -Message $(New-ScriptMessage -Block BEGIN -message 'Checking Pre-Requisites')
       Get-CiresonPortalPSConfiguration -WarningAction Stop
      }
      CATCH
      {
       # Stop the function
       break;
      }

    I have had to change this to:

      TRY{
       Write-Verbose -Message $(New-ScriptMessage -Block BEGIN -message 'Checking Pre-Requisites')
       Get-CiresonPortalPSConfiguration -WarningAction Stop
      }
      CATCH
      {
       # Stop the function
       Throw "Not Connected to Cireson Portal"
      }

    The main reason, is that I need to detect when the connection has timed out (when an exception is thrown), so that I can re-connect, but I only want to reconnect when required. If that makes sense..

    With a break; I cant detect this, because it does not throw an exception.

    I will make a fork and add these change in. Feel free to adjust it if you wish.

    Cheers,

    Adrian

  • Adrian_PaechAdrian_Paech Customer Advanced IT Monkey ✭✭✭

    So, not sure if I didn't this correctly, but I have tried to add two pull requests:

    axpae-Get-CiresonPortalUser:

    'Get-CiresonPortalUser' has already been written, but was missing from the list of available functions to import.

    and

    axpae-FunctionUpdates:

    Update-CiresonPortalProjection.ps1:
     - Added '-Force' Switch
     - Improved Help / Examples.

    Get-CiresonPortalProjection.ps1:
     - Added '-ReturnDuplicateCopy' Switch
     - Improved Help / Examples.

    For all other functions, added line:
       Throw "Not Connected to Cireson Portal"
    ... To help with error handling.

    What I did was download your latest Dev version and made the changes to that dev version.

    Unfortionately, when I did the fork request, it would only let me do it against the master prod version, so in axpae-Get-CiresonPortalUser you will notice that ModuleVersion = '1.0.0.2'.

    I did quite a bit of testing, so code should be fine.

    Adrian

  • LazyWinAdminLazyWinAdmin Member IT Monkey ✭
    Hi @Adrian_Paech
    I see two branches on your repository with those names but I did not receive pull requests.

    I compare the two but something is off... did you change the encoding of the files ? It looks like all the files coming from your repo are different :-/
  • Adrian_PaechAdrian_Paech Customer Advanced IT Monkey ✭✭✭

    No I didn't change the encoding :-/

    I really don't know how to fix it. Any chance you can sort it?

    Am kind of new to this GitHub thing (obviously) :)

    I have attached the latest code if that helps.

  • Adrian_PaechAdrian_Paech Customer Advanced IT Monkey ✭✭✭

    I have also added 'Get-CiresonPortalEnumDisplayName.ps1'

    Which allows for retrieving of Enum Display names. I created a fork and uploaded the file, otherwise I have attached it here.

  • LazyWinAdminLazyWinAdmin Member IT Monkey ✭
    Thanks Adrian, I ended up adding them into the Dev branch myself
    https://github.com/lazywinadmin/CiresonPortalPS/tree/dev

    Can you download it and give it a shot ?
    https://github.com/lazywinadmin/CiresonPortalPS/archive/dev.zip

    Then I'll merge with master and upload to PowerShell Gallery

    Thanks again for your help
  • Adrian_PaechAdrian_Paech Customer Advanced IT Monkey ✭✭✭

    For some reason all of the amendments have not come across into dev.

    Amendments required:

     - Add 'Get-CiresonPortalUser' to line 69 in CiresonPortalPS.psd1

     - Add the latest versions of Update-CiresonPortalProjection and Get-CiresonPortalProjection.

     - Ensure that functions throw exception when not connected, rather then just 'breaking'. e.g.:
    Throw "Not Connected to Cireson Portal"

    I have re-attached all functions and required amendments.

    Thanks again.

    Adrian

  • LazyWinAdminLazyWinAdmin Member IT Monkey ✭
    Thanks Adrian, I just updated the code
  • Adrian_PaechAdrian_Paech Customer Advanced IT Monkey ✭✭✭

    Almost.

    There was a typo in "Get-CiresonPortalRequestOfferingTop.ps1". Was just missing a bracket.

    I have fixed it in the attached, I have also included one additional function "Get-CiresonPortalObjectHistory"

    If you could include this one aswell that would be much appreciated.

    I am pretty confident we don't need to test again, you should be good to go with putting it into production now.

    Regards,

    Adrian

  • Adrian_PaechAdrian_Paech Customer Advanced IT Monkey ✭✭✭

    Heya LazyWinAdmin.

    Any chance we could get the final version uploaded?

    Thanks again!,

    Adrian

  • Adrian_PaechAdrian_Paech Customer Advanced IT Monkey ✭✭✭

    Hi.

    To hopefully make things a bit easier, I have created another fork with all ammendments so that changes can be easily committed.

    I have thoroughly tested this version.

    If can be viewed here:

    https://github.com/axpae/CiresonPortalPS/tree/axpae-FunctionUpdates

    and downloaded here for testing here:

    https://github.com/axpae/CiresonPortalPS/archive/axpae-FunctionUpdates.zip

    I tried to create a pull request against your "Dev" fork, but I don't have access to upload files to Dev, hence why I had to create a separate fork.

    If you could commit these changes, that would be much appreciated.

    Kind Regards,

    Adrian

  • LazyWinAdminLazyWinAdmin Member IT Monkey ✭
    Thanks Adrian,will check it out this week-end. (sorry for delay, been travelling)
  • LazyWinAdminLazyWinAdmin Member IT Monkey ✭
    dev branch merge to master.

    Thanks again for your help, I will add some changes soon as well, make sure to pull the last version if you want to provide any pull request.
  • Adrian_PaechAdrian_Paech Customer Advanced IT Monkey ✭✭✭

    Thanks.

    I went to re-install CiresonPortalPS... Uninstall-Module CiresonPortalPS, Install-Module CiresonPortalPS, etc, but its still loading the old version? Any ideas..?

    Regards,

    Adrian

  • LazyWinAdminLazyWinAdmin Member IT Monkey ✭
    I published the last version on the PowerShell Gallery
    https://www.powershellgallery.com/packages/CiresonPortalPS/1.0.0.2
  • Adrian_PaechAdrian_Paech Customer Advanced IT Monkey ✭✭✭

    Just tested, all works find now! Thanks for that..

    Regards,

    Adrian

Sign In or Register to comment.