diff --git a/README.md b/README.md index 5928950a8b1..3313bb39199 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/samples/0-InstallModule.ps1 b/samples/0-InstallModule.ps1 index 469b9e2c6a6..4c1827bcebd 100644 --- a/samples/0-InstallModule.ps1 +++ b/samples/0-InstallModule.ps1 @@ -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 diff --git a/samples/1-FindCommands.ps1 b/samples/1-FindCommands.ps1 index 9c5cdd38ff5..ef91ed9987d 100644 --- a/samples/1-FindCommands.ps1 +++ b/samples/1-FindCommands.ps1 @@ -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* \ No newline at end of file +Get-Command -Module Microsoft.Graph* *Team* \ No newline at end of file diff --git a/samples/2-ConnectToGraph.ps1 b/samples/2-ConnectToGraph.ps1 index 8c3b33b6f05..aa0d009139f 100644 --- a/samples/2-ConnectToGraph.ps1 +++ b/samples/2-ConnectToGraph.ps1 @@ -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",` diff --git a/samples/3-TenantInformation.ps1 b/samples/3-TenantInformation.ps1 index 274e5bb47ca..1872f62da51 100644 --- a/samples/3-TenantInformation.ps1 +++ b/samples/3-TenantInformation.ps1 @@ -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" diff --git a/samples/4-UsersAndGroups.ps1 b/samples/4-UsersAndGroups.ps1 index 47b313b8b53..710a12e9f0a 100644 --- a/samples/4-UsersAndGroups.ps1 +++ b/samples/4-UsersAndGroups.ps1 @@ -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}" diff --git a/samples/5-Chats.ps1 b/samples/5-Chats.ps1 index 233242285a5..ff2b43d4249 100644 --- a/samples/5-Chats.ps1 +++ b/samples/5-Chats.ps1 @@ -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!" \ No newline at end of file +New-MgChatMessage -chatId $chatId -BodyContent "Hi from VSCode again!" \ No newline at end of file diff --git a/samples/6-Sites.ps1 b/samples/6-Sites.ps1 index c64b1a3aa3b..bcffea40d6f 100644 --- a/samples/6-Sites.ps1 +++ b/samples/6-Sites.ps1 @@ -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 diff --git a/samples/Scripts/Get-TeamMembers.ps1 b/samples/Scripts/Get-TeamMembers.ps1 index bae28b21c59..9ad49dbf6f3 100644 --- a/samples/Scripts/Get-TeamMembers.ps1 +++ b/samples/Scripts/Get-TeamMembers.ps1 @@ -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 } } diff --git a/samples/Scripts/Remove-ServicePrincipal.ps1 b/samples/Scripts/Remove-ServicePrincipal.ps1 index da1fdb913c0..40efc2caf67 100644 --- a/samples/Scripts/Remove-ServicePrincipal.ps1 +++ b/samples/Scripts/Remove-ServicePrincipal.ps1 @@ -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 \ No newline at end of file +$sp = Get-MgServicePrincipal -top 999 | ? { $_.AppId -like "14d82eec-204b-4c2f-b7e8-296a70dab67e" } +Remove-MgServicePrincipal -ServicePrincipalId $sp.Id \ No newline at end of file