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.
What is PowerShell
A cmdlet (pronounced "command-let"):
PowerShell modules and packages
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)
# Command Add-on
# 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
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
top-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
# Get-Help/-? command #Message to download/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
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 -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 '18.104.22.168' or newer to interact with NuGet-based repositories.
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 email@example.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.