word
  1. Open Topics …
  2. => System.Object[] [System.Management.Automation.PSCustomObject[]]

Set-StrictMode -Version "Latest"

[Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Interop.Word") | Out-Null

$Local:PDFDoc_FullName = Join-Path -Path ([System.Environment]::GetFolderPath("Desktop")) -ChildPath "PVWAWebSDK_ModuleCommands.pdf"

if ( (Test-Path -Path $PDFDoc_FullName -PathType Leaf) ) { return ('The document "{0}" already exists' -f $PDFDoc_FullName) }

$objWord = New-Object -comobject Word.Application
$objWord.Visible = $true
$objWord.WindowState = $wdWindowStateMinimize
$objDoc = $objWord.Documents.Add()
$objSelection = $objWord.Selection

  1. Loading Word constants to PSVariables

$Local:MSWord_ConstantEnumerationsToLoad_List = @("WdBorderType", "WdLineStyle", "WdLineWidth", "WdBreakType", "WdSaveOptions", "WdCalendarType", "WdColor", "WdCountry", "WdLanguageID", "WdParagraphAlignment", "WdSaveFormat", "WdSeekView", "WdUnits", "WdWindowState")
foreach ($Current_ConstantEnumerator in @($MSWord_ConstantEnumerationsToLoad_List | Sort-Object -Unique)) {
[System.Enum]::GetNames("Microsoft.Office.Interop.Word.$Current_ConstantEnumerator") | ForEach-Object { Set-Variable -Name $_ -Value (([System.Type]("Microsoft.Office.Interop.Word.$Current_ConstantEnumerator"))::($_)) -Scope Local -Force }
}

$Local:CyberArk_Fuctions_List = New-Object -TypeName System.Collections.Queue
Get-CyberArkCommands | ForEach-Object { Get-Command $_.Name } | Sort-Object -Property "Noun", "Verb" -Descending | ForEach-Object { $CyberArk_Fuctions_List.Enqueue( ($_.Name) ) }

  1. Get-DiBaCommands | ForEach-Object { Get-Command $_.Name } | Sort-Object -Property "Noun", "Verb" -Descending | ForEach-Object { $CyberArk_Fuctions_List.Enqueue( ($_.Name) ) }

while ( ($CyberArk_Fuctions_List.Count) ) {
$Local:Current_Function_Name = $CyberArk_Fuctions_List.Dequeue()

$Local:Current_Function_HelpOut_FullName = (Join-Path ($env:temp) -ChildPath (("{0}.txt" -f $Current_Function_Name)))
Get-Help $Current_Function_Name -Full | Out-File -PSPath $Current_Function_HelpOut_FullName -Force

$Local:Current_Function_HelpOut_Content = ((((Get-Content $Current_Function_HelpOut_FullName -Raw).Trim()) -replace " \r\n \r\n \r\n \r\n") -replace " \r\n \r\n \r\n", (" {0}" -f ([System.Environment]::NewLine)))

$objSelection.Font.Name = "Courier New"
$objSelection.Font.Size = 8
$objSelection.Font.Bold = $false

$objSelection.ParagraphFormat.SpaceBefore = 0
$objSelection.ParagraphFormat.SpaceBeforeAuto = $false
$objSelection.ParagraphFormat.SpaceAfter = 0
$objSelection.ParagraphFormat.SpaceAfterAuto = $false

$objSelection.TypeParagraph()
[void]$objSelection.MoveUp($wdLine, 1)

$objSelection.Font.Name = "Calibri"
$objSelection.Font.Size = 18
$objSelection.Font.Bold = $true
$objSelection.ParagraphFormat.Alignment = $wdAlignParagraphCenter

$Local:Current_BorderTop = $objSelection.ParagraphFormat.Borders.Item($wdBorderTop)
$Current_BorderTop.LineStyle = $wdLineStyleDouble
$Current_BorderTop.LineWidth = $wdLineWidth150pt
$Current_BorderTop.Color = $wdColorAutomatic

$Local:Current_BorderBottom = $objSelection.ParagraphFormat.Borders.Item($wdBorderBottom)
$Current_BorderBottom.LineStyle = $wdLineStyleDouble
$Current_BorderBottom.LineWidth = $wdLineWidth150pt
$Current_BorderBottom.Color = $wdColorAutomatic

$objSelection.ParagraphFormat.Borders.DistanceFromTop = 4
$objSelection.ParagraphFormat.Borders.DistanceFromLeft = 4
$objSelection.ParagraphFormat.Borders.DistanceFromBottom = 4
$objSelection.ParagraphFormat.Borders.DistanceFromRight = 4
$objSelection.ParagraphFormat.Borders.Shadow = $false

$objSelection.TypeText($Current_Function_Name)

[void]$objSelection.EndKey($wdStory)
$objSelection.TypeParagraph()
$objSelection.TypeParagraph()
$objSelection.TypeParagraph()
$objSelection.TypeParagraph()

$objSelection.TypeText($Current_Function_HelpOut_Content)

if ( ($CyberArk_Fuctions_List.Count) ) { $objSelection.InsertBreak($wdPageBreak) }

Remove-Item -Path $Current_Function_HelpOut_FullName -Force

}

  1. activate Footer

$objWord.ActiveWindow.ActivePane.View.SeekView = $wdSeekPrimaryFooter
$objSelection = $objWord.Selection
$objSelection.Font.Name = "Calibri"
$objSelection.Font.Size = 4
$objSelection.Font.Bold = $false
$objSelection.ParagraphFormat.Alignment = $wdAlignParagraphRight

  1. $objSelection.InsertDateTime("yyyy-MM-dd", $false, $false, $wdGerman, $wdCalendarWestern)

$objSelection.InsertDateTime("yyyy-MM-ddTHH:mm:ss", $false, $false, $wdGerman, $wdCalendarWestern)

  1. activate MainDocument

$objWord.ActiveWindow.ActivePane.View.SeekView = $wdSeekMainDocument

Start-Sleep -Seconds 2

  1. Save and leave

$objDoc.SaveAs2([ref][system.object]$PDFDoc_FullName, [ref]$wdFormatPDF)
$objDoc.Close([ref]$wdDoNotSaveChanges)
$objWord.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($objWord) | Out-Null
[System.GC]::Collect()
[System.GC]::WaitForPendingFinalizers()
Remove-Variable "objWord" -Force

return ("The documant has been safed under: {0}" -f $PDFDoc_FullName)

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License