I am trying to work with PowerShell and have it output the copyright character into a Microsoft Word document. For example, the code listed below is what I am trying to use and it is not working.
$SummaryPara.Range.Text = "© "
$SummaryPara.Range.Text = "Get-Date -Format yyyy"
$SummaryPara.Range.Text = " - Name of Org Here "
$SummaryPara.Range.InsertParagraphAfter()
Do I need to use the Alt + 0169 sequence somehow?
I am not sure what I am doing wrong since the following code seems to work:
$selection.TypeParagraph()
$selection.TypeText("© ")
$selection.TypeText((Get-Date -Format yyyy))
$selection.TypeText(" - Name of Org Here ")
$selection.TypeParagraph()
How can I make this work for both the copyright character and other similar special characters?
There are a few problems here. I’ll list those and address each:
You can get any character you need by casting the Unicode representation to a
char. In this caseYou assign a new value to
$SummaryPara.Range.Textthree times. So, you are overwriting the previous value each time, instead of concatenating (‘+’ operator), which I think is what you were trying to do.You are trying to use the cmdlet Get-Date, but since you have quoted it, you will end up with the literal string “Get-Date -Format yyyy”, instead of the result of the cmdlet.
Putting it all together, I think you want something like this: