In this first follow-up blog post of the Tridion Docs webinar 'Automating tasks in SDL Tridion Docs using PowerShell', I will share a short summary of the 'How to get started with Microsoft PowerShell' part of the webinar, the resources and the script used during this webinar.

Summary

What is PowerShell

  • A task-based command-line shell and scripting language from Microsoft
  • Harnesses the power of the .NET Framework, providing rich objects and a massive set of built-in functionality for taking control of your environments and applications

Cmdlets

A cmdlet (pronounced "command-let"):

  • is a lightweight PowerShell script that performs a single function,
  • is expressed as a Verb-(Prefix)Noun pair (e.g. Get-Help, Get-AdUser),
  • has a .ps1 extension.   

PowerShell modules and packages

  • A collection of cmdlets can be grouped and made available over a versioned  module/package.
  • These modules can be managed as packages using e.g. PowerShellGet (a package manager for Windows PowerShell)
  • The packages can be made available on a public repository (e.g. https://powershellgallery.com) or a private repository (e.g. Nexus).

Installing PowerShell

Using PowerShell

  • Most of the time needs to be run as Administrator
  • PowerShell ISE (Integrated Scripting Environment)
    Run commands and write, test, and debug scripts in a single Windows-based graphic user interface with multi-line editing, tab completion, syntax coloring, selective execution, context-sensitive help, ...
  • Execution (Security) Policy
    The execution policies let you determine the conditions under which PowerShell scripts are run (and configuration files are loaded)

Online resources

Webinar script

Inside the script, you will also find some comments and additional links to specific online resources.

#
# 0. PowerShell?
#
#    (*) https://docs.microsoft.com/en-us/powershell/scripting/powershell-scripting
 
#
# 1. Installing PowerShell (version 5.1)
#    PowerShell 5.1 comes with Windows 10/Windows Server 2016 out-of-the-box.
#    Needs to be installed/upgraded on other Operating
#        (*) https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell?view=powershell-6#upgrading-existing-windows-powershell
 
$PSVersionTable # $ -> variable
 

#
# 2. PowerShell/PowerShell ISE (Integrated Scripting Environment)
#    .ps1
#    Intellisense/tab-completion/...
#    Command Add-on
#    Breakpoints

Write-
 

#
# 3. Execution (Security) Policy
#    (*) http://powershelltutorial.net/V3/Powershell-Security-Policy
#    (*) https://docs.microsoft.com/nl-be/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-6
 
Get-ExecutionPolicy -List
Get-ExecutionPolicy
 
Set-ExecutionPolicy -ExecutionPolicy Unrestricted
Set-Executionpolicy -Scope CurrentUser -ExecutionPolicy Unrestricted​

#
# 4. Verb-Noun Principle
#    The Philosophy Verb-Noun - (*) https://sid-500.com/2017/12/28/powershell-for-beginners-part-2-the-philosophy-verb-noun/
#    Approved Verbs for Windows PowerShell Commands - (*)https://msdn.microsoft.com/en-us/library/ms714428(v=vs.85).aspx
#    Cmdlets Use Verb-Noun Names to Reduce Command Memorization
 
Start-Process # Start-Process notepad.exe
 
Get-Process   # Get-Process -Name notepad
 
Stop-Process  # Stop-Process -Name notepad
 
#    You can list all commands that include a particular noun/verb with the -Noun/-Verb parameter for Get-Command
Get-Command -Noun Process
Get-Command -Verb Get
 
#    Simular for e.g. services...
Get-Command -Noun Service
Start-Service
Get-Service
Stop-Service
#...

#    Get-Help/-? command #Message to download/update help
#    Update-Help
Get-Help Write-Host # Write-Host -?
Get-Help Write-Host -Detailed
Get-Help Write-Host -ShowWindow
 

#
# 5. Parameters
#    Cmdlets Use Standard Parameters
#    It is a developer guidance/encouragement to standardize parameter names (not guaranteed).
#    Intellisense/tab-completion (parameters names and values)
#
Get-Process -Name explorer
Get-Service -Name dhcp
 
 
#
# 6. Piping
#     Combining commands into pipelines in the PowerShell
#     (*) https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_pipelines?view=powershell-6
Start-Process notepad.exe
Get-Process -Name notepad | Stop-Process
 
 
#
# 7. Package Management/Modules
#    Packages are served up by package providers, which are created from various sources.
#    By default, PowerShell comes with two package sources: nuget.org and PSGallery.
#    Public: E.g. PowerShell Gallery vs Private repositories
Get-PackageProvider -? #PowerShellGet # Get-Help Get-PackageProvider -ShowWindow
Get-PackageSource -?                  # Get-Help Get-PackageSource -ShowWindow

Get-PSRepository -?                   # Get-Help Get-PSRepository -ShowWindow
 
#    Installed modules
Get-Module -ListAvailable
Get-Module -ListAvailable -Name WindowsUpdate
Get-Module -ListAvailable -Name ISHRemote

# Available modules (from defined PSRepositories) -> Nuget provider !
Find-Module -Name "ISH*" #Find-Module -Name "ISHRemote" -Repository  PSGallery

Install-Module -Name ISHRemote -Repository PSGallery -Scope CurrentUser
# NuGet provider is required to continue
# PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based repositories.
Anonymous
  • John, please send me an email and I will get you the sources. I was still planning to clean it up a bit more and then to open source it, but if you want to get started now I can provide it to you as is. My email address fclosset@sdl.com

  • Great webinar! This generated a lot of excitement on our team for the huge potential efficiency gains.

    Toward the end, Frank's demo of the scripts that synchronized with Elastic Search and Kabana really got our wheels turning, and such an option would solve a lot of open issues for us. Are those scripts posted anywhere, or available to existing SDL customers? I realize they would require heavy modification for our own use, but having them for reference would be an excellent starting point for us.