For one of the MVP retreat projects I had a chance to revisit PowerShell and Peter Kjaer PowerShell CoreService module.
PowerShell Tips for Newbies
I heard PowerShell had some features and conventions but I found the following tips and reminders helped get reacquainted with the command-line shell and scripting language.
Help
You can use the help function (or get-help cmdlet) to learn more about a cmdlet (prounounced "command-let").
> Help {cmdlet name}
Tips
PowerShell cmdlets follow a {verb}-{noun} naming convention and prefers singular nouns over plural.
Like other developer software command-line interfaces, PowerShell supports auto-complete. After typing part of a command use Tab and Ctrl+Space to automatically choose a matching command or function.
Other useful tips:
- Confirm your version of PowerShell using:
> Get-host - Run PowerShell as an administrator in order to change the execution policy (which prevents scripts downloaded from the internet by default):
> Set-ExecutionPolicy RemoteSigned - Learn more about a module:
> Get-Command -Module {Module Name} - Powershell supports automatic outputting to formats such as table or .csv. Use the "pipe" ("|") command.
Quickly Get Started with the Tridion-CoreService PowerShell Module
I got started in a few minutes by doing the following, starting at: https://github.com/pkjaer/tridion-powershell-modules.
- Start PowerShell as an administrator.
- Update execution policy to allow remote signed scripts:
> Set-ExecutionPolicy RemoteSigned - Confirm version number (3 or higher needed):
> Get-host - Install the Tridion PowerShell CoreService module:
iwr "https://raw.githubusercontent.com/pkjaer/tridion-powershell-modules/master/CoreService/Installation/Install.ps1" | iex - To try the develop branch you can instead use:
> iwr "https://raw.githubusercontent.com/pkjaer/tridion-powershell-modules/develop/CoreService/Installation/Install.ps1" | iex - Set up the Tridion Core Service client (adjust accordingly):
> Set-TridionCoreServiceSettings -HostName xxx.xxx.x.xxx -Version Web-8.5 -Credential machinename\username -Persist
xxx.xxx.x.xxx is the IP address of the CMS (no http:\\) - Learn about available cmdlets:
> Get-Command -Module Tridion-CoreService
Use Cases
After getting set up, I worked with the rest of the PowerShell CoreService Module team which included Peter Kjaer, Chris Morgan, Mark Saunders, Hem Kant, and Pankaj Guar.
We needed requirements. I shared authorization documentation as a familiar use case common to consulting and business analysis.
Authorization
I've previously created the BA Toolkit to automatically output a Tridion's authorization model and settings including groups, rights, organizational structure, and permissions. The challenge with my original .NET Console app was I needed a 3rd-party library to handle .CSV output as well as Visual Studio and I wasn't on projects as a technical consultant.
See example output as an Excel Spreadsheet (https://community.rws.com/cfs-file/__key/communityserver-blogs-components-weblogfiles/00-00-00-00-95/Test.csv).
This was input into Pankaj's BluePrinting Rights example script. If you're interested, you might explore other scenarios such as schemas, publishing, and ad-hoc reporting.
Schemas
In my later projects as a Functional Consultant, I would ask the developers to confirm or automate the results. For example I've used Stanislav Kroshchenko's Schema Documenter from the 2011/2013 PowerTools. There's a newer GUI extension to document schemas on the Alchemy Webstore.
Though you could query the CMS for some useful stats for an upgrade, a PowerShell script is a bit more portable across software versions. You can also contribute new examples and cmdlets.
Publishing and Ad-hoc Reporting
You can also check Tridion Stack Exchange to see request like how to check and export publishing queue entries. Previously I asked the community on Tridion Meta StackExchange for example reports you've seen in implementations and the community provided plenty of useful examples.
Restrictions
We discussed the feeling that for production environments, although the CoreService enforces the same authorization model as the Content Manager Explorer or Experience Manager, running scripts might need to be part of a development release process. If anything, it might be okay to run read-only scripts against a Production CMS, but after they've been tested or vetted in lower environments such as development.
It’s probably more flexible to use PowerShell for DEV and QA where consultants or developers have more freedom to change, script, or automate changes in the CMS on-the-fly.
To be clear, you just need authorization and proper CoreService client settings (and the CoreService Module) to use PowerShell to interact with a Content Manager. PowerShell does not need to run on the CM environment directly.
Summary
In this post, I covered some basic PowerShell tips and steps you can use to explore Peter's Tridion CoreService module. I described one of the main use cases we worked on at the 2017 MVP retreat but showed there are plenty of other scenarios you can easily find in the community. If I could rewind back to when I created my BA Toolkit, I would have preferred a lightweight approach with PowerShell instead.
As a consultant or developer authorized to use a Content Manager, I might need to do quick or repetitive actions that I'd prefer to automate. With limited access to an IDE, I prefer a command line interface in order to guickly get information out or changes into the CMS.
That command line interface is the Tridion CoreService (PowerShell) module.