Result not showing up in powershell

Welcome Forums General PowerShell Q&A Result not showing up in powershell

Viewing 6 reply threads
  • Author
    Posts
    • #284050
      Ben
      Participant
      Topics: 4
      Replies: 12
      Points: 21
      Rank: Member

      Happy New Year All!

      Just a small issue that I haven’t got my head around why the get-mailboxfolderpermission command comes up blank when I run the script as a module after signing in to exchange online. But when I rename the module as a ps1 file the command shows the result instead of a blank line. I have copied a sample code as I think that maybe the issue, if not I will be happy to paste the entire code.

      Thanks

      Ben

      • This topic was modified 2 weeks, 1 day ago by kvprasoon. Reason: code formatting
    • #284053
      Participant
      Topics: 5
      Replies: 252
      Points: 998
      Helping Hand
      Rank: Major Contributor

      Can you explain what you mean by “run the script as a module”?

    • #284089
      Participant
      Topics: 6
      Replies: 14
      Points: 126
      Rank: Participant

      If all that you do is rename file extension from *.ps1 to *.psm1 then it will not work unless you also export function.

      Otherwise if you run function in combination with other functions that write output to same session you might not see the result because of a behavior of Format-Table which you apply to your function.

      To verify try removing Format-Table and try again, and if this resolves your problem consider using custom format.

       

      Otherwise according to docs:

      If the Output Type field is blank, the cmdlet doesn’t return data.

      Get-MailboxFolderPermission (ExchangePowerShell) | Microsoft Docs

       

      To see a list of exchange commandlets that do return data see:

      Exchange Management Shell cmdlet input and output types | Microsoft Docs

    • #284194
      Senior Moderator
      Topics: 9
      Replies: 1449
      Points: 5,428
      Helping Hand
      Rank: Community MVP

      Are these codes part of your module ? A module would have only functions which will be used by a calling script. Here it looks like the calling script. Can you share us more details on your module ?

    • #284236
      Ben
      Participant
      Topics: 4
      Replies: 12
      Points: 21
      Rank: Member

      Hello All

      many thanks for taking to time to reply, I just reread my original post and realised I wasn’t clear. So the script created is stored in the following location c:\windows\system32\windowspowershell\1.0\modules as a psm1 file.

      When I run the script within ISE the command get-mailboxfolderpermission works as it shows a result. If I call the script from a regular PowerShell window the command shows up blank though I am searching for the same user. I went back to ISE and reran the command get-mailboxfolderpermission on its own and it shows the result I need. I have tried removing the | FT -AutoSize and calling the script in a regular PowerShell window and I do not get a result. The command also does not show to the screen when I am adding the permission, setting, or removing the permission. Taking a copy of the psm1 and renaming it to ps1 and running the script within a regular Powershell window the command returns results I need.

      I have included the full script as a colleague I asked suspect it might be related to the loop and hope someone with more knowledge would be able to help.

      Many thanks

      Ben

      • This reply was modified 1 week, 6 days ago by kvprasoon. Reason: Code formating
    • #284251
      Participant
      Topics: 5
      Replies: 252
      Points: 998
      Helping Hand
      Rank: Major Contributor

      When you are running it in ISE, how specifically are you running it?  When you open a .psm1 file in ISE, it doesn’t NOT allow you to just press F5.  I’m assuming you are running portions of the code (F8) by highlighting them or all of them.  If that’s the case it is NOT the same thing as running the module in ISE.  You are basically just running lines of code not the module script.

      To use the functions in a script module a couple things need to happen.  1.  You need an Export-ModuleMember command at the bottom of your module that exposes the functions you want to have available.  2.  You need to import the module in the session you want use the functions in.

      Recommend reviewing: https://docs.microsoft.com/en-us/powershell/scripting/developer/module/how-to-write-a-powershell-script-module?view=powershell-5.1

    • #284665
      Ben
      Participant
      Topics: 4
      Replies: 12
      Points: 21
      Rank: Member

      Hi

      Just wanted to update that I managed to resolve this. I suspected it was how the exchange command was trying to return the result that the powershell console doesnt like so it comes up blank. I chose to use out-gridview and it works.

      Many thanks to all that took the time to post a reply.

      Ben

Viewing 6 reply threads
  • You must be logged in to reply to this topic.