New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New cmdlets for working with subscriptions #79

Merged
merged 13 commits into from Oct 18, 2017

Conversation

Projects
None yet
3 participants
@markwragg
Contributor

markwragg commented Oct 4, 2017

Changes proposed in this pull request:

  • Add a cmdlet New-RsSubscription for creating new subscriptions via PowerShell
  • Add a cmdlet New-RsScheduleXML for creating the XML string definition of a schedule needed to work with New-RsSubscription -Schedule parameter
  • Add a cmdlet Export-RsSubscription for exporting subscriptions to XML via Export-CliXML. This function isn't strictly needed but its there to compliment Import-RsSubscription and make explicit how Subscriptions need to be stored (e.g in XML as generated by Export-CliXML).
  • Add a cmdlet Import-RsSubscription for importing subscriptions that have exported to disk as XML and recreating their .ExtensionSettings property so that it is a valid object for use with the existing Set-RsSubscription cmdlet.

4th October 2017 Changes:

  • Modified Set-RsSubscription so that it recreates the DeliverySettings property for Subscription objects that have been deserialized (e.g if you have Export/Imported them via Import-CliXML).

5th October 2017 Changes:

  • Modified Get-RsSubscription to support the 2005 SOAP webservice API via a parameter so that you can retrieve subscriptions from old versions of SSRS.
  • Modified New-RsWebServiceProxy and Connect-RsReportServer to support the -ApiVersion switch and settings so that the old webservice URL can be queried when needed.
  • Have added Pester tests for each new function.
  • Have amended the Readme.md regarding new functions, as well as added Get-RsSubscription and Set-RsSubscription to Readme.md as these were missing.

10th October 2017 Changes:

  • This commit addresses all of the comments made on the PR by parthsha.
  • This commit reintroduces the Import and Export cmdlets as Import-RsSubscriptionXml and Export-RsSubscriptionXml. Decided these were needed to enforce -Depth 3 on export and to move the recreation of the deserialized objects out of the Set-RsSubscription cmdlet so as to not convolute it.
  • Reintroduces pester tests for Import- and Export-RsSubscription
  • Fixes a bug in Get-RsSubscription where $item was being set in a If statement instead of tested (line 81)
  • Changes Get-RsSubscription so that it can retrieve data driven subscriptions.
  • Changes Set-RsSubscription so that it can create data driven subscriptions.

How to test this code:

  • Run the relevant Pester tests
  • Manually create a new subscription via New-RsSubscription -Path /some/path -Description 'This is a test' -Destination FileShare -DestinationPath '\\some\path' -Filename 'Somefile' -Schedule (New-RsScheduleXML) -RenderFormat PDF
  • Export subscriptions via: Get-RsSubscription | Export-RsSubscriptions .\sub.xml
  • Import subscriptions and add to SRSS via Import-RsSubscription .\sub.xml | Set-RsSubscription -Path /some/path

