Script to assign multiple users to a specific external access policy

Just a short script to save you some time when enabling a group of AD users for a specific external access policy

#################################################################################
#
# A script to assign multiple users to a specific external access policy.
# Created by Kjetil LindLøkken
# http://drlync.blogspot.no/
# The script import users from a specific AD-Group and grants them an external access policy 
# The users ofcourse need to be enabled for lync before you begin
# The script can easily be manipulated to whatever you want to do with the users you select from AD
#################################################################################

$ADgroupname = $(Read-Host -prompt "Please enter group name")
$accesspolicyname = $(Read-Host -prompt "Please enter name of external access policy")
$ADgroupname
$accesspolicyname
pause
import-module activedirectory

$transcriptname = "ImportedUsers" + (Get-Date -Format s).replace(":","-") +".txt"
Start-Transcript $transcriptname


#### Here is where the users are read from a specific group in AD

$importedusers = Get-ADGroupMember -Identity $ADgroupname -verbose


#### This is where you specify what you want to do with the users you selected fro AD  ####

foreach ($importeduser in $importedusers)
    {
        Grant-CsExternalAccessPolicy -PolicyName $accesspolicyname -Identity $importeduser.DistinguishedName


    }
Stop-Transcript

Comments

Popular Posts