0

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

  • You mention `Joe Dow` as an example: if your usernames have spaces in them, `-join ($String -csplit "([A-Z])")[1..3]` won't work as intended. Do they really have spaces? – mklement0 Aug 27 '21 at 02:39
  • No, there are no spaces. $email variable is in the correct format, but something doesn't work – user16673088 Aug 27 '21 at 11:47

0 Answers0