Set a variable as DistinguishedName? (powershell)


i'm new powershell scripting, , scripting in general, easy question. sorry if there's answered question out there already.

my goal create script prompts enter existing active directory username, , reports users have "send-as" rights exchange mailbox.

(this part need with)
first part of script collects distinguishedname of mailbox in question , sets variable $dn

$un = read-host "enter username" $dn = $un???????????? 

(this part have figured out)

the second part uses get-adpermission command report users have "send-as" rights. problem is, due organization's active directory structure, have use distinguishedname of object work, otherwise command errors.

get-adpermission -identity $dn | ? {($_.extendedrights -like "*send-as*") -and -not ($_.user -like "*exchange*") | ft user,extendedrights

any appreciated! thank you!

 - dan


don't know if helps or not, here's adaptation of i've been using our service desk. 

it requires powershell v3, , requires enter @ least 3 characters of part of user name.  wildcard search on string.  if enter entire name, , gets single exact match, return dn user.  if gets more one, display matches in gridview, , can select user want list.

function getuser {   switch -regex (read-host 'enter username (min 3 chars)')     {     '\s{3,}' {                $sb = [scriptblock]::create("name -like '*$_*'")                $found = @(get-mailbox -filter $sb | select name,alias,distinguishedname)                switch ($found.count) {                  0  {                       write-host 'no matching users found'                         return                       }                  1  { return $found.distiniguishedname }                 default {                           $found |                             out-gridview -outputmode single -title 'select user' |                              select -expand distinguishedname                           return                           }                    }              }     'q'      { return }     default  {               'invalid input. retry, or enter q quit.'               . getuser               }         }  } $user =  getuser     if ($user) {     get-adpermission -identity $user |? {                                  ($_.extendedrights -like "*send-as*") -and -not                                  ($_.user -like "*exchange*")                                  } | ft user,extendedrights             }


[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "




Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

2008 Windows Deployment Server Properties Error

Can no longer user MS Update - Files required to use Microsoft Update are no longer registered

How do a find data in one file, search for it in another file and if not found, write a custom message to another file