Last active
November 26, 2020 11:56
-
-
Save achmel/b21203c83394769e44d7526871127145 to your computer and use it in GitHub Desktop.
Powershell script that fetches a custom property field from Microsoft Excel document.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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