functionConvert-WordDocument { param ( # accept path strings or items from Get-ChildItem [Parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName)] [string] [Alias('FullName')] $Path )
begin { # we are collecting all paths first [Collections.ArrayList]$collector = @() }
process { # find extension $extension = [System.IO.Path]::GetExtension($Path)
# we only process .doc and .dot files if ($extension-eq'.doc'-or$extension-eq'.dot') { # add to list for later processing $null = $collector.Add($Path)
} } end { # pipeline is done, now we can start converting!
# conversion cannot work for read-only docs If (!$doc.ActiveWindow.View.ReadingLayout) { if ($targetConversion-gt0) { $pathOut = [IO.Path]::ChangeExtension($Path, $targetExtension)