none
Powershell script msoluser null at first execution RRS feed

  • General discussion

  • Hi All,

    I wrote a powershell script, which uses a menu and a function

    MENU

    function Show-Menu{
    param ([string]$Title = 'My Menu')
    clear-host
    write-host "========================$Title======================"
    write-host "1: Press '0' to show this menu."
    write-host "1: Press '1' for Removing User from a shared Mailbox Access."
    write-host "2: Press '2' for Converting a user's mailbox to a shared mailbox."
    write-host "3: Press '3' to list all users"
    write-host "4: Press '4' to list all the mailboxes"
    write-host "Q: Press 'Q' to quit."
    }
    Show-Menu -Title 'My Menu'
    do 
    {
    Show-Menu
    $selection = Read-Host "Please make a selection"
    switch ($selection) {
    '0' {Show-Menu}
    '1' {UserShareMailBoxRemove}
    '2' {ConvertToSharedMailbox}
    '3' {ListUsers}
    '4' {getMailboxes}
    }
    pause
    }
    until ($selection -eq 'q')

    FUNCTIONS

    #ListUsers
    function ListUsers {
    get-msoluser
    }
    #getMailboxes
    function getMailboxes{
    get-mailbox
    }

    RESULTS

    When the user press "3" to list all users which triggers the function "get-msoluser" (-trace 1 have been enabled)

    DEBUG:   36+  >>>> write-host "========================$Title======================"
    ========================My Menu======================
    DEBUG:   37+  >>>> write-host "1: Press '0' to show this menu."
    1: Press '0' to show this menu.
    DEBUG:   38+  >>>> write-host "1: Press '1' for Removing User from a shared Mailbox Access."
    1: Press '1' for Removing User from a shared Mailbox Access.
    DEBUG:   39+  >>>> write-host "2: Press '2' for Converting a user's mailbox to a shared mailbox."
    2: Press '2' for Converting a user's mailbox to a shared mailbox.
    DEBUG:   40+  >>>> write-host "3: Press '3' to List all the users"
    3: Press '3' to List all the users
    DEBUG:   41+  >>>> write-host "4: Press '4' to get a list of mailboxes"
    4: Press '4' to get a list of mailboxes
    DEBUG:   42+  >>>> write-host "Q: Press 'Q' to quit."
    Q: Press 'Q' to quit.
    DEBUG:   43+  >>>> }
    DEBUG:   48+  >>>> $selection = Read-Host "Please make a selection"
    Please make a selection: 3
    DEBUG:   49+ switch ( >>>> $selection) {
    DEBUG:   50+  >>>> '0' {Show-Menu}
    DEBUG:   51+  >>>> '1' {UserShareMailBoxRemove}
    DEBUG:   52+  >>>> '2' {ConvertToSharedMailbox}
    DEBUG:   53+  >>>> '3' {ListUsers}
    DEBUG:   53+ '3' { >>>> ListUsers}
    DEBUG:   25+ function ListUsers  >>>> {
    DEBUG:   26+  >>>> get-msoluser
    
    DEBUG:   27+  >>>> }
    DEBUG:   54+  >>>> '4' {getMailboxes}
    DEBUG:   49+ switch ( >>>> $selection) {
    DEBUG:   56+  >>>> pause
    DEBUG:    1+  >>>> $null = Read-Host 'Press Enter to continue...'
    Press Enter to continue...:
    

    Pressing '3' the 2nd time:

    DEBUG:   36+  >>>> write-host "========================$Title======================"
    ========================My Menu======================
    DEBUG:   37+  >>>> write-host "1: Press '0' to show this menu."
    1: Press '0' to show this menu.
    DEBUG:   38+  >>>> write-host "1: Press '1' for Removing User from a shared Mailbox Access."
    1: Press '1' for Removing User from a shared Mailbox Access.
    DEBUG:   39+  >>>> write-host "2: Press '2' for Converting a user's mailbox to a shared mailbox."
    2: Press '2' for Converting a user's mailbox to a shared mailbox.
    DEBUG:   40+  >>>> write-host "3: Press '3' to List all the users"
    3: Press '3' to List all the users
    DEBUG:   41+  >>>> write-host "4: Press '4' to get a list of mailboxes"
    4: Press '4' to get a list of mailboxes
    DEBUG:   42+  >>>> write-host "Q: Press 'Q' to quit."
    Q: Press 'Q' to quit.
    DEBUG:   43+  >>>> }
    DEBUG:   48+  >>>> $selection = Read-Host "Please make a selection"
    Please make a selection: 3
    DEBUG:   49+ switch ( >>>> $selection) {
    DEBUG:   50+  >>>> '0' {Show-Menu}
    DEBUG:   51+  >>>> '1' {UserShareMailBoxRemove}
    DEBUG:   52+  >>>> '2' {ConvertToSharedMailbox}
    DEBUG:   53+  >>>> '3' {ListUsers}
    DEBUG:   53+ '3' { >>>> ListUsers}
    DEBUG:   25+ function ListUsers  >>>> {
    DEBUG:   26+  >>>> get-msoluser
    UserPrincipalName                                          DisplayName                                           isLice
                                                                                                                     nsed
    -----------------                                          -----------                                           ------
    DEBUG:   27+  >>>> }
    DEBUG:   54+  >>>> '4' {getMailboxes}
    DEBUG:   49+ switch ( >>>> $selection) {
    DEBUG:   56+  >>>> pause
    DEBUG:    1+  >>>> $null = Read-Host 'Press Enter to continue...'

    Question:

    I want to know is this normal? or am I missing something?

    Thanks

    David


    david.lay7@tafensw.net.au netadminstrator@hotmail.com

    • Changed type Bill_Stewart Wednesday, February 14, 2018 7:37 PM
    • Moved by Bill_Stewart Wednesday, February 14, 2018 7:37 PM Unanswerable drive-by question
    Friday, January 5, 2018 1:27 AM

All replies

  • You want to know if what is normal?

    -- Bill Stewart [Bill_Stewart]

    Friday, January 5, 2018 3:50 PM
  • You want to know if what is normal?

    -- Bill Stewart [Bill_Stewart]

     Yes, I want to know is it normal that "get-msoluser", when triggered by a function call, it will execute as null, then when you re-call the function again, it provides the necessary contents.

    As shown in the traces.

    First call:

    DEBUG:   53+ '3' { >>>> ListUsers}
    DEBUG:   25+ function ListUsers  >>>> {
    DEBUG:   26+  >>>> get-msoluser
    
    DEBUG:   27+  >>>> }

    Second call:

    DEBUG:   53+ '3' { >>>> ListUsers}
    DEBUG:   25+ function ListUsers  >>>> {
    DEBUG:   26+  >>>> get-msoluser
    UserPrincipalName                                          DisplayName                                           isLice
                                                                                                                     nsed
    -----------------                                          -----------                                           ------
    DEBUG:   27+  >>>> }

     So technically, I would have to run the menu twice, or at least I would need to press "3" twice to get the data from msoluser, hence is this a normal appearance, or am I writing it wrong?

    I can share the scripts if need :D

    Thanks


    david.lay7@tafensw.net.au netadminstrator@hotmail.com




    • Edited by Synice Saturday, January 6, 2018 3:19 AM Removed html tags via Edge. {IE is broken, nothing is clickable.}
    Saturday, January 6, 2018 2:01 AM
  • Please fix your post.  It is unreadable.  You cannot paste THML into this forum as it will not be readable.

    \_(ツ)_/

    Saturday, January 6, 2018 2:46 AM
  • Please fix your post.  It is unreadable.  You cannot paste THML into this forum as it will not be readable.

    \_(ツ)_/

     I tried to remove the <g> its keeps appearing on msoluser.

    Please advise a fix.


    David Lay |netadminstrator@hotmail.com | david.lay90@gmail.com |

    Saturday, January 6, 2018 3:10 AM
  • Perhaps you need to use a different browser or just delete and retype the parts that are broken.  It is unreadable.  Maybe just delete the whole post and start again.

    Use IE or Edge to post.  Don't cut and paste from a non-textonly editor like notepad.


    \_(ツ)_/

    Saturday, January 6, 2018 3:13 AM
  • Perhaps you need to use a different browser or just delete and retype the parts that are broken.  It is unreadable.  Maybe just delete the whole post and start again.

    Use IE or Edge to post.  Don't cut and paste from a non-textonly editor like notepad.


    \_(ツ)_/

     Looks like you are right, seems like Edge is the only browser that can edit this. IE was broken, those edit links are not-clickable.. seems like its Edge for TechNet Forum only...since Chrome may throw those <g> </g>

    Its now formatted properly.

    Thanks


    David Lay |netadminstrator@hotmail.com | david.lay90@gmail.com |

    Saturday, January 6, 2018 3:21 AM
  • Clear IE cache to prevent this.

    Chrome and Firefox also are susceptible to this kind of corruption.  Edge less but it can also become corrupted.

    The issue is that certain types of malware that attempts to stela browser data seems to also inject HTML into edit blocks on TechNet.  MSDN doesn't seem to have this issue.

    There are also issues with this web site.  Certain sequences corrupt the CSS rendering which appears to be caused by some bad JavaScript code on the TechNet sites.


    \_(ツ)_/

    Saturday, January 6, 2018 3:30 AM
  •  Back to my problem post.

    David Lay |netadminstrator@hotmail.com | david.lay90@gmail.com |

    Saturday, January 6, 2018 5:02 AM