I modified the script so that I could feed it a CSV file for multiple properties--it works great! (THANK YOU!)
Modified Script:
#Set the PATH variable to the location where you saved the script and CSV file $path = "c:\temp\PowerShell Scripts\" #Set the DOC variable to the location of the document you want to update $doc = "c:\temp\test.docx" $application = New-Object -ComObject word.application $application.Visible = $false $document = $application.documents.open($doc) $binding = "System.Reflection.BindingFlags" -as [type] $customProperties = $document.CustomDocumentProperties $typeCustomProperties = $customProperties.GetType() $CustomPropertiesWorklist = Import-Csv $path\args.csv if($CustomPropertiesWorklist.Count){ for($i = 0; $i -lt $CustomPropertiesWorklist.Count; $i++) { $CustomProperty = $CustomPropertiesWorklist[$i].CP $msoPropertyType = $CustomPropertiesWorklist[$i].Type $Value = $CustomPropertiesWorklist[$i].Value [array]$arrayArgs = $CustomProperty,$false,$msoPropertyType,$Value Try { $typeCustomProperties.InvokeMember(` "add", $binding::InvokeMethod,$null,$customProperties,$arrayArgs) | out-null } Catch [system.exception] { $propertyObject = $typeCustomProperties.InvokeMember(` "Item", $binding::GetProperty,$null,$customProperties,$CustomProperty) $typeCustomProperties.InvokeMember(` "Delete", $binding::InvokeMethod,$null,$propertyObject,$null) $typeCustomProperties.InvokeMember(` "add", $binding::InvokeMethod,$null,$customProperties,$arrayArgs) | Out-Null } } } else { $CustomProperty = $CustomPropertiesWorklist.CP $msoPropertyType = $CustomPropertiesWorklist.Type $Value = $CustomPropertiesWorklist.Value [array]$arrayArgs = $CustomProperty,$false,$msoPropertyType,$Value Try { $typeCustomProperties.InvokeMember(` "add", $binding::InvokeMethod,$null,$customProperties,$arrayArgs) | out-null } Catch [system.exception] { $propertyObject = $typeCustomProperties.InvokeMember(` "Item", $binding::GetProperty,$null,$customProperties,$CustomProperty) $typeCustomProperties.InvokeMember(` "Delete", $binding::InvokeMethod,$null,$propertyObject,$null) $typeCustomProperties.InvokeMember(` "add", $binding::InvokeMethod,$null,$customProperties,$arrayArgs) | Out-Null } } $document.Saved = $false $document.save() $application.quit() $application = $null [gc]::collect() [gc]::WaitForPendingFinalizers()What I need now, however, is a way to REMOVE custom properties from a Word document (preferably using the same script).
Any ideas?