Click here to Skip to main content
15,883,749 members
Articles / Hosted Services / Azure
Tip/Trick

Azure Information Protection (AIP) Labelling in VBscript

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
1 Feb 2022CPOL2 min read 12.1K   1   2
How to set AIP label via VBScript code
This tip provides a solution to the problem of automatizing Excel file creation without Azure bugging the user to manually select the protection label.

Introduction

This article solves the problem of automatizing Excel file creation without Azure bugging the user to manually select the protection label. I have been struggling with this for quite some time now - I have a bunch of batch scripts which are producing CSV files and converting them into Excel files; but when my company started using Azure Information Protection (AIP), the scripts would pause before saving the Excel file requesting a manual input of a label.

I have been looking for this solution for quite some time. There are some workaround solutions on the Internet, including using a prelabelled Excel files, Powershell and dummy emails. The usage of prelabelled blank Excel files seemed like a plausible solution, but when the files got changed, Azure required entering a label again.

I found this in the official Microsoft documentation, but it is very scarce and you basically have to figure it out on your own.

The concrete solution shown is for Excel workbook, but it should be applicable also to any other Office document.

Using the Code

This is all the code you need after you have edited your objWorkbook (Excel.Workbook object) and are ready to save.

(Note #1: SensitivityLabel.SetLabel requires a context object, it can practically be anything if you are not using it, I chose dictionary).

(Note #2: You can add other properties to your LabelInfo, you can find it in the official Microsoft documentation here).

VBScript
Dim myLabelInfo, context

Set myLabelInfo = objWorkbook.SensitivityLabel.CreateLabelInfo()

Set context = CreateObject("Scripting.Dictionary")

With myLabelInfo

  .AssignmentMethod = 1

  .IsEnabled = True

  .LabelId = "--your labelID--"

  .LabelName = "--your label name--"

  .SetDate = Now()

End With

objWorkbook.SensitivityLabel.SetLabel myLabelInfo, context

Naturally, you need to change --your labelID-- with the actual label ID, and --your label name-- with an actual label name.

You can find this out by asking your company's administrator (whoever set up Azure) - or you can check for your own by using Powershell cmdlets:

You first find an office file with a label that you need, let's say, for example that the file you found is C:\myFile.xlsx; this is how you will find the label info for that file in Powershell:

PowerShell
Get-AIPFileStatus "C:\myFile.xlsx"

If you want to set a label using PS cmdlet, you can try this:

PowerShell
Set-AIPFileLabel -Path "C:\myFile.xlsx" -LabelId "--your labelID--"

History

  • 1st February, 2022: Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
User Interface Analyst Raiffeisenbank Austria
Croatia Croatia
I acquired Masters degree in computing science at the Faculty of Electrical Engineering and Computing in Zagreb, Croatia in 2009. Following my studies, I got a job in a Croatian branch of Austrian-based CEE Raiffeisen Bank as an MIS (Management information system) analyst.
I have been working there since 2010, as an IT expert within the Controlling department, maintaining the Oracle's OFSA system, underlying interfaces and databases.
Throughout that time, I have worked with several different technologies, which include SQL & PL/SQL (mostly), postgres, Cognos BI, Apparo, Datastage, ODI, Jenkins, Qlik, ...
I am doing a lot of automation with scripting in batch / shell and VBscript (mostly) - data analysis and processing, automated DB imports and exports, Jenkins automation etc.
Privately, I was mostly doing Windows Forms and Console app tools in Visual Studio, C#.

Comments and Discussions

 
Questionoutlook email object Pin
Anh Doe13-Mar-23 18:59
Anh Doe13-Mar-23 18:59 
AnswerRe: outlook email object Pin
Marijan Nikic13-Mar-23 21:20
professionalMarijan Nikic13-Mar-23 21:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.