I'have a simple task - add users into the local administrators group. We have an Azure AD and using Intune to manage users and computers. I have a script that I'm going to deploy via Intune:
$String = [System.Environment]::UserName
$String = -join ($String -csplit "([A-Z])")[1..3]
$email = $String+ "@somedomain.com"
Net localgroup administrators "AzureAD\$email" /add
The first three rows make a current user's email address that should be in format firstname+lastnameinitial@somedomain.com e.g. joed@somedomain.com for Joe Dow
Here is an issue, $email variable in the right format, but the script failed while deploying it, BUT, if I type email explicitly in the last row like: Net localgroup administrators "AzureAD\joed@somedomain.com" /add it works. What I missed Appreciate any help Thanks, Mat