{"id":3899,"date":"2024-08-25T12:08:28","date_gmt":"2024-08-25T04:08:28","guid":{"rendered":"https:\/\/www.rockfu.net\/blog\/?p=3899"},"modified":"2024-08-25T16:00:04","modified_gmt":"2024-08-25T08:00:04","slug":"microsoft-graph-powershell-%e8%a8%ad%e5%ae%9am365%e7%9a%84%e4%bd%bf%e7%94%a8%e8%80%85","status":"publish","type":"post","link":"https:\/\/www.rockfu.net\/blog\/2024\/08\/computer\/software\/microsoft-graph-powershell-%e8%a8%ad%e5%ae%9am365%e7%9a%84%e4%bd%bf%e7%94%a8%e8%80%85\/","title":{"rendered":"Microsoft Graph PowerShell \u8a2d\u5b9aM365\u7684\u4f7f\u7528\u8005"},"content":{"rendered":"\n<p>\u767c\u73feM365 powershell \u53c8\u505c\u7528\u4e86\u4e00\u4e9b\uff0c\u5176\u5be6\u771f\u7684\u597d\u7169\uff0c\u7db2\u9801\u754c\u9762\u53ea\u80fd\u4e00\u6b21\u66f4\u65b040\u4f4d\uff0c\u6c92\u8fa6\u6cd5\u5c31\u8981\u7e7c\u7e8c\u5b78\u7fd2\uff0c\u770b\u4e86\u4e00\u4e0bdocs\uff0cpowershell \u8f49\u79fb\u5230Graph\uff0c\u4f8b\u5982\u4e4b\u524d\u80fd\u7528\u7684Set-MsolUserLicense \u5df2\u7d93\u5931\u6548\uff0c\u9700\u8981\u4f7f\u7528microsoft graph \u4f86\u66f4\u65b0\u3002\u5047\u5982\u4f60\u4e0d\u61c2\u5f97\uff0c\u53ef\u4ee5\u8003\u616e\u4f7f\u7528Entra ID \u4f86\u66f4\u65b0\u7528\u6236<\/p><div class=\"rockf-content\" id=\"rockf-3438514262\"><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-5237544886808594\" crossorigin=\"anonymous\"><\/script><ins class=\"adsbygoogle\" style=\"display:block;\" data-ad-client=\"ca-pub-5237544886808594\" \ndata-ad-slot=\"6353985797\" \ndata-ad-format=\"auto\"><\/ins>\n<script> \n(adsbygoogle = window.adsbygoogle || []).push({}); \n<\/script>\n<\/div>\n\n\n\n<p><a href=\"https:\/\/learn.microsoft.com\/zh-tw\/entra\/identity\/users\/users-bulk-add\">\u5728 Azure \u5165\u53e3\u7db2\u7ad9 \u4e2d\u5927\u91cf\u5efa\u7acb\u4f7f\u7528\u8005 &#8211; Microsoft Entra ID | Microsoft Learn<\/a><\/p>\n\n\n\n<p>\u5b89\u88ddGraph PowerShell<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Install-Module Microsoft.Graph -Scope CurrentUser -Repository PSGallery -Force<\/code><\/pre>\n\n\n\n<p>\u5047\u5982\u60f3\u6307\u5b9a\u67d0\u4e9b \u7248\u672c\u4e5f\u53ef\u4ee5\u4f7f\u7528<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Install-Module -Name Microsoft.Graph -Scope CurrentUser -RequiredVersion 2.5.0<\/code><\/pre>\n\n\n\n<p>\u6210\u529f\u5f8c\u5c31\u8981\u958b\u59cb\u767b\u5165\u9032\u884c\u6388\u6b0a\uff0c\u4e00\u822c\u662f\u4f7f\u7528 Connect-MgGraph\uff0c\u4e0d\u904e\u9019\u6a23\u76f4\u63a5\u767b\u5165\u53ea\u662f\u67e5\u8a62\uff0c\u57fa\u672c\u6b0a\u9650\u5f88\u4f4e\uff0c\u6240\u4ee5\u8981\u767b\u5165\u4e26\u8981\u6c42\u66f4\u591a\u6b0a\u9650<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Connect-MgGraph -Scopes \"User.ReadWrite.All\",\"Organization.Read.All\",\"Team.ReadBasic.All\"<\/code><\/pre>\n\n\n\n<p>\u9019\u6a23\u5c31\u6210\u529f\u4e86\uff0c\u63a5\u4e0b\u4f86\u5c31\u662f\u66f4\u65b0\u6388\u6b0a\u4e86\uff0c\u6211\u770b\u4e86\u4e00\u4e9b\u5916\u570b\u7684\u4ee3\u78bc\uff0c\u9ad8\u624b\u90fd\u5beb\u6210script\uff0c\u4e0d\u904e\u6211\u4e00\u5e74\u53ea\u505a\u4e00\u6b21\u5c31\u4e0d\u6298\u9a30\u4e86\uff0c\u9084\u662f\u7528csv \u66f4\u65b0\u3002\u6709\u4e00\u4e9b\u6b04\u76ee\u540d\u4e0d\u592a\u4e00\u6a23\uff0c\u4f8b\u5982UserPrincipalName \u63db\u6210\u4e86UserId\uff0c\u6211\u61f6\u5f97\u63db\u539f\u4f86\u7684csv titile \uff0c\u5c31\u53ea\u662f\u547d\u4ee4\u90a3\u908a\u66f4\u63db\u4e86UserId,csv \u90a3\u908atitle \u5c31\u7e7c\u7e8c\u4f7f\u7528UserPrincipalName \uff0c\u5728Grphy \u9019\u908a\u53ef\u4ee5\u5148\u770b\u770b\u4e00\u500b\u7528\u6236\u7684\u6388\u6b0a\u78bc\uff0c\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Get-MgUserLicenseDetail -UserId davidchew@contoso.com<\/code><\/pre>\n\n\n\n<p>\u6211\u9019\u6b21\u56e0\u70ba\u8981\u6279\u91cf\u53bb\u522a\u9664\u6388\u6b0a\uff0c\u6240\u4ee5\u5c31\u60f3\u770b\u4e86\u4e00\u4e0b\u8cec\u865f\u6709\u4ec0\u9ebc\u6388\u6b0a\uff0c\u7136\u5f8c\u5c31\u8b80\u53d6SkuId\uff0c\u7136\u5f8c\u5c31\u53ea\u6839\u64dacsv \u7684\u8cec\u865f\u5217\u8868\u53bb\u522a\u9664Skuid \u8cc7\u6599<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Import-Csv C:\\rmlic.csv  | ForEach-Object {Set-MgUserLicense -UserId $_.UserPrincipalName -RemoveLicenses \"Sukid\u865f\u78bc\" -AddLicenses @()}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><\/code><\/pre>\n\n\n\n<p>\u5047\u5982\u60f3\u589e\u52a0\u6388\u6b0a\u5c31\u662fRemoveLicenses \u6539\u6210AddLicenses ,\u5f8c\u9762-AddLicenses @() \u6539\u6210&nbsp;&#8211;RemoveLicenses @()&nbsp;\u5c31\u53ef\u4ee5\u4e86\uff0c\u6700\u5f8c\u767b\u51faDisconnect-MgGraph<\/p>\n\n\n\n<p>\u53ef\u4ee5\u53c3\u8003\u4e00\u4e0b\u5916\u570b\u8cc7\u6599\uff0c\u5f88\u8a73\u7d30\uff0c\u4e0b\u9762\u662f\u6211\u770b\u7684\u6587\u7ae0\uff1a<\/p>\n\n\n\n<p><a href=\"https:\/\/practical365.com\/microsoft-365-license-graph-sdk\/\">Manage Microsoft 365 Licenses with the Microsoft Graph PowerShell SDK (practical365.com)<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/practical365.com\/introduction-to-the-microsoft-graph-powershell-sdk-part-ii-performing-common-user-and-group-operations\/\">Microsoft Graph PowerShell SDK: User and Group Operations (practical365.com)<\/a><\/p>\n\n\n\n<p>\u9084\u6709\u5beb\u597d\u7684Script<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/12Knocksinna\/Office365itpros\">GitHub &#8211; 12Knocksinna\/Office365itpros: Office 365 for IT Pros PowerShell examples<\/a><\/p>\n\n\n\n<p>\u7fa4\u7d44<\/p>\n\n\n\n<p><a href=\"https:\/\/learn.microsoft.com\/en-us\/microsoft-365\/enterprise\/manage-security-groups-with-microsoft-365-powershell?view=o365-worldwide\">Manage security groups with PowerShell &#8211; Microsoft 365 Enterprise | Microsoft Learn<\/a><\/p>\n\n\n\n<p>\u8cec\u865f<\/p>\n\n\n\n<p><a href=\"https:\/\/learn.microsoft.com\/en-us\/microsoft-365\/enterprise\/create-user-accounts-with-microsoft-365-powershell?view=o365-worldwide\">Create Microsoft 365 user accounts with PowerShell &#8211; Microsoft 365 Enterprise | Microsoft Learn<\/a><\/p>\n<div class=\"rockf-after\" id=\"rockf-1272874915\"><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-5237544886808594\" crossorigin=\"anonymous\"><\/script><ins class=\"adsbygoogle\" style=\"display:block;\" data-ad-client=\"ca-pub-5237544886808594\" \ndata-ad-slot=\"6353985797\" \ndata-ad-format=\"auto\"><\/ins>\n<script> \n(adsbygoogle = window.adsbygoogle || []).push({}); \n<\/script>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>\u767c\u73feM365 powershell \u53c8\u505c\u7528\u4e86\u4e00\u4e9b\uff0c\u5176\u5be6\u771f\u7684\u597d\u7169\uff0c\u7db2\u9801\u754c\u9762\u53ea\u80fd\u4e00\u6b21\u66f4\u65b040\u4f4d\uff0c\u6c92\u8fa6\u6cd5\u5c31\u8981\u7e7c\u7e8c\u5b78\u7fd2 &hellip; <a href=\"https:\/\/www.rockfu.net\/blog\/2024\/08\/computer\/software\/microsoft-graph-powershell-%e8%a8%ad%e5%ae%9am365%e7%9a%84%e4%bd%bf%e7%94%a8%e8%80%85\/\" class=\"more-link\">\u7e7c\u7e8c\u95b1\u8b80<span class=\"screen-reader-text\"> &#8220;Microsoft Graph PowerShell \u8a2d\u5b9aM365\u7684\u4f7f\u7528\u8005&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[84,8,16,584],"tags":[892,885,538,893,328,877,857],"class_list":["post-3899","post","type-post","status-publish","format-standard","hentry","category-computer","category-software","category-windows","category-584","tag-892","tag-bulk-update","tag-command-line","tag-graph","tag-microsoft","tag-office","tag-powershell"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/prNEE-10T","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.rockfu.net\/blog\/wp-json\/wp\/v2\/posts\/3899","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rockfu.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rockfu.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rockfu.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rockfu.net\/blog\/wp-json\/wp\/v2\/comments?post=3899"}],"version-history":[{"count":4,"href":"https:\/\/www.rockfu.net\/blog\/wp-json\/wp\/v2\/posts\/3899\/revisions"}],"predecessor-version":[{"id":3904,"href":"https:\/\/www.rockfu.net\/blog\/wp-json\/wp\/v2\/posts\/3899\/revisions\/3904"}],"wp:attachment":[{"href":"https:\/\/www.rockfu.net\/blog\/wp-json\/wp\/v2\/media?parent=3899"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rockfu.net\/blog\/wp-json\/wp\/v2\/categories?post=3899"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rockfu.net\/blog\/wp-json\/wp\/v2\/tags?post=3899"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}