none
composing the command... RRS feed

  • Question

  • Hi All, I am very poor in PowerShell. Hence need some help from the experts.

    I guess this has to do with Array or functions. The requirement is to pass the values obtained in the powershell command.

    I will try to explain.

    On Exchange Server 2013 PowerShell if we run this command

    Get-CasMailbox user1@contoso.com | fl            it will list all the properties for user1@contoso.com among with one of the property is  "ActiveSyncAllowedDeviceIDs" which will have values like android3873,SAMSUNG2347,Nokia464 etc.  

    Then I have to take a note of the ActiveSyncAllowedDeviceIDs and run

    Set-CasMailbox user1@contoso.com  -ActiveSyncAllowedDeviceIDs @{Remove="android3873","SAMSUNG2347"}

    How do I compose a command that will automatically remove the ActiveSyncAllowedDeviceIDs other then BB* & WorxMail*

    Requirement is to remove the devices by their DeviceIDs, except ones starting with  BB* & WorxMail*

    Thanks for your time, effort and knowledge.


    Gautam.

    • Moved by Bill_Stewart Friday, July 27, 2018 6:08 PM This is not "debug/fix/rewrite my script for me" forum
    Monday, April 16, 2018 2:57 PM

All replies

  • If you have an array with IDs and want to keep only specific ones you can use Where-Object with a regular expression .... like this:
    $idList = 'android3873','SAMSUNG2347','BBV10','WorxMailbox'  
    $idList | Where-Object {$_ -notmatch '^BB|^WorxMail'}
    This way you'll get the IDs to remove.

    Best regards,

    (79,108,97,102|%{[char]$_})-join''


    • Edited by BOfH-666 Monday, April 16, 2018 7:36 PM
    Monday, April 16, 2018 7:20 PM