Error with string processing

Welcome Forums General PowerShell Q&A Error with string processing

Viewing 3 reply threads
  • Author
    Posts
    • #232780
      Participant
      Topics: 1
      Replies: 1
      Points: 14
      Rank: Member

      I’m trying to create and run a command in powershell.

      I have a list of email addresses to remove and when I try to create a command it is not working.

      Command:

      get-mailbox -resultsize unlimited | search mailbox -searchquery from:”[email protected]” -targetmailbox Cleanup -targetfolder Processed -deletecontent -loglevel full

      In PS I cannot combine the strings

      $CMDString = “get-mailbox -resultsize unlimited | search mailbox -searchquery from:” +”"" + $emailaddress + "“” +”

      -targetmailbox Cleanup -targetfolder Processed -deletecontent -loglevel full”

      This is the end result:

      ” -targetmailbox Cleanup -targetfolder Processed -deletecontent -loglevel full [email protected]

      It appears anything after the variable overwrites the beginning of the string.

       

    • #232786
      Moderator
      Topics: 4
      Replies: 231
      Points: 1,260
      Helping Hand
      Rank: Community Hero

      Hi coulbc59

      I am not an expert in Exchange Server though, but for your requirement to manage with the strings in the arguments you can run the command like below…

      Get-Mailbox -ResultSize unlimited | Search-Mailbox -SearchQuery ‘from:”$emailaddress”‘ -TargetMailbox Cleanup -TargetFolder Processed -DeleteContent -LogLevel Full
      And please format the code using PRE tags to highlight the code.
      Thank you.
    • #232798
      Participant
      Topics: 1
      Replies: 1
      Points: 14
      Rank: Member

      This is not an Exchange issue. I’m trying to build a command line through a string and then invoke it. The problem is the string is not parsing correctly.

      String:

      Get-Mailbox -resultsize unlimited | Search-Mailbox -SearchQuery from:” [email protected]” -TargetMailbox MessageCleaning -TargetFolder Processed -DeleteContent -LogLevel Full

       

      What it tries to invoke.

      ” -TargetMailbox MessageCleaning -TargetFolder Processed -DeleteContent -LogLevel –forcetes.com

    • #232834
      Participant
      Topics: 5
      Replies: 2384
      Points: 6,066
      Helping Hand
      Rank: Community MVP

      Charles

      When you post code, error messages, sample data or console output format it as code, please.
      In the “Text” view you can use the code tags “PRE“, in the “Visual” view you can use the format template “Preformatted“. You can go back edit your post and fix the formatting – you don’t have to create a new one.
      Thanks in advance.

      This might help you toi understand:

      $emailAddress = '[email protected]'
      Get-Mailbox -ResultSize Unlimited | 
          Search-Mailbox -SearchQuery "from:$emailAddress" -TargetMailbox MessageCleaning -TargetFolder Processed -DeleteContent -LogLevel Full

      You have to provide a filter string for the parameter -SearchQuery. So the “from” has to be included in the filter string. 😉

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