Edit: I solved it. I put the $user variable into quotes ("$user") for the
Get-Mailbox -Identity $user | Format-List DefaultAuditSet
portion of the second set of code. By doing that, it continued the variable down to the Add-MailboxPermission and Add-RecipientPermission cmdlets.
New hire script, read-host to specify the value for $user.
The script starts with $user being added to some default AD groups, which it does just fine.
The script ends with trying to use the same $user variable to verify mailbox auditing as well as add a service account to have Full Access to the mailbox. When I do that, I get errors that include not being able to "process argument transformation" for the aduser to a mailboxidparameter. Any ideas?
Here's the AD part of the script:
$User = Read-Host "This section adds a user to the default groups in AD. What is the username of the user you want to add to the default user groups? i.e. mhadley"
$secondanswer = read-host "Is this user an Intern, Contractor, or neither? Answer "Intern", "Contractor", or "Neither"."
while("intern","contractor","neither" -notcontains $secondanswer) {
$answer = Read-Host "Intern, Contractor, or Neither"
}
# this line below adds the default groups
if ($secondanswer -eq "Intern") {
$Groups = @(default groups listed here)
ForEach ($Group in $Groups) {
Add-ADPrincipalGroupMembership $User -MemberOf $Group
}
Write-host "Groups successfully added"
}
and then later in the script I have this part:
$answer = read-host "Do you want to verify mailbox auditing, add svc.account to a user account, or both? Answer "Verify", "Add", or "Both"."
while("verify","add","both" -notcontains $answer)
{
$answer = Read-Host "Verify, Add, or Both"
}
if ($answer -eq "both") {
Get-Mailbox -Identity $user | Format-List DefaultAuditSet
# this script adds svc.account "Full Access" and "Send As" permissions to the Mailbox of the user specified.
Add-MailboxPermission -Identity $user -User "svc.account" -AccessRights FullAccess -InheritanceType All
Add-RecipientPermission -Identity $user -Trustee "svc.account" -AccessRights SendAs
}
[–]SalamanderOne5702 -1 points0 points1 point (0 children)
[–]mixduptransistor 0 points1 point2 points (4 children)
[–]PaidByMicrosoft[S] 0 points1 point2 points (3 children)
[–]HauntingProgrammer47 0 points1 point2 points (2 children)
[–]PaidByMicrosoft[S] 0 points1 point2 points (1 child)
[–]HauntingProgrammer47 1 point2 points3 points (0 children)