Add-MailboxPermission - Removing Automapping Piped Command


hi all,

i'd remove automapping based upon csv of users via piped command.  i'm pretty close, cannot figure out way structure last portion in remove automapping.

for example if query specific mailbox user has full rights "supdude":

[ps] c:\>get-mailboxpermission -id supdude@thedomain.org | where-object { $_.accessrights -eq "fullaccess" -and $_.isinherited -like "false" } | ft -auto

identity                                   user          accessrights isinherited deny
--------                                   ----          ------------ ----------- ----
thedomain/users/supdude thedomain\dudethathasfullrights {fullaccess} false       false

i'll extract "supdude" csv header of removeautomapping , csv called "removeautomapping.csv" , run following piped command:

[ps] c:\>import-csv c:\temp\removeautomapping.csv | foreach { get-mailboxpermission -id $_.removeautomapping } | where-object { $_.accessrights -eq "fullaccess" -and $_.isinherited -eq $false } | add-mailboxpermission -identity $_.removeautomapping -user $_.user -accessrights:fullaccess -automapping $false

the command doesn't fail, nor set automapping false.  can't add "foreach" in front of "add-mailboxpermission" because i'll warning running concurrent pipes.

please, i'm still learning powershell , grateful in resolving i'm doing wrong , how correct it.

thank time,

mr mister

hi,

i suggest try below code:

 

$results=import-csv c:\temp\removeautomapping.csv | foreach { get-mailboxpermission -id $_.removeautomapping } | where-object { $_.accessrights -eq "fullaccess" -and $_.isinherited -eq $false }

foreeach($one in $results)

{

add-mailboxpermission -identity $one.removeautomapping -user $one.user -accessrights:fullaccess -automapping $false

}

hope helps.

best regards,

yan li


yan li

technet community support






Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Generating Event ID 91, 44 with CA (In Event Viewer with source as Certsvc)

Group policy default policy cannot be edited because network name not found

Problem when changing update source