pdf - Using newer PowerShell code on an old PowerShell version -


i apologize ahead of time first post, sure make few mistakes. anyway, writing code retrieve list of computer file, users , groups each computer, each computer have 2 files saved users , groups 1 .txt , 1 .pdf. script works great on windows 10 computer wrote code on. when go virtual servers test out, have problems pdf part of code. have 2 windows 2008-r2 , 2 2012-r2 virtual machines. can not run part of code , grateful situation. chunk of code pdf.

< #make pdf  # required word variables $wdexportformatpdf = 17 $wddonotsavechanges = 0  # create hidden word window $word = new-object -comobject word.application $word.visible = $false  # add word document $doc = $word.documents.add()  # put text word document $txt = get-content $txtpath $selection = $word.selection foreach($line in $txt){ $selection.typetext($line) | format-wide $selection.typeparagraph() } # export pdf file , close without saving word document $doc.exportasfixedformat($pdfpath,$wdexportformatpdf)  if($?){write-host 'users , groups saved ' $pdfpath -foregroundcolor cyan} $doc.close([ref]$wddonotsavechanges) $word.quit() } > 

these lines of code above came errors.

< #new-object : retrieving com class factory component clsid{00000000-0000-0000-0000-000000000000} failed due following error:80040154 class not registered (exception hresult: 0x80040154(regdb_e_classnotreg)). new-object -comobject word.application    #the property 'visible' cannot found on object. verify property exists , can set. $word.visible = $false  #you cannot call method on null-valued expression. $doc = $word.documents.add()   #you cannot call method on null-valued expression. $selection.typetext($line) | format-wide   #you cannot call method on null-valued expression. $selection.typeparagraph()  #you cannot call method on null-valued expression. $doc.exportasfixedformat($pdfpath,$wdexportformatpdf)  #you cannot call method on null-valued expression. $doc.close([ref]$wddonotsavechanges)  #you cannot call method on null-valued expression. $word.quit() > 

i don't see powershell version-specific in code. if edit error question. can think of on servers don't have microsoft word installed; need instantiate com object.


Comments