Has been tested on (remove any that don't apply):

  • Powershell 5.1
  • Windows Server 2016
  • SQL Server 2016
  • SRSS Version 13.0.4435.0

markwragg added some commits Oct 3, 2017

New subscription functions
Added the following functions for working with subscriptions:
- New-RsSubscription -- Use to create new subscriptions by specifying settings through parameters
- New-RsScheduleXML -- Use to create the XML string needed to define the schedule for New-RsSubscription -Schedule parameter
- Export-RsSubscription -- Use to export subscriptions retrieved via Get-RsSubscription to an XML file (essentially just a wrapper to Export-CliXML which can be used directly)
- Import-RsSubscription -- Use to read saved subscriptions from an XML file and rebuilds the ExtensionSettings properties so that Set-RsSubscription can be used to load them in to a server.

Also amended the module manifest to include the new functions.
Improvements
- Improved the way ParameterValues is built as an array, removed some duplication in the code and the need for $i as a counter. Note can't use += to extend the array without ScriptAnalyzer complaining about unused variables.
- Throw error if DocumentLibrary is used as destination as its not yet supported. Don't have a Sharepoint integrated SRSS system to test this with.
- Improved the way $ExtensionSettings was built, 1 line vs 3.
Fix to Export-RsSubscription
- Due to the pipeline unrolling the collection it was only exporting a single subscription when there were multiple. Fixed this by collating them first in a process block.
Pester test for New-RsSubscription
- Added Pester test for New-RSSubscription, initially just based on the existing one for Set-RsSubscription.
- Added copyright notice to each new file.
Amended readme.md
- Added details of new functions that are part of this PR to Readme.md
- Also noticed Get-RsSubscription and Set-RsSubscription were missing from Readme.md so added those also.
Tests for New-RsScheduleXML
- Pester tests for the New-RsScheduleXML cmdlet.
Pester tests for Import and Export
- Added Pester tests for Import-RsSubscription and Export-RsSubscription
@msftclas

This comment has been minimized.

Show comment
Hide comment
@msftclas

msftclas Oct 4, 2017

CLA assistant check
All CLA requirements met.

msftclas commented Oct 4, 2017

CLA assistant check
All CLA requirements met.

@markwragg

This comment has been minimized.

Show comment
Hide comment
@markwragg

markwragg Oct 4, 2017

Contributor

I discussed these new functions with @ClaudioESSilva on Twitter and he suggested that the Import- Export- functions could just be worked in to the existing functions. Thinking about if I put the fix that the Import- cmdlet performs in to the Set-RsSubscription cmdlet then the Import- and Export- cmdlets can just be replaced with Import/Export-CliXML. I'm going to have a go at doing that.

Contributor

markwragg commented Oct 4, 2017

I discussed these new functions with @ClaudioESSilva on Twitter and he suggested that the Import- Export- functions could just be worked in to the existing functions. Thinking about if I put the fix that the Import- cmdlet performs in to the Set-RsSubscription cmdlet then the Import- and Export- cmdlets can just be replaced with Import/Export-CliXML. I'm going to have a go at doing that.

Fix to Set-RsSubscription
- Added a fix to Set-RsSubscription so that it would handle deserialized objects. As such you can now use Export-CliXML and Import-CliXML in place of the Import/Export-RsSubscription cmdlets I added earlier.
- Removed Import/Export-RsSubscription, their Pester tests and references to them in Readme.md.
@markwragg

This comment has been minimized.

Show comment
Hide comment
@markwragg

markwragg Oct 4, 2017

Contributor

I have now done as noted in the previous comment, I've amended the Set-RsSubscription cmdlet so that it recreates the .DeliverySettings property for a Deserialized object and removed the Import/Export-RsSubscription cmdlets that I added (as well as their Pester tests and references to them in Readme.md). I've also added a test to Set-RsSubscription.Tests.ps1 to show that it can create a subscription that has been saved and loaded from disk via Export/Import-CliXML.

As a result you should now be able to:

Get-RsSubscription -Path /some/path | Export-CliXML .\somefile.xml
Import-CliXML .\somefile.xml | Set-RsSubscription -Path /some/path

Successfully.

This PR of course still contains the the new New-RsSubscription cmdlet which I think will be useful to anyone looking to create subscriptions from scratch directly with PowerShell.

Contributor

markwragg commented Oct 4, 2017

I have now done as noted in the previous comment, I've amended the Set-RsSubscription cmdlet so that it recreates the .DeliverySettings property for a Deserialized object and removed the Import/Export-RsSubscription cmdlets that I added (as well as their Pester tests and references to them in Readme.md). I've also added a test to Set-RsSubscription.Tests.ps1 to show that it can create a subscription that has been saved and loaded from disk via Export/Import-CliXML.

As a result you should now be able to:

Get-RsSubscription -Path /some/path | Export-CliXML .\somefile.xml
Import-CliXML .\somefile.xml | Set-RsSubscription -Path /some/path

Successfully.

This PR of course still contains the the new New-RsSubscription cmdlet which I think will be useful to anyone looking to create subscriptions from scratch directly with PowerShell.

markwragg added some commits Oct 5, 2017

Added backwards compatibility for Get-RsSubscriptions
- Modified Get-RsSubscription so that you can query the 2005 Report Service SOAP API and retrieve subscriptions.
- As a result of the above, modified Connect-RsReportServer and New-RsWebService proxy to support a -ApiVersion switch with '2010' (the original value) as the default.
- Also have made a minor change to the way Set-RsSubscription validates whether the subscription object is valid, dependent on whether there is a value for a .ExtensionSettings property. This stops errors occurring if you have retrieved subscriptions that currently have invalid/missing DeliverySettings which seemingly can happen if certain delivery options have been decommed from the server (e.g SharePoint integration).
Update to module manifest
- Removed the two cmdlets that I had originally added but later retracted.
@parthsha

Thank you very much for taking the time to make the changes for this PR. Most of my comments are around style than functionality.

Show outdated Hide outdated ReportingServicesTools/Functions/CatalogItems/Get-RsSubscription.ps1
Show outdated Hide outdated ReportingServicesTools/Functions/Common/ConnectionObjectRequests.ps1
Show outdated Hide outdated ReportingServicesTools/Functions/CatalogItems/Get-RsSubscription.ps1
Show outdated Hide outdated ReportingServicesTools/Functions/Utilities/Connect-RsReportServer.ps1
Show outdated Hide outdated ReportingServicesTools/Functions/Utilities/New-RsWebServiceProxy.ps1
Show outdated Hide outdated ReportingServicesTools/Functions/Utilities/Connect-RsReportServer.ps1
Show outdated Hide outdated ReportingServicesTools/Functions/CatalogItems/New-RsScheduleXML.ps1
Show outdated Hide outdated ReportingServicesTools/Functions/CatalogItems/New-RsScheduleXML.ps1
.PARAMETER Path
Specify the path to the destination report.
.PARAMETER ReportServerUri

This comment has been minimized.

@parthsha

parthsha Oct 8, 2017

Member

For consistency sake, I recommend you to add ApiVersion parameter to this cmdlet also.

@parthsha

parthsha Oct 8, 2017

Member

For consistency sake, I recommend you to add ApiVersion parameter to this cmdlet also.

This comment has been minimized.

@markwragg

markwragg Oct 10, 2017

Contributor

Not sure it yet supports the older APIs for creating subscriptions so am going to leave this for now.

@markwragg

markwragg Oct 10, 2017

Contributor

Not sure it yet supports the older APIs for creating subscriptions so am going to leave this for now.

@@ -90,6 +90,7 @@ function Set-RsSubscription
Begin

This comment has been minimized.

@parthsha

parthsha Oct 8, 2017

Member

For consistency sake, I would recommend you to add ApiVersion to this cmdlet also.

@parthsha

parthsha Oct 8, 2017

Member

For consistency sake, I would recommend you to add ApiVersion to this cmdlet also.

This comment has been minimized.

@markwragg

markwragg Oct 10, 2017

Contributor

Not sure it yet supports the older APIs for creating subscriptions so am going to leave this for now.

@markwragg

markwragg Oct 10, 2017

Contributor

Not sure it yet supports the older APIs for creating subscriptions so am going to leave this for now.

markwragg added some commits Oct 10, 2017

Improvements
- This commit addresses all of the comments made on the PR by parthsha.
- This commit reintroduces the Import and Export cmdlets as Import-RsSubscriptionXml and Export-RsSubscriptionXml. Decided these were needed to enforce -Depth 3 on export and to move the recreation of the deserialized objects out of the Set-RsSubscription cmdlet so as to not convolute it.
- Reintroduces pester tests for Import- and Export-RsSubscription
- Fixes a bug in Get-RsSubscription where $item was being set in a If statement instead of tested (line 81)
- Changes Get-RsSubscription so that it can retrieve data driven subscriptions.
- Changes Set-RsSubscription so that it can create data driven subscriptions.
Pester Test Fixes
- Expected .Values property was missing in the mock subscription object.
- Set-RsSubscription from disk test was not using the Import-RsSubscription cmdlet to handle the deserialized objects (previously this wasn't necessary as the code was directly in the Set- cmdlet).
Style changes
- Minor style changes to better confirm to the style guide.

@parthsha parthsha merged commit 4b4d9f4 into Microsoft:master Oct 18, 2017

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
license/cla All CLA requirements met.
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment