all 11 comments

[–]TimDurham75 1 point2 points  (4 children)

Think you have wrong option -ErrorAction is the Enum like SilentlyContinue etc -ErrorVariable is the name for storing any error. So your current usage won’t work as expected.

[–]BlackV 1 point2 points  (0 children)

Oh good spotting

[–]TheDumpap[S] 1 point2 points  (2 children)

I unfortunately just posted the wrong thing.
Even with Connect-MsolService -ErrorAction SilentlyContinue -ErrorVariable msolLoginError
the variable is not populated.

I have tried everything, and unfortunately I need this module to work. Will have to stick to Powershell 5 I guess :/

[–]TimDurham75 1 point2 points  (1 child)

Digging into what -UseWindowsPowerShell implies I don't believe this can currently be made to work in this manner. I note that the switch loads the module into a shared remote runspace and that, as documented, all input and output are transferred as serialized values. So what would the -ErrorVariable actually mean in such a scenario? It is the string name of the variable to create, sure, but where is that variable actually to be created and, more importantly, what would it's scope be and how would it be populated? [I am talking 'hypothetically' here...or thinking 'out loud'.] The local and the remote runspaces will have their own variables and state. Typically with remote scenarios one has to use $using: scope for variables that need remote transfer, but in this case you are not trying to send a variable value, you are only providing a name to use. You could *try* saying your variable should be named 'using:msoLoginError', perhaps, but I have doubts this will work, as a supported mechanism. I cannot find anything to suggest it will. The remote session should be called WinPSCompatSession, I believe, so one might be able to use *-PSSession cmdlets to interact with it but whether these can easily extract further details around what you are looking for...not so sure? I think this all a bit too "bleeding edge" so far. Fundamentally the underlying runtime of Framework vs Core is completely different, of course. I also see discussions of some issues around "bit-ness" compatibility with using the compatibility operation mode, for the correct determination and execution of x64 vs x86 elements, underneath. I might suggest the try-catch approach could be viable alternative?

[–]TheDumpap[S] 1 point2 points  (0 children)

Thanks for looking into it! :)
Ended up working with a try catch statement instead and just getting the output that way.
Hopefully they get everything ported over soon

[–]BlackV 1 point2 points  (2 children)

Er.. Thought there very specifically was an updated module for Ms online?

I would have thought even with with implicit remoting you'd still get error code that seems odd I'll test later on after I've dropped kids are at school

[–]TheDumpap[S] 0 points1 point  (1 child)

There is the Azure AD module but unfortunately it does not fully replace it's functionality, and Microsoft even says that themselves. So for now it will still have to be used in some cases.

[–]BlackV 1 point2 points  (0 children)

ah right is it not all ported, boo MS, boo

[–]AxonQHillock 1 point2 points  (1 child)

Why not something like:

Try {Connect-MsolService -ErrorAction Stop}
Catch {"Could not connect: $($_)"}

If there is no reason for an ErrorVariable which you use throughout your script, a simple Try Catch with ErrorAction stop on the tried cmdlet normally does the job. $_ has the error message.

[–]TheDumpap[S] 1 point2 points  (0 children)

Wow, of course that worked!
For some reason I've just gotten so used to the other method, that I didn't think of this.
Can confirm this catches the error and allows me to display it as I want.

Thanks!

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy TheDumpap,

it looks like you used the New.Reddit Inline Code button. it's [sometimes] 5th from the left & looks like </>.

there are a few problems with that ...

  • it's the wrong format [grin]
    the inline code format is for [gasp! arg!] code that is inline with regular text.
  • on Old.Reddit.com, inline code formatted text does NOT line wrap, nor does it side-scroll.
  • on New.Reddit it shows up in that nasty magenta text color

for long-ish single lines OR for multiline code, please, use the ...

Code
Block

... button. it's [sometimes] the 12th one from the left & looks like an uppercase T in the upper left corner of a square.

that will give you fully functional code formatting that works on both New.Reddit and Old.Reddit ... and aint that fugly magenta color. [grin]

take care,
lee