Using powershell to create a word doc, but cant put focus outside of table

Welcome Forums General PowerShell Q&A Using powershell to create a word doc, but cant put focus outside of table

Viewing 0 reply threads
  • Author
    Posts
    • #248515
      Participant
      Topics: 52
      Replies: 86
      Points: 25
      Rank: Member

      I’m using powershell to create a word report to show some AD information. I have it presenting a table and putting information into it which works fine…but I’m unsure how to put focus AFTER the table…so when I do $selection.typeparagraph() it just creates a new line in the table…how do I put focus outside the table after it is created/populated?

      $word = New-Object -ComObject word.application<br />$word.visible = $true<br />$doc = $word.documents.add()<br />$selection = $word.selection</p><p>$90DaysAgo = (get-date).AddDays(-90)</p><p>$90StaleUsers = ($adusers | ? {$_.PasswordLastSet -le $90DaysAgo -and $_.enabled -eq $true}).samaccountname | Sort-Object</p><p>#total rows<br />$RowCount = $90staleusers.count / 3<br />$i = 1 #count row<br />$C = 1 #count column<br />$Table = $selection.Tables.Add(<br />$selection.range,($RowCount),3<br />)<br />foreach($90user in $90staleusers)<br />{<br />if($i -le $rowcount)<br />{<br />$table.cell($i,$c).range.text = $90user<br />$table.cell($i,$c).range.listformat.applybulletdefault()<br />$i++<br />}<br />else<br />{<br />$table.cell($i,$c).range.text = $90user<br />$table.cell($i,$c).range.listformat.applybulletdefault()<br />$i=1<br />$c++<br />}<br />}</p><p>#here the table is populated correctly, but i want to exit it and put focus BACK to the document after the table...but it just populates more crap to the table...</p><p>$Selection.TypeParagraph()
      Any help would be greatly appreciated

      • This topic was modified 1 month, 2 weeks ago by grokkit.
Viewing 0 reply threads
  • You must be logged in to reply to this topic.