[GE]导入图片至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 "tcsgegdc\814072", $pw
New-PSDrive -Name P -PSProvider FileSystem -Root "\\3.242.165.18\c$\screenshot" -Credential $Creds
Get-ChildItem -Path P:\ | Move-Item -Destination $target -Force
Remove-PSDrive -Name P
#文件名命名规则
$datetime = (Get-Date).Tostring("yyyyMMdd")
$lastday = ((Get-Date 0).AddYears((Get-Date).Year - 1).AddMonths((Get-Date).Month).AddDays(-1)).Day
switch($null) {
    {(Get-Date).Day -eq $lastday} {$filename = "Monthly backup " + $datetime}
    {(Get-Date).DayOfWeek -ne "Friday" -or "Saturday" -or "Sunday" -and (Get-Date).Day -ne $lastday} {$filename = "Daily backup " + $datetime}
    {(Get-Date).DayOfWeek -eq "Friday" -and (Get-Date).Day -ne $lastday} {$filename = "Weekly backup " + $datetime}
}
#将图片导入Word并且保存到硬盘
$objWord = New-Object -ComObject Word.Application
$objWord.Visible = $false
$objDoc = $objWord.Documents.Add()
$objSelection = $objWord.Selection
$objShape = $objDoc.Shapes.AddPicture("e:\screenshot\$filename.JPEG")
$objDoc.SaveAs([ref]"e:\screenshot\$filename",[ref]16)
$objword.Quit()
#删除所有JPG文件
#Get-ChildItem -path *.JPEG | Remove-Item

 

你可能感兴趣的:(word)