【发布时间】:2020-12-13 07:24:56
【问题描述】:
我正在编写一个用于扫描文件以查找 SSN 的脚本。我已经完成了大部分工作,但这部分让我很伤心,我找不到任何有用的文档。
我遇到了跳过受密码保护的 PowerPoint 文件的问题。
#Scan for SSN in pptx
$findtext = "\b(?!0{3}|6{3})([0-6]\d{2}|7([0-6]\d|7[012]))([ -]?)(?!00)\d\d\3(?!0000)\d{4}\b"
$pptfiles = Get-Childitem -Path $searchpath -Include *.ppt, *.pptx -Recurse
# Create instance of the PowerPoint.Application COM object
$ppt = New-Object -ComObject PowerPoint.Application
# walk through the collection of slides
foreach ($pptfile in $pptfiles) {
$presentation = $ppt.Presentations.open($pptfile, [Microsoft.Office.Core.MsoTriState]::msoTrue,
[Microsoft.Office.Core.MsoTriState]::msoFalse, [Microsoft.Office.Core.MsoTriState]::msoFalse)
$slidecount = $presentation.Slides.Count
$slideCounter = 1
WHILE ($slideCounter -le $slideCount) {
$slide = $presentation.slides.item($slidecounter)
$title = $slide.Shapes[1].TextFrame.TextRange.Text
$body = $slide.Shapes[2].TextFrame.TextRange.Text
$arrcontents = @($title, $body)
ForEach ($line in $arrcontents) {
$pptline = $line.trim()
If ($pptline -match $findtext) {
$Violation = [PSCustomObject]@{
Path = $pptfile | Select-Object | Select-object -ExpandProperty fullname
Line = $pptline
LineNumber = "Slide $slideCounter"
}
$Violation | Select-Object Path, Line, LineNumber | export-csv $outputpath\$PIIFile -append -NoTypeInformation
}
}
$slideCounter++
}
# prevent the Save Presentation prompt from displaying
$presentation.saved = $true
# close presentation
$presentation.close()
} #end for
# release memory
$ppt.quit()
# release the memory immediately
$ppt = $null
$file = $null
Stop-Process -name POWERPNT
如果不打开文件,我无法自动检查是否有密码,这很矛盾,所以我的计划是在打开文件时使用 try-catch 语句(从当前代码中删除),并将密码传入. 问题是PowerPoint的参数与Word或Excel的参数不同,所以在第5个参数输入假密码不起作用。这个方法(下),好像也行不通。
Presentation presentation = ppApp.Presentations.Open($"{presentationFile}::{password1}::", MsoTriState.msoFalse, MsoTriState.msoFalse, WithWindow: MsoTriState.msoFalse);
任何帮助将不胜感激。提前致谢。
【问题讨论】:
标签: powershell passwords powerpoint comobject