SOLVED

Azure Automation: issues connecting to security and compliance center in remote session

%3CLINGO-SUB%20id%3D%22lingo-sub-1248307%22%20slang%3D%22en-US%22%3EAzure%20Automation%3A%20issues%20connecting%20to%20security%20and%20compliance%20center%20in%20remote%20session%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1248307%22%20slang%3D%22en-US%22%3E%3CP%3EI'm%20at%20a%20loss%20here.%20I'm%20trying%20to%20use%20a%20Azure%20Automation%20PowerShell%20runbook%20to%20connect%20to%20the%20Security%20and%20Compliance%20Center.%20Specifically%20I%20am%20looking%20to%20use%20the%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Fexchange%2Fpolicy-and-compliance-retention%2Fget-retentioncompliancepolicy%3Fview%3Dexchange-ps%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3E%3CSTRONG%3EGet-RetentionCompliancePolicy%3C%2FSTRONG%3E%3C%2FA%3E%20and%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Fexchange%2Fpolicy-and-compliance-retention%2Fset-retentioncompliancepolicy%3Fview%3Dexchange-ps%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3E%3CSTRONG%3ESet-RetentionCompliancePolicy%3C%2FSTRONG%3E%3C%2FA%3E%20commands.%3C%2FP%3E%3CDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EI've%20tried%20a%20number%20of%20different%20modules%20to%20attempt%20to%20connect%20but%20none%20seem%20to%20work.%20I%20have%20code%20that%20works%20locally%2C%20but%20when%20put%20into%20a%20runbook%20and%20load%20the%20same%20module%20there%2C%20it%20won't%20connect%20properly.%20Instead%20it%20redirects%20and%20seems%20to%20loop%20on%20the%20connect%20and%20import%20step.%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EWhen%20I%20finally%20got%20it%20to%20appear%20to%20connect%20and%20import%20once%20(not%20loop)%2C%20it%20does%20not%20recognize%20the%20%3CSTRONG%3EGet-RetentionCompliancePolicy%3C%2FSTRONG%3E%26nbsp%3Bcommand%20and%20I%20can't%20find%20it%20in%20a%20Get-Commands%20call.%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EAny%20tips%20on%20how%20to%20get%20this%20to%20work%3F%20below%20is%20the%20code%20I'm%20using%20to%20connect%20and%20import.%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-javascript%22%3E%3CCODE%3E%24cred%20%3D%20Get-AutomationPSCredential%20-Name%20%22Admin%22%0A%24Session%20%3D%20New-PSSession%20-ConfigurationName%20Microsoft.Exchange%20-ConnectionUri%20https%3A%2F%2Fps.compliance.protection.outlook.com%2Fpowershell-liveid%2F%20-Credential%20%24cred%20-Authentication%20Basic%20-AllowRedirection%0AImport-PSSession%20%24Session%20-DisableNameChecking%20-AllowClobber%20%7C%20Out-Null%0A%0AGet-RetentionCompliancePolicy%0A%0AGet-PSSession%20%7C%20Remove-PSSession%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1248307%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20Automation%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ERemote%20Session%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESecurity%20%26amp%3B%20Compliance%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1273135%22%20slang%3D%22en-US%22%3ERe%3A%20Azure%20Automation%3A%20issues%20connecting%20to%20security%20and%20compliance%20center%20in%20remote%20session%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1273135%22%20slang%3D%22en-US%22%3E%3CP%3EIt%20turned%20out%20to%20be%20a%20permission%20issue%20on%20my%20service%20account.%20I%20had%20it%20setup%20as%20a%20Security%20Center%20Admin%20but%20apparently%20that%20is%20not%20enough%20for%20this%20to%20work.%20After%20giving%20the%20account%20more%20capabilities%20under%20the%20Security%20and%20Compliance%20center%20it%20started%20working.%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22thinkhaven_0-1586386355519.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F183218i7B55067F7FC7590C%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22thinkhaven_0-1586386355519.png%22%20alt%3D%22thinkhaven_0-1586386355519.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EI%20have%20not%20tested%20exactly%20what%20minimum%20permissions%20is%20required%20but%20when%20I%20checked%20all%20these%20it%20started%20working.%20Previously%20I%20only%20had%20Security%20admin%20checked.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20lesson%20here%20is%20don't%20assume%20Security%20Admin%20role%20means%20they%20can%20do%20everything%20in%20the%20Security%20and%20Compliance%20center.%20Seems%20backwards%20but%20there%20you%20have%20it.%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

I'm at a loss here. I'm trying to use a Azure Automation PowerShell runbook to connect to the Security and Compliance Center. Specifically I am looking to use the Get-RetentionCompliancePolicy and Set-RetentionCompliancePolicy commands.

 
I've tried a number of different modules to attempt to connect but none seem to work. I have code that works locally, but when put into a runbook and load the same module there, it won't connect properly. Instead it redirects and seems to loop on the connect and import step.
 
When I finally got it to appear to connect and import once (not loop), it does not recognize the Get-RetentionCompliancePolicy command and I can't find it in a Get-Commands call.

Any tips on how to get this to work? below is the code I'm using to connect and import.

 

 

 

$cred = Get-AutomationPSCredential -Name "Admin"
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.compliance.protection.outlook.com/powershell-liveid/ -Credential $cred -Authentication Basic -AllowRedirection
Import-PSSession $Session -DisableNameChecking -AllowClobber | Out-Null

Get-RetentionCompliancePolicy

Get-PSSession | Remove-PSSession

 

 

 

1 Reply
best response confirmed by thinkhaven (New Contributor)
Solution

It turned out to be a permission issue on my service account. I had it setup as a Security Center Admin but apparently that is not enough for this to work. After giving the account more capabilities under the Security and Compliance center it started working.

thinkhaven_0-1586386355519.png

I have not tested exactly what minimum permissions is required but when I checked all these it started working. Previously I only had Security admin checked.

 

So lesson here is don't assume Security Admin role means they can do everything in the Security and Compliance center. Seems backwards but there you have it.