Page 1 of 1

Connectingto Msol

Posted: Mon Sep 23, 2019 11:01 am
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

  1. $username=Read-Host "Email Address"
  3. $role=Read-Host "Role to Add"
  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.

Re: Connectingto Msol

Posted: Mon Sep 23, 2019 12:26 pm
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.

Re: Connecting to Msol

Posted: Mon Sep 23, 2019 1:07 pm
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.

Re: Connectingto Msol

Posted: Mon Sep 23, 2019 1:30 pm
by Alexander Riedel
I am not sure I understand what you are asking.

Re: Connectingto Msol

Posted: Tue Sep 24, 2019 8:29 am
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?

Re: Connectingto Msol

Posted: Tue Sep 24, 2019 1:53 pm
by Alexander Riedel
Hit Ctrl+F8. That will run it in the integrated console, which also uses your profile.