Skip to content

Instantly share code, notes, and snippets.

@achmel
Last active November 26, 2020 11:56
Show Gist options
  • Save achmel/b21203c83394769e44d7526871127145 to your computer and use it in GitHub Desktop.
Save achmel/b21203c83394769e44d7526871127145 to your computer and use it in GitHub Desktop.
Powershell script that fetches a custom property field from Microsoft Excel document.
$tmpPath = "C:\tmp\"
# $searchPath = "H:\Desktop"
$searchPath = (Get-Location).Path
$files = Get-ChildItem $searchPath -Recurse -Include *.xlsx
foreach ($f in $files){
$filename = $f.FullName
$guid = [guid]::NewGuid().Guid
$tempname = $tmpPath + $guid + ".zip"
$destinationUnarchivedPath = $tmpPath + $guid
$docProps = $destinationUnarchivedPath + "\docProps\custom.xml"
if (Test-Path $filename) {
Copy-Item $filename $tempname -force
Expand-Archive $tempname -DestinationPath $destinationUnarchivedPath
Remove-Item $tempname -Force
if (Test-Path $docProps) {
$xml = [xml](Get-Content $docProps)
$documentId = $xml.Properties.property | Where {$_.name -eq "documentId"}
$response = $documentId.r8
Write-Output $response
}
Remove-Item $destinationUnarchivedPath -Recurse -Force -Confirm:$false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment