MID Server and connecting to PowerShell modules

alexheer
Kilo Contributor

Hi all, apologies if this is the wrong board.

 

The ServiceNow team in the business I have worked for have introduced a MID server which they wish to run PowerShell commands from. They have asked me to create a PowerShell script, but the script requires connecting to M365 services (in this case, connect-msolservice)

The team have come back to me to say that this does not work, presumably because the 'connect-msolservice' is going to prompt for credentials. 

I suspect I will need to store credentials that can be used to connect, somewhere on the MID Server. (I don't have access to the MID Server). Has anyone got round this and can offer some advice?

 

Thanks

 

Alex

3 REPLIES 3

Richard Hine
Tera Guru
Tera Guru

Alex,

 

My understanding is that connect-msolservice is to connect to Azure Active Directory, depending on what you are attempting to do, would it be possible to achieve your outcomes with direct API calls to Azure from SN?

 

Perhaps you could expand on what you are trying to do in Azure as other might have already solve the issue...

 

Thanks,

 

Richard 

Hi Richard,

 

Firstly, thank you for your response.
I personally do not perform any administration on ServiceNow and my role here is that I have just been asked to help provide PowerShell scripts to grab some information from AzureAD. The team are looking to get the Last Password Change Date from AzureAD so they can use that information in ServiceNow.

I am happy to explore your suggestion of direct API calls further!

 

Thanks,

 

Alex

Based on the docs on connect-MsolServ

 

Connect-MsolService [-Credential <PSCredential>]

 

All you would need is to either put the credentials directly into the script, or have ServiceNow to pass the credentials as a parameter to your script.

ice it should be possible to supply the credential as well:

The credential object required can be generated without prompting the user like this:

$User = "Domain01\User01"
$PWord = ConvertTo-SecureString -String "P@sSwOrd" -AsPlainText -Force
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord

 

Found here:

Get-Credential (Microsoft.PowerShell.Security) - PowerShell | Microsoft Learn