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 SUBSCRIPTION NUMBERS, LICENSE 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.
User avatar
Reddrgn2
Posts: 17
Joined: Wed May 23, 2018 6:13 am

Connectingto Msol

Post by Reddrgn2 » Mon Sep 23, 2019 11:01 am

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.  
  3. $role=Read-Host "Role to Add"
  4.  
  5. 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: 7118
Joined: Tue May 29, 2007 4:43 pm

Re: Connectingto Msol

Post by Alexander Riedel » Mon Sep 23, 2019 12:26 pm

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: 17
Joined: Wed May 23, 2018 6:13 am

Re: Connecting to Msol

Post by Reddrgn2 » Mon Sep 23, 2019 1:07 pm

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: 7118
Joined: Tue May 29, 2007 4:43 pm

Re: Connectingto Msol

Post by Alexander Riedel » Mon Sep 23, 2019 1:30 pm

I am not sure I understand what you are asking.
Alexander Riedel
SAPIEN Technologies, Inc.

User avatar
Reddrgn2
Posts: 17
Joined: Wed May 23, 2018 6:13 am

Re: Connectingto Msol

Post by Reddrgn2 » Tue Sep 24, 2019 8:29 am

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: 7118
Joined: Tue May 29, 2007 4:43 pm

Re: Connectingto Msol

Post by Alexander Riedel » Tue Sep 24, 2019 1:53 pm

Hit Ctrl+F8. That will run it in the integrated console, which also uses your profile.
Alexander Riedel
SAPIEN Technologies, Inc.