Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
# Microsoft Graph PowerShell SDK (alpha)
The Microsoft Graph PowerShell SDK is a collection of PowerShell modules that contain cmdlets for calling Microsoft Graph.
# Microsoft Graph PowerShell SDK Preview
The Microsoft Graph PowerShell SDK is a collection of PowerShell modules that contain cmdlets for calling Microsoft Graph.

## Installing the Microsoft.Graph.Beta Module
## Installing the Microsoft.Graph Module

In the future, the modules will be published to the PowerShell Gallery, however in the short term they are hosted on our own nuget feed. Use the following commands to register repository and then install the `Microsoft.Graph.Beta` module from there.
The modules are now published on the PowerShell Gallery. Installing is as simple as:

```ps
Register-PSRepository `
-Name GraphPowerShell `
-SourceLocation https://graphpowershellrepository.azurewebsites.net/nuget

# Installing the Graph PowerShell module for the Beta API
Install-module Microsoft.Graph.Beta -Repository GraphPowerShell
Install-module Microsoft.Graph
```

There are a set of samples in the `samples` folder to help getting started with the library.
There are a set of samples in the `samples` folder to help getting started with the library. If you have an older version of these modules installed, there are uninstall instructions in the [InstallModule](./samples/0-InstallModule.ps1) script.

## Generate Module

Expand Down
19 changes: 13 additions & 6 deletions samples/0-InstallModule.ps1
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
# Installing the Module

# Temporarily, register this repository
Register-PSRepository `
-Name GraphPowerShell `
-SourceLocation https://graphpowershellrepository.azurewebsites.net/nuget
# Installing the Graph PowerShell module for the Beta API with no previous versions installed
Install-module Microsoft.Graph

# Uninstalling the old preview version, before installing the new

# Remove the main meta module
Uninstall-Module Microsoft.Graph.Beta

# Remove all the dependent modules
Get-InstalledModule Microsoft.Graph.Beta.* | uninstall-module

# Update the authentication module from 0.1.4 to 0.1.5
Install-Module Microsoft.Graph.Authentication -Repository PSGallery -force

# Installing the Graph PowerShell module for the Beta API
Install-module Microsoft.Graph.Beta -Repository GraphPowerShell
8 changes: 4 additions & 4 deletions samples/1-FindCommands.ps1
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

# Modules Current Available
Find-Module -Repository GraphPowerShell | Select-Object Name
Find-module Microsoft.Graph* | Select-Object Name

# Commands Available for licenses
Get-Command -Module Microsoft.Graph.Beta* *license*
Get-Command -Module Microsoft.Graph* *license*

# Commands Available for Outlook tasks
Get-Command -Module Microsoft.Graph.Beta* *OutlookTask*
Get-Command -Module Microsoft.Graph* *OutlookTask*

# Commands Available for Teams
Get-Command -Module Microsoft.Graph.Beta* *Team*
Get-Command -Module Microsoft.Graph* *Team*
2 changes: 1 addition & 1 deletion samples/2-ConnectToGraph.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Connect-Graph

# Try to Get-User
Get-User
Get-MgUser

