Skip to content

Commit

Permalink
Graph (#67)
Browse files Browse the repository at this point in the history
* Graph

* Fix spelling.
  • Loading branch information
adamdriscoll authored Aug 26, 2024
1 parent e92b339 commit 2771b55
Show file tree
Hide file tree
Showing 4 changed files with 210 additions and 0 deletions.
132 changes: 132 additions & 0 deletions Graph/Graph.Users.Scripts/Graph.Users.Scripts.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#
# Module manifest for module 'Graph.Users.Scripts'
#
# Generated by: adamr
#
# Generated on: 5/23/2023
#

@{

# Script module or binary module file associated with this manifest.
RootModule = 'Graph.Users.Scripts.psm1'

# Version number of this module.
ModuleVersion = '0.0.1'

# Supported PSEditions
# CompatiblePSEditions = @()

# ID used to uniquely identify this module
GUID = '1a6fd2ea-c280-4ea2-897e-2c75eaeff5f5'

# Author of this module
Author = 'Ironman Software'

# Company or vendor of this module
CompanyName = 'Ironman Software'

# Copyright statement for this module
Copyright = '(c) Ironman Software. All rights reserved.'

# Description of the functionality provided by this module
Description = 'Scripts for working with users in Microsoft Graph.'

# Minimum version of the PowerShell engine required by this module
# PowerShellVersion = ''

# Name of the PowerShell host required by this module
# PowerShellHostName = ''

# Minimum version of the PowerShell host required by this module
# PowerShellHostVersion = ''

# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
# DotNetFrameworkVersion = ''

# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
# ClrVersion = ''

# Processor architecture (None, X86, Amd64) required by this module
# ProcessorArchitecture = ''

# Modules that must be imported into the global environment prior to importing this module
# RequiredModules = @('')

# Assemblies that must be loaded prior to importing this module
# RequiredAssemblies = @()

# Script files (.ps1) that are run in the caller's environment prior to importing this module.
# ScriptsToProcess = @()

# Type files (.ps1xml) to be loaded when importing this module
# TypesToProcess = @()

# Format files (.ps1xml) to be loaded when importing this module
# FormatsToProcess = @()

# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
# NestedModules = @()

# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
# FunctionsToExport = '*'

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
# CmdletsToExport = '*'

# Variables to export from this module
# VariablesToExport = '*'

# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
# AliasesToExport = '*'

# DSC resources to export from this module
# DscResourcesToExport = @()

# List of all modules packaged with this module
# ModuleList = @()

# List of all files packaged with this module
# FileList = @("")

# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
PrivateData = @{

PSData = @{

# Tags applied to this module. These help with module discovery in online galleries.
Tags = @('azure', 'microsoft', 'graph', 'scripts')

# A URL to the license for this module.
LicenseUri = 'https://github.com/ironmansoftware/scripts/tree/main/LICENSE'

# A URL to the main website for this project.
ProjectUri = 'https://github.com/ironmansoftware/scripts/tree/main/Graph/Graph.Users.Scripts'

# A URL to an icon representing this module.
IconUri = 'https://raw.githubusercontent.com/ironmansoftware/scripts/main/images/widget.png'

# ReleaseNotes of this module
# ReleaseNotes = ''

# Prerelease string of this module
# Prerelease = ''

# Flag to indicate whether the module requires explicit user acceptance for install/update/save
# RequireLicenseAcceptance = $false

# External dependent modules of this module
# ExternalModuleDependencies = @()

} # End of PSData hashtable

} # End of PrivateData hashtable

# HelpInfo URI of this module
# HelpInfoURI = ''

# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
# DefaultCommandPrefix = ''

}

53 changes: 53 additions & 0 deletions Graph/Graph.Users.Scripts/Graph.Users.Scripts.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
function New-Password {
$chars = @(33..126) | ForEach-Object { [char]$_ }
$passwordLength = 12
$password = [String]::Empty
for ($i = 0; $i -lt $passwordLength; $i++) {
$password += $Chars | Get-Random
}
return $password
}

function New-PSUMgUser {
<#
.SYNOPSIS
Creates a new user in Microsoft Graph with a generated password.
.DESCRIPTION
This function creates a new user in Microsoft Graph with a generated password. The function takes the user's display name, user principal name, and account enabled status as parameters. It generates a random password and sets the user's password profile accordingly. The function returns the user's display name, user principal name, generated password, and user ID.
.PARAMETER DisplayName
The display name of the user.
.PARAMETER UserPrincipalName
The user principal name (UPN) of the user.
.PARAMETER AccountEnabled
Specifies whether the user account is enabled.
#>
param(
[Parameter(Mandatory = $true)]
[string]$DisplayName,
[Parameter(Mandatory = $true)]
[string]$UserPrincipalName,
[Parameter(Mandatory = $true)]
[switch]$AccountEnabled
)

$PasswordProfile = @{
Password = New-Password
}

Connect-MgGraph

$MGUser = New-MgUser -DisplayName $DisplayName -UserPrincipalName $UserPrincipalName -PasswordProfile $PasswordProfile -AccountEnabled:$AccountEnabled

@{
DisplayName = $DisplayName
UserPrincipalName = $UserPrincipalName
Password = $password
Id = $MGUser.Id
}

Disconnect-MgGraph
}
21 changes: 21 additions & 0 deletions Graph/Graph.Users.Scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Microsoft Graph User Scripts

This folder contains scripts that demonstrate how to use the Microsoft Graph to manage users in EntraID.

## Pre-requisites

- [Microsoft Graph PowerShell Module](https://www.powershellgallery.com/packages/Microsoft.Graph)

## Adding a Script

These scripts can be added to PowerShell Universal using the Create Script From Command button on Automation \ Scripts. Select the `Graph.Users.Scripts` module and then the command you would like to add. You can then add it to the [portal](https://docs.powershelluniversal.com/portal/portal) for users to execute.

## Commands

### `New-PsuMgUser`

This command creates a new user in EntraID using Microsoft Graph.

```powershell
New-PsuMgUser -DisplayName "John Doe" -UserPrincipalName "johndoe@ironmansoftware.com" -AccountEnabled
```
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ Contains scripts and widgets that are specific to Active Directory.

Contains full apps that can be run with PowerShell Universal.

### [Graph](/Graph)

Contains scripts that interact with the Microsoft Graph.

### [Notifications](/Notifications)

Contains scripts that can be used to send notifications like email and chat apps.
Expand Down

0 comments on commit 2771b55

Please sign in to comment.