Result not showing up in powershell

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

function Skype-CallDelegate {


param (
[string]$Title = ‘Skype Menu’
)
cls
Write-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-CallDelegate
Write-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 -AutoSize
Write-Host ” ”


PAUSE
}

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

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

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 ?

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

function Skype-CallDelegate {


param (
[string]$Title = ‘Skype Menu’
)
cls
Write-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-CallDelegate
Write-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 -AutoSize
Write-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 Delegate
Add-RecipientPermission -identity ${accesswho} -Trustee $accessfor -accessrights SendAs -Confirm:$false


Write-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 -AutoSize


PAUSE
}


‘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 Delegate
Add-RecipientPermission -identity ${accesswho} -Trustee $accessfor -accessrights SendAs -Confirm:$false


Write-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 -AutoSize


PAUSE
}


‘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:$True
Remove-RecipientPermission -identity ${accesswho} -Trustee $accessfor -AccessRights SendAS -Confirm:$True


Get-MailboxFolderPermission -identity ${accesswho}:\calendar | ft -AutoSize

Write-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

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

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