Please note that VisualCron support is not actively monitoring this community forum. Please use our contact page for contacting the VisualCron support directly.


keithdavis
2014-05-20T20:55:44Z
Trying to run some Exchange PowerShell commands. I can do this via regular PowerShell, by calling this command first:

. 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'
Connect-ExchangeServer -auto


But when I try to add this to my commands in VisualCron, like this:

. 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'
Connect-ExchangeServer -auto
Get-Mailbox | Add-MailboxPermission -User "pridedallas\Domain Admins" -AccessRights Fullaccess -InheritanceType all


I get this:

Exception in Task: A command that prompts the user failed because the host program or the command type does not support user interaction. Try a host program that supports user interaction, such as the Windows PowerShell Console or Windows PowerShell ISE, and remove prompt-related commands from command types that do not support user interaction, such as Windows PowerShell workflows. A command that prompts the user failed because the host program or the command type does not support user interaction. Try a host program that supports user interaction, such as the Windows PowerShell Console or Windows PowerShell ISE, and remove prompt-related commands from command types that do not support user interaction, such as Windows PowerShell workflows.
Sponsor
Forum information
bbusse
2014-05-20T23:00:30Z
You likely need to stop it from confirming. What happens when you run that command to set the permissions yourself? Does it ask you if you want to continue?

best guess, add "-Confirm:$False" to the end of your command. If it's gotta prompt you, you can't run it as a powershell task in VisuclCron.


Get-Mailbox | Add-MailboxPermission -User "pridedallas\Domain Admins" -AccessRights Fullaccess -InheritanceType all -Confirm:$false" 


Brian
keithdavis
2014-05-20T23:11:18Z
No, it just runs. I don't get any prompts. Want me to post the output?
bbusse
2014-05-20T23:36:35Z
Originally Posted by: keithdavis 

No, it just runs. I don't get any prompts. Want me to post the output?



I'm home already, but if you want, I can do some testing tomorrow. We have Exchange 2010 in our environment and I'm an admin. I can test on a new ID i create (instead of all users lol)

Brian
keithdavis
2014-05-21T15:41:03Z
FYI, the problem is may be the importing of the Exchange module:

. 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'
Connect-ExchangeServer -auto

Because when I just run this, I get a different message (it can't find the command Get-Mailbox):

Get-Mailbox | Add-MailboxPermission -User "pridedallas\Domain Admins" -AccessRights Fullaccess -InheritanceType all
bbusse
2014-05-21T15:46:45Z
You're right. I just tried a Powershell Task that does nothing more than this:


. 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'

And it gave me the same message at you.

Brian
keithdavis
2014-05-21T15:49:39Z
Oh, I think I know what it might be. When not started in a truly local environment, the server to connect to has to be specified. I need to find the syntax for that and try it.
bbusse
2014-05-21T16:06:27Z
Originally Posted by: keithdavis 

Oh, I think I know what it might be. When not started in a truly local environment, the server to connect to has to be specified. I need to find the syntax for that and try it.



What you're likely running into is more of a 'what type of Host is Powershell running in' situation. PowerShell.exe is a ConsoleHost, where as the method VC is using to call powershell from that PowerShell task is via the API's and is not a console that can take input. There are certain commands you cannot run. Such as... try running "start-transcript" by itself, it's not allowed.

You'll likely need to do what I posted here, and run via PowerShell.exe instead of the PowerShell task. Which of course means you have to save a ps1 file with your code instead of within VC's task.

http://www.visualcron.co...ts&m=18454#post18454 


EDIT: I just tried. I saved a PS1 file with nothing but your first line (dot sourced path to ps1) as the contents.

I ran it via an Execute task and i get this as the Output... which means it worked just fine. It's a Console thing.


Quote:

Welcome to the Exchange Management Shell!

Full list of cmdlets: Get-Command
Only Exchange cmdlets: Get-ExCommand
Cmdlets that match a specific string: Help *<string>*
Get general help: Help
Get help for a cmdlet: Help <cmdlet name> or <cmdlet name> -?
Show quick reference guide: QuickRef
Exchange team blog: Get-ExBlog
Show full output for a command: <command> | Format-List

Tip of the day #65:

The special variable $_ represents the objects being passed from one cmdlet to another cmdlet in the pipeline. The $_ variable is automatically initiated by the Shell and is bound to the current pipeline object. You can access the properties of the object assigned to the $_ variable as you would any other object. The following example shows how you can view the Name property of each mailbox object that is passed through the pipeline:

Get-Mailbox | ForEach { $_.Name }




Brian
keithdavis
2014-05-21T16:23:06Z
Booyah!!!!!

Thanks Brian!
bbusse
2014-05-21T16:33:23Z
Originally Posted by: keithdavis 

Booyah!!!!!

Thanks Brian!



Glad to have helped. The post i linked is one of a few feature requests for getting the PowerShell task to have the option to launch via PowerShell.exe just like my workaround. Hopefully eventually we can get away from having to save the script on the filesystem somewhere and just keep it within VC 🙂 Less clutter.

Brian
Scroll to Top