Advertisement
opexxx

Get-TSWordXMetadata.ps1

Jul 16th, 2014
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Get-TSWordXMetadata {
  2.   <#
  3.    
  4.     .SYNOPSIS
  5.     Displays Metadata Information from a WordX file.
  6.  
  7.     .DESCRIPTION
  8.     The Get-TSWordXMetadata CmdLet displays Metadata from a WordX file using the Word.Application Com Object.
  9.  
  10.     .EXAMPLE
  11.     dir C:\foo -Filter *.docx | Get-TSWordXMetadata
  12.  
  13.     .LINK
  14.     http://www.truesec.com
  15.  
  16.     .NOTES
  17.     Goude 2012, TreuSec
  18.   #>
  19.   param(
  20.     [parameter(Mandatory = $true,
  21.       ValueFromPipeLine = $true,
  22.       ValueFromPipeLineByPropertyName = $true)]
  23.     [Alias("Fullname")]
  24.     [string]$Path
  25.   )
  26.   Process {
  27.     $referenceObject = Get-Process
  28.     $Word = New-Object -comobject Word.Application
  29.     $Word.Visible = $False
  30.     $OpenDoc = $Word.Documents.Open($path)
  31.     $docX = [xml]$OpenDoc.WordOpenXML
  32.     $coreXML = $docX.package.part | Where { $_.name -eq "/docProps/core.xml" }
  33.     $properties = $coreXML.xmlData.coreProperties
  34.  
  35.     New-Object PSObject -Property @{
  36.       Subject = $(if($properties.subject) { $properties.subject } else { $null });
  37.       Creator = $(if($properties.creator) { $properties.creator } else { $null });
  38.       LastModifiedBy = $(if($properties.lastModifiedBy) { $properties.lastModifiedBy } else { $null });
  39.       Revision = $(if($properties.revision) { $properties.revision } else { $null });
  40.       Created = [datetime]$properties.created.'#text';
  41.       Modified = [datetime]$properties.modified.'#text';
  42.       Category = $(if($properties.category) { $properties.category } else { $null });
  43.       ContentStatus = $(if($properties.contentStatus) { $properties.contentStatus } else { $null })
  44.     }
  45.     $differenceObject = Get-Process
  46.     $compare = Compare-Object -Property ID -ReferenceObject $referenceObject -DifferenceObject $differenceObject
  47.  
  48.     $compare | Where-Object { $_.SideIndicator -eq "=>" } |
  49.      ForEach-Object {
  50.        $id = $_.ID
  51.        if(Get-Process | Where-Object { $_.ID -eq $id -AND $_.ProcessName -eq "WINWORD" }) {
  52.          Stop-Process -Id $id -Force
  53.        }
  54.      }
  55.   }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement