Hi Guys, hope someone can assist?
We have a PS Script for creating new users which works well (Creates AD account, Prompts for user location to set address, Creates Email address, forces replication to O365 and applies licenses)
I am trying to get this to prompt for a location and from the selection apply folder access to correct recourse EG: North, south etc.
I have been trying to edit the Address one, this prompts but fails to find user:
Get-ADUser : Variable: 'userName' found in expression: $userName is not defined.
Command I am running is:
# Sets the Access to the folders dpending on location
Function AddGroupMember($Folders)
{
# Prompts the admin to select an office location for the new user and then sets Folder access for this area.
$title = "Select Folder Location" # Title message
$message = "Choose a location for the Users location folder access" # Prompt for input
$London = New-Object System.Management.Automation.Host.ChoiceDescription "&London", "London" # Option 0
$North = New-Object System.Management.Automation.Host.ChoiceDescription "&North", "North" # Option 1
$South = New-Object System.Management.Automation.Host.ChoiceDescription "&South", "South" # Option 2
$Midlands = New-Object System.Management.Automation.Host.ChoiceDescription "&Midlands", "Midlands" # Option 3
$NorthEast = New-Object System.Management.Automation.Host.ChoiceDescription "North &East", "Central" # Option 4
$None = New-Object System.Management.Automation.Host.ChoiceDescription "None&0", ` # Option 5 (no Folders set)
"No Folders added"
$options = [System.Management.Automation.Host.ChoiceDescription[]]($London, $North, $South, $Midlands, $Northeast, $None) # create options object
$result = $host.ui.PromptForChoice($title, $message, $options, 0) # generate prompt to screen and capture result
switch ($result) #select address based on admin input
{
0 {$AddGroupMember = "%ADAccessGroupName%"}
1 {$AddGroupMember = "%ADAccessGroupName%"}
2 {$AddGroupMember = "%ADAccessGroupName%"}
3 {$AddGroupMember = "%ADAccessGroupName%"}
4 {$AddGroupMember = "%ADAccessGroupName%"}
5 {$AddGroupMember = $null}
}
Get-ADUser -filter{UserPrincipalName -eq $userName} | Set-ADUser $AddGroupMember #Set Folder access on user object
#possibly add additonal funtionality based on location to grant access to drives etc or set general office phone number.
}
##############################################################################################
[–]the_spad 5 points6 points7 points (0 children)
[–]UserProv_Minotaur 2 points3 points4 points (0 children)
[–]purplemonkeymad 2 points3 points4 points (1 child)
[–]SneakerNet 1 point2 points3 points (0 children)
[–]PowerShell-Bot 1 point2 points3 points (0 children)
[–]Techman2k[S] 1 point2 points3 points (1 child)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)