SHARE
TWEET

Select Text From Word Doc

ShiftNick Jun 4th, 2015 926 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Path to new hire document
  2. $DocPath = 'C:\Temp\Onboarding.docx'
  3.  
  4. #Open Word document
  5. $SearchArray = @('1. First Name:','2. Last Name:','7. Job Title:','8. Manager/Supervisor','User Name:')
  6. $Word = New-Object -ComObject Word.Application
  7. $Document = $Word.Documents.Open($DocPath)
  8. $CSVInfo = $Document.Paragraphs | ForEach-Object {
  9.     foreach ($SearchText in $SearchArray) {
  10.         $_.Range.Text | Where-Object {$_ -match $SearchText} | ForEach-Object {
  11.             $_ -split ':' | Select-Object -Last 1
  12.         }
  13.     }
  14. }
  15.  
  16. #All contents of Word Doc with spaces removed
  17. $Trim = $CSVInfo.trim()
  18.  
  19. #New user information
  20. $Ufirstname = $Trim | select-object -Index 0
  21. $Ulastname = $Trim | select-object -Index 1
  22. $UDetailedName= $Ulastname + ", " + $Ufirstname
  23. $Usam = $Ufirstname.Substring(0,1) + $Ulastname
  24. $UPN = $Ufirstname + "." + $Ulastname + "@domain.com"
  25. $Password = "Password"
  26.  
  27. #Manger Name
  28. $mname = ($trim | Select-Object -Index 3).split(" ")
  29. $Mfirstname = $mname | select-object -Index 0
  30. $Mlastname = $mname | select-object -Index 1
  31. $Msam = $Mfirstname.Substring(0,1) + $Mlastname
  32.  
  33. #User to copy group membership from
  34. $cname = ($trim | Select-Object -Index 4).split(" ")
  35. $Cfirstname = $cname | select-object -Index 0
  36. $Clastname = $cname | select-object -Index 1
  37. $Csam = $Cfirstname.Substring(0,1) + $Clastname
  38. $ou = (get-aduser -Identity $Csam -Properties * | Select -ExpandProperty distinguishedname).split(",",3) | Select -Last 1
  39.  
  40. #Job Title
  41. $jtitle = $Trim | Select-Object -index 2
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top