Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

3. Scripting with the MCAS module

javanite edited this page Dec 18, 2018 · 1 revision

To have a script that runs against MCAS automatically, such as in a scheduled task, you will need to store a valid credential in a .credential file to make it available when the script executes.

Step 1 - Export a Credential to a File

To do that, you must first get a credential into a session, as described on the Getting Started page, using:

Get-MCASCredential

Once you have entered your tenant URI and API token into the credential prompt, it will be stored in the variable:

$CASCredential

The next step is to export that credential to a file, like this:

$CASCredential | Export-CliXml C:\Scripts\My.credential

Step 2 - Using the Stored Credential in a Script

Now, that credential can be used in scripts (or other Powershell sessions) by including the following line:

$CASCredential = Import-CliXml C:\Scripts\My.credential

IMPORTANT NOTE!!!

The credential file is storing the API token as a secure string that is encrypted using keying material that is only available in the key store of the machine on which it was generated, so it will only work on the machine on which it was created. Therefore, if you plan to run the script as a scheduled task on SERVER1, then the first step of getting a credential and exporting it to a file must also be done on SERVER1.

Clone this wiki locally