Forum Discussion

vlciho's avatar
vlciho
Copper Contributor
Oct 02, 2019
Solved

Using @ character in exchange powershell remoting (2010)

Hello, how can i use this: Set-MailPublicFolder -Identity Set-MailPublicFolder -Identity "CN=PF1,CN=Microsoft Exchange System Objects,DC=xxxxxxx,DC=local" -GrantSendOnBehalfTo @{add='domain\john.do...
  • Kevin_Morgan's avatar
    Oct 08, 2019

    vlciho 

     

    I would recommend you to set complete commands in one string variable and use AddScript function to add the string text as commands

    Dim strScript As String = "Set-MailPublicFolder -Identity '"+strIdentity+"' -GrantSendOnBehalfTo @{add= "+ _username +" }"
    Dim R2 As System.Management.Automation.Runspaces.Runspace = System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(pConnectionInfo)
    R2.Open()
    Dim P2 As System.Management.Automation.Runspaces.Pipeline = R2.CreatePipeline()
    P2.Commands.AddScript(strScript);
    Dim results As Collection(Of PSObject) = P2.Invoke()
    R2.Close()

    For your case, the string text should be like below :

    Dim strScript As String = "Set-MailPublicFolder -Identity Set-MailPublicFolder -Identity 'CN=PF1,CN=Microsoft Exchange System Objects,DC=xxxxxxx,DC=local' -GrantSendOnBehalfTo @{add='domain\john.doe'}"

Resources