locked
Get-mailbox | search-mailbox prompt for input RRS feed

  • Question

  • I am pretty new to building PS scripts, but I was hoping someone could point me in the right direction. I am trying to get the below script to prompt me for the following input.

    -searchquery

    -TargetMailbox

    -TargetFolder

    get-mailbox -ignoredefaultscope -resultsize unlimited | search-mailbox -domaincontroller "ENTERFQDN" -searchquery 'attachment:"promptedforinput" -TargetMailbox "promptedforinput" -TargetFolder "promptedforinput" -logonly -loglevel full

    Tuesday, December 9, 2014 7:50 PM

Answers

  • If I'm correctly understanding your post, I think you could do something like this. You might want to name your variables something else :)

    $var1 = read-host "Search query"
    $var2 = read-host "Target mailbox"
    $var3 = read-host "Target folder"
    
    get-mailbox -ignoredefaultscope -resultsize unlimited | search-mailbox -domaincontroller "ENTERFQDN" -searchquery 'attachment:$var1 -TargetMailbox $var2 -TargetFolder $var3 -logonly -loglevel full

    • Marked as answer by Bill_Stewart Thursday, January 22, 2015 4:33 PM
    Tuesday, December 9, 2014 8:00 PM

All replies

  • PowerShell does not really have a good facility for that but you can use Read-Host.

    HELP Read-Host -Full.


    ¯\_(ツ)_/¯

    Tuesday, December 9, 2014 7:58 PM
  • If I'm correctly understanding your post, I think you could do something like this. You might want to name your variables something else :)

    $var1 = read-host "Search query"
    $var2 = read-host "Target mailbox"
    $var3 = read-host "Target folder"
    
    get-mailbox -ignoredefaultscope -resultsize unlimited | search-mailbox -domaincontroller "ENTERFQDN" -searchquery 'attachment:$var1 -TargetMailbox $var2 -TargetFolder $var3 -logonly -loglevel full

    • Marked as answer by Bill_Stewart Thursday, January 22, 2015 4:33 PM
    Tuesday, December 9, 2014 8:00 PM