Hi.
I am moving from DocTag to Azure Information Protection. I found some script as a reference for reading Word document custom attributes. I was able to edit the scritpt to read the relevant attribute and based on its value set the correct AIP label. It works fine, it reads the attribute correctly and then set AIP attribute and refresh visual marking. But even though for every document I get this error
The RPC server is unavailable. (Exception from HRESULT: 0x800706BA) At C:\script\DocTag2AIP.ps1:11 char:13+ foreach($property in $customProperties) {+ ~~~~~~~~~+ CategoryInfo : OperationStopped: (:) [], COMException+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
The script looks like this
$files = @(Get-ChildItem C:\Users\luberan\Desktop\*.docx -Recurse) foreach ($file in $files) { $fileName = $file.Name $filePath = $file.DirectoryName $directory = $filePath + "\" + $fileName $word = New-Object -comobject Word.Application $document = $word.documents.open($directory) $binding = "System.Reflection.BindingFlags" -as [type] $customProperties = $document.CustomDocumentProperties foreach($property in $customProperties) { $vl = [System.__ComObject].InvokeMember("value",$binding::GetProperty,$null,$property,$null) if ($vl -eq "PU - For Personal Usage") { $word.Application.Quit() Set-AIPFileLabel -Path $directory -LabelId id1 -PreserveFileDetails $word = New-Object -comobject Word.Application $document = $word.documents.open($directory) $document.Save() } elseif ($vl -eq "C1") { $word.Application.Quit() Set-AIPFileLabel -Path $directory -LabelId id2 -PreserveFileDetails $word = New-Object -comobject Word.Application $document = $word.documents.open($directory) $document.Save() } elseif ($vl -eq "C2") { $word.Application.Quit() Set-AIPFileLabel -Path $directory -LabelId id3 -PreserveFileDetails $word = New-Object -comobject Word.Application $document = $word.documents.open($directory) $document.Save() } elseif ($vl -eq "C3") { $word.Application.Quit() Set-AIPFileLabel -Path $directory -LabelId id4 -PreserveFileDetails $word = New-Object -comobject Word.Application $document = $word.documents.open($directory) $document.Save() } elseif ($vl -eq "C4") { $word.Application.Quit() Set-AIPFileLabel -Path $directory -LabelId id5 -PreserveFileDetails $word = New-Object -comobject Word.Application $document = $word.documents.open($directory) $document.Save() } } $word.Application.Quit() }
The provided script is exact copy of the real script, I just replaced AIP label IDs by id1 - id5.
How to fix the issue please? Or is the script completely wrong?