[APAC]导入图片至Word,然后按规则命名(2/2)

#将所有docx文件改成可读
Set-ItemProperty -Path "e:screenshot*.docx" -Name IsReadOnly -Value $false
#从远端服务器剪切截图至本地
$target = "e:screenshot"
$pw = ConvertTo-SecureString '密码' -AsPlainText -Force
$Creds = New-Object -Typename System.Management.Automation.PSCredential -Argumentlist "apac814072", $pw
New-PSDrive -Name P -PSProvider FileSystem -Root "\10.103.22.39c$ScreenShot" -Credential $Creds
Get-ChildItem -Path P: | Move-Item -Destination $target -Force
Remove-PSDrive -Name P
#文件名命名规则
$filename = (Get-Date).Tostring("yyyyMMdd")
#创建一个空的word文档,供Add-OSCPicture使用
$objWord = New-Object -ComObject Word.Application
$objWord.Visible = $false
$objDoc = $objWord.Documents.Add()
$objSelection = $objWord.Selection
$objDoc.SaveAs([ref]"e:screenshot$filename",[ref]16)
$objword.Quit()
#调用外部函数Add-OSCPicture,将多张图片依次导入word
Add-OSCPicture -WordDocumentPath "e:screenshot$filename.docx" -ImageFolderPath "e:screenshot"
#删除所有JPG文件
#Get-ChildItem -path *.JPEG | Remove-Item
原文地址:https://www.cnblogs.com/IvanChen/p/4500775.html