# Grant more permissions
Connect-Graph -Scopes "User.Read","User.ReadWrite.All","Mail.ReadWrite",`
Expand Down
10 changes: 5 additions & 5 deletions samples/3-TenantInformation.ps1
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Tenant Information

## Organization Contact Details
Get-Organization | Select-Object DisplayName, City, State, Country, PostalCode, BusinessPhones
Get-MgOrganization | Select-Object DisplayName, City, State, Country, PostalCode, BusinessPhones

## Organization Assigned Plans
Get-Organization | Select-Object -expand AssignedPlans
Get-MgOrganization | Select-Object -expand AssignedPlans

## List application registrations in the tenant
Get-Application | Select-Object DisplayName, Appid, WebRedirectUris
Get-MgApplication | Select-Object DisplayName, Appid, WebRedirectUris

## List service principals in the tenant
get-serviceprincipal | Select-Object id, AppDisplayName | Where-Object { $_.AppDisplayName -like "*powershell*" }
get-MgServicePrincipal | Select-Object id, AppDisplayName | Where-Object { $_.AppDisplayName -like "*powershell*" }

## Create a new Application Registration
New-Application -displayName "MyTestApp7"
New-MgApplication -displayName "MyTestApp7"
30 changes: 15 additions & 15 deletions samples/4-UsersAndGroups.ps1
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
# Microsoft Graph Users and Groups Snippets

# List of Users
Get-User -top 999 | Select-Object id, displayName, OfficeLocation, BusinessPhones
Get-MgUser -top 999 | Select-Object id, displayName, OfficeLocation, BusinessPhones

# List of users with no Office Location
Get-User | Select-Object id, displayName, OfficeLocation, BusinessPhones | Where-Object {!$_.OfficeLocation }
Get-MgUser | Select-Object id, displayName, OfficeLocation, BusinessPhones | Where-Object {!$_.OfficeLocation }

# Update the location of the user
Update-User -UserId $UserId -OfficeLocation $NewLocation
Update-MgUser -UserId $UserId -OfficeLocation $NewLocation

# Get all Groups
Get-Group -top 999 | Select-Object id, DisplayName, GroupTypes
Get-MgGroup -top 999 | Select-Object id, DisplayName, GroupTypes

# Get-Details of a single Group
Get-Group -GroupId $groupId | Format-List | more
Get-MgGroup -GroupId $groupId | Format-List | more

# Get Owners of a Group
Get-GroupOwner -GroupId $GroupId
Get-MgGroupOwner -GroupId $GroupId

# Translate Directory Objects to Users
Get-GroupOwner -GroupId $GroupId | ForEach-Object { @{ UserId=$_.Id}} | get-user | Select-Object id, DisplayName, Mail
Get-MgGroupOwner -GroupId $GroupId | ForEach-Object { @{ UserId=$_.Id}} | get-MgUser | Select-Object id, DisplayName, Mail

# Could do the same for Group Members
Get-GroupMember -GroupId $GroupId
Get-MgGroupMember -GroupId $GroupId

# Get your mail
Get-UserMessage -UserId $UserId -Filter "contains(subject,'Marketing')" | select sentDateTime, subject
Get-MgUserMessage -UserId $UserId -Filter "contains(subject,'Marketing')" | select sentDateTime, subject

# New Group
$group = new-Group -DisplayName "PowerFam" -MailEnabled:$false -mailNickName "powerfam" -SecurityEnabled
$group = new-MgGroup -DisplayName "PowerFam" -MailEnabled:$false -mailNickName "powerfam" -SecurityEnabled

# Add member to Group
new-GroupMember -GroupId $Group.Id -DirectoryObjectId $UserId
# Add member to Group
new-MgGroupMember -GroupId $Group.Id -DirectoryObjectId $UserId

# View new member to Group
Get-GroupMember -GroupId $group.Id | ForEach-Object { @{ UserId=$_.Id}} | get-user | Select-Object id, DisplayName, Mail
Get-MgGroupMember -GroupId $group.Id | ForEach-Object { @{ UserId=$_.Id}} | get-user | Select-Object id, DisplayName, Mail

#Remove Group
Remove-Group -GroupId $Group.Id
Remove-MgGroup -GroupId $Group.Id

# Create a new User
new-user -displayName "Bob Brown" -AccountEnabled -PasswordProfilePassword "{password}" `
new-MgUser -displayName "Bob Brown" -AccountEnabled -PasswordProfilePassword "{password}" `
-MailNickname "Bob.Brown" -UserPrincipalName "bob.brown@{tenantdomain}"
6 changes: 3 additions & 3 deletions samples/5-Chats.ps1
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Teams Chat snippets

# Get list of 1:1 chats
Get-Chat
Get-MgChat

# Get Messages from Chat
Get-ChatMessage -chatId $chatId
Get-MgChatMessage -chatId $chatId

# Send a message in that 1:1 chat
New-ChatMessage -chatId $chatId -BodyContent "Hi from VSCode again!"
New-MgChatMessage -chatId $chatId -BodyContent "Hi from VSCode again!"
12 changes: 6 additions & 6 deletions samples/6-Sites.ps1
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# Microsoft Graph Sites PowerShell Snippets

# Get root site
Get-Site -siteId root | Select-Object id, DisplayName
Get-MgSite -siteId root | Select-Object id, DisplayName

# Search for sites
Get-Site -search "marketing" | Select-Object DisplayName, Description, WebUrl
Get-MgSite -search "marketing" | Select-Object DisplayName, Description, WebUrl

# Get Id for marketing site
$Sites = Get-Site -search "marketing" | Select-Object id
$Sites = Get-MgSite -search "marketing" | Select-Object id

# Get Site Pages
Get-SitePage -SiteId $Sites[0].Id
Get-MgSitePage -SiteId $Sites[0].Id

# Get Site Lists
Get-SiteList -SiteId $Sites[0].Id | Select-Object id, DisplayName
Get-MgSiteList -SiteId $Sites[0].Id | Select-Object id, DisplayName

# Get Document Libraries
Get-SiteDrive -SiteId $Sites[0].Id
Get-MgSiteDrive -SiteId $Sites[0].Id

10 changes: 5 additions & 5 deletions samples/Scripts/Get-TeamMembers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
Connect-Graph -ClientId "1e4ee20b-9a64-44cb-bb6f-0d693e76490a" `
-TenantId "d5fe491b-5987-4770-a68f-477c204cd1ca" `
-CertificateName "CN=GraphPowerShellScriptCert"
$groups = get-group
$groups = Get-MgGroup
$teams = $groups | Where-Object { $_.ResourceProvisioningOptions -Contains "Team" }

foreach($team in $teams) {
Write-Host "Team: " + $team.DisplayName -ForegroundColor Blue

Write-Host "Owners: " -ForegroundColor Yellow
$owners = Get-GroupOwner -GroupId $team.Id
$owners = Get-MgGroupOwner -GroupId $team.Id
foreach($owner in $owners) {
$o = Get-User -UserId $owner.Id
$o = Get-MgUser -UserId $owner.Id
Write-Host $o.DisplayName -ForegroundColor Yellow
}

Write-Host "Members: " -ForegroundColor Green
$members = Get-GroupMember -GroupId $team.Id
$members = Get-MgGroupMember -GroupId $team.Id
foreach($member in $members) {
$u = Get-User -UserId $member.Id
$u = Get-MgUser -UserId $member.Id
Write-Host $u.DisplayName -ForegroundColor Green
}
}
4 changes: 2 additions & 2 deletions samples/Scripts/Remove-ServicePrincipal.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Removes Microsoft Graph PowerShell (preview) Service Principal
# This will cause you to need to reconsent after doing Disconnect-Graph

$sp = Get-ServicePrincipal -top 999 | ? { $_.AppId -like "14d82eec-204b-4c2f-b7e8-296a70dab67e" }
Remove-ServicePrincipal -ServicePrincipalId $sp.Id
$sp = Get-MgServicePrincipal -top 999 | ? { $_.AppId -like "14d82eec-204b-4c2f-b7e8-296a70dab67e" }
Remove-MgServicePrincipal -ServicePrincipalId $sp.Id