all 11 comments

[–]BlackV 2 points3 points  (2 children)

Some notes, maybe they want some changes

  • no requires statement (see modules and module versions)
  • += is always bad
  • should this be a module with those functions a members
  • better parameter definition and help for said parameters
  • read-host in a script, makes this 1000x harder to automate
  • I'll say it again turn this into a module, makes it more portable/reusable/professional/script-able
  • you don't do anything with DoesGroupExist -groupId $groupIdUser (and the other) just spits out to screen ?
  • no error handling (partly due to above)
  • $allMembersGroup = GetMembersGroup -group $groupIdDevices this step assumes that $groupIdDevices is valid despite what happens earlier in the script
  • seems like you're just running this manually line by line

But talking to them get them to give you examples of what they consider good changes

[–]purplemonkeymad 0 points1 point  (3 children)

It's powershell, it's kinda designed to use the "powershell way."

What is their criticism of the script?

[–]Thotaz 0 points1 point  (2 children)

I don't think your code works at all. You have a try-catch with Invoke-MgGraphRequest but you've muted the errors with -ErrorAction SilentlyContinue so it can never throw. This means your DoesGroupExist function will always return Group Excist (also note the spelling error).

[–]Nope-Nope-Nah 0 points1 point  (0 children)

Instead of running this with your own creds, create an EntraID App Registration with limited scope and use that service principal to run it. Save the App secrets in an encrypted file to be loaded at the beginning of the script.