Parameter validation

Validating parameters in a Powershell function

Parameter validation In this article we will talk about an option available in Powershell: the validation of parameters The purpose of this option is, as the name suggests, to validate that a parameter passed to a function is indeed the one we expect. Throughout this article we will keep the following script as a guideline. function Do-SomeThing { [CmdletBinding()] param ( [String[]]$ComputerName, [Int]$Age ) begin { #The value of computername must not be null or empty if (($null -eq $ComputerName) -or ($ComputerName -eq "")) { throw "ComputerName cannot be empty or null" } #Test to verify that the computer name does not exceed 13 characters If ($ComputerName. [Read More]

Word: cutting a Word file

Cut a file and save it in several documents

Cut a Word file into several PDFs… Initial Request The initial request which led me to reflect on this subject came from a colleague. My colleague receives a large Word document from his ERP containing on each page a letter for a different recipient. In order to be able to integrate it into EDM (Electronic Document Management) he had the following needs: Cut the large file into several files (1 page = 1 file) Retrieve data from documents to name the PDF Save new documents in PDF Not knowing much about manipulating Word via PowerShell, I cut my thinking, as usual, into small steps. [Read More]