Welcome › Forums › General PowerShell Q&A › Result not showing up in powershell
- This topic has 6 replies, 4 voices, and was last updated 1 week, 5 days ago by
Participant.
-
AuthorPosts
-
-
January 4, 2021 at 11:46 am #284050
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
PowerShell1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556function Skype-CallDelegate {param ([string]$Title = ‘Skype Menu’)clsWrite-host ” ”Write-Host “================ $Title ================”Write-Host “1: To sign into Exchange Online:Write-Host ” ”Write-Host “2: To check permissions”Write-Host “3: To add permissions”Write-Host “4: To fix permissions”Write-Host “5: To remove permissions”Write-host ” ”Write-Host “E: EXIT”}do{Skype-CallDelegateWrite-host ” ”Write-host ” ”$selection = Read-Host “Please make a selection”switch ($selection){‘1’ {Write-host ” ”Write-Host “————————————————————————————————”Write-Host “Sign in to Exchange Online to begin (ADMINXX)”Connect-ExchangeOnlineShell}‘2’ {Write-Host “————————————————————————————————”Write-Host “Check users permission”Write-host ” ”$accesswho = read-host -Prompt ‘Who do you need to check? firstname.surname’Write-host ” ”Write-Host “————————————————————————————————”Write-Host “Existing permissions for “$accesswho”‘s calendar are shown below.”Write-Host ” ”Get-MailboxFolderPermission -identity ${accesswho}:\calendar | ft -AutoSizeWrite-Host ” ”PAUSE}-
This topic was modified 2 weeks, 1 day ago by
kvprasoon. Reason: code formatting
-
This topic was modified 2 weeks, 1 day ago by
-
January 4, 2021 at 11:50 am #284053
Can you explain what you mean by “run the script as a module”?
-
January 4, 2021 at 1:20 pm #284089
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
-
January 5, 2021 at 12:40 am #284194
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 ?
-
January 5, 2021 at 6:15 am #284236
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
PowerShell123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130function Skype-CallDelegate {param ([string]$Title = ‘Skype Menu’)clsWrite-host ” ”Write-Host “================ $Title ================”Write-Host “1: To sign into Exchange OnlineWrite-Host ” ”Write-Host “2: To check permissions”Write-Host “3: To add permissions”Write-Host “4: To fix permissions”Write-Host “5: To remove permissions”Write-host ” ”Write-Host “E: EXIT”}do{Skype-CallDelegateWrite-host ” ”Write-host ” ”$selection = Read-Host “Please make a selection”switch ($selection){‘1’ {Write-host ” ”Write-Host “————————————————————————————————”Write-Host “Sign in to Exchange Online to begin (ADMINXX)”Connect-ExchangeOnlineShell}‘2’ {Write-Host “————————————————————————————————”Write-Host “Check users permission”Write-host ” ”$accesswho = read-host -Prompt ‘Who do you need to check? firstname.surname’Write-host ” ”Write-Host “————————————————————————————————”Write-Host “Existing permissions for “$accesswho”‘s calendar are shown below.”Write-Host ” ”Get-MailboxFolderPermission -identity ${accesswho}:\calendar | ft -AutoSizeWrite-Host ” ”PAUSE}‘3’ {Write-Host “————————————————————————————————”Write-Host “Add user permission”Write-host ” ”$accesswho = read-host -Prompt ‘Whos calendar do you need access to? firstname.surname’Write-host ” ”$accessfor = Read-Host -Prompt ‘Who is the delegate? firstname.surname’Write-host ” ”Write-Host “————————————————————————————————”Write-host ” ”Add-MailboxFolderPermission -identity ${accesswho}:\calendar -User $accessfor -Accessrights Editor -SharingPermissionFlags DelegateAdd-RecipientPermission -identity ${accesswho} -Trustee $accessfor -accessrights SendAs -Confirm:$falseWrite-Host “$accessfor now has delegate calendar access in Outlook and Skype for Business to create and edit meetings on behalf of $accesswho”Write-Host ” ”Get-MailboxFolderPermission -identity ${accesswho}:\calendar | ft -AutoSizePAUSE}‘4’ {Write-Host “————————————————————————————————”Write-Host “Fix user permission”Write-host ” ”$accesswho = read-host -Prompt ‘Whos calendar do you need access to? firstname.surname’Write-host ” ”$accessfor = Read-Host -Prompt ‘Who is the delegate? firstname.surname’Write-host ” ”Set-MailboxFolderPermission -identity ${accesswho}:\calendar -User $accessfor -Accessrights Editor -SharingPermissionFlags DelegateAdd-RecipientPermission -identity ${accesswho} -Trustee $accessfor -accessrights SendAs -Confirm:$falseWrite-Host “$accessfor now has delegate calendar access in Outlook and Skype for Business to create and edit meetings on behalf of $accesswho”Write-Host ” ”Get-MailboxFolderPermission -identity ${accesswho}:\calendar | ft -AutoSizePAUSE}‘5’ {Write-Host “————————————————————————————————”Write-Host “Remove user permission”$accesswho = read-host -Prompt ‘Remove access to which calendar? firstname.surname’$accessfor = Read-Host -Prompt ‘Who is the delegate to remove? firstname.surname’Remove-MailboxFolderPermission -identity ${accesswho}:\calendar -User $accessfor -Confirm:$TrueRemove-RecipientPermission -identity ${accesswho} -Trustee $accessfor -AccessRights SendAS -Confirm:$TrueGet-MailboxFolderPermission -identity ${accesswho}:\calendar | ft -AutoSizeWrite-Host ” ”Write-Host “SUMMARY”Write-Host “”$accessfor”‘s delegate permissions to Skype have been removed from $accesswho”Write-host ” ”PAUSE}}}until ($selection -eq ‘e’)Exit-
This reply was modified 1 week, 6 days ago by
kvprasoon. Reason: Code formating
-
This reply was modified 1 week, 6 days ago by
-
January 5, 2021 at 8:21 am #284251
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
-
January 7, 2021 at 1:33 pm #284665
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
-
-
AuthorPosts
- You must be logged in to reply to this topic.