Connectingto Msol

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 4 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
Reddrgn2
Posts: 49
Last visit: Wed Nov 08, 2023 10:34 am
Answers: 1

Connectingto Msol

Post by Reddrgn2 »

Product, version and build:
64 bit PrimalScript 2019
Operating system:
64 bit OS: Win 10

Question - Why when building a script and testing does it tell me to connect to msolservice? Example below

Script
  1. $username=Read-Host "Email Address"
  2. $role=Read-Host "Role to Add"
  3. Add-MsolRoleMember -RoleName $role -RoleMemberEmailAddress $username
Running script - have already connected to msol, azure, sharepoint, AD (part of script ran when first signing into pc)
When I run the script (ctrl+f5) it pops up diag box, for the username to add and the role to add. Great that part works
Now when I check to confirm user added, user not there.
Looking at the output diag box i see:
"ERROR: Add-MsolRoleMember : The term 'Add-MsolRoleMember' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling
ERROR: of the name, or if a path was included, verify that the path is correct and try again


I have tried a few other things thinking I lost connection some how, but I didn't I can still do other things with Msol.
Still same issue when trying to run it from looking at the script (kind of in edit mode)
From the File Browser if I right click on script and "run in shell" it works, no popups but in console able to enter name and role. Then when checking I see that the new user is added to that role.

Anything I am missing or not really doing correctly? I should not have to add the connect-msolservice to this script to run it every time.
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: Connectingto Msol

Post by Alexander Riedel »

You probably have dependencies on settings in your profile. When you run it in a shell your profile gets executed. If you run it from PrimalScript it doesn't.
That is intentionally so you discover dependencies like this which will work fine in a shell on your machine but not necessarily elsewhere.
Likewise, once you package a script as an executable, it is executed stand-alone, so you cannot rely on setting that are made in a profile.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
Reddrgn2
Posts: 49
Last visit: Wed Nov 08, 2023 10:34 am
Answers: 1

Re: Connecting to Msol

Post by Reddrgn2 »

Is that something I can change?

Thinking I am not sure if I want to, in the long run. I can see how I will forget both ways.
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: Connectingto Msol

Post by Alexander Riedel »

I am not sure I understand what you are asking.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
Reddrgn2
Posts: 49
Last visit: Wed Nov 08, 2023 10:34 am
Answers: 1

Re: Connectingto Msol

Post by Reddrgn2 »

Is there a way for me to be editing the script, run the script, (for me its hitting cntrl +f5 or clicking run script) without need to add in the part to connect to msolservice each time? I ask cause when testing I am already connected to msol.

I can see how it is a good way to catch minor oversights or help with creating scripts from start to finish. And when building for a lot of people to use I defiantly see the perk.

Question is can I change a setting to stop if from making me need to use connect-msolservice when testing script?
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: Connectingto Msol

Post by Alexander Riedel »

Hit Ctrl+F8. That will run it in the integrated console, which also uses your profile.
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 4 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.