{"id":3848,"date":"2020-08-14T10:41:44","date_gmt":"2020-08-14T02:41:44","guid":{"rendered":"https:\/\/www.rockfu.net\/blog\/?p=3848"},"modified":"2020-08-14T10:41:44","modified_gmt":"2020-08-14T02:41:44","slug":"office-365-command-shell-%e5%a4%a7%e9%87%8f%e4%bf%ae%e6%94%b9%e7%94%a8%e6%88%b6%e8%b3%87%e6%96%99","status":"publish","type":"post","link":"https:\/\/www.rockfu.net\/blog\/2020\/08\/%e9%9b%bb%e5%ad%90%e5%ad%b8%e7%bf%92\/office-365-command-shell-%e5%a4%a7%e9%87%8f%e4%bf%ae%e6%94%b9%e7%94%a8%e6%88%b6%e8%b3%87%e6%96%99\/","title":{"rendered":"office 365 command shell \u5927\u91cf\u4fee\u6539\u7528\u6236\u8cc7\u6599"},"content":{"rendered":"<p>\u7db2\u8ab2\u958b\u59cb\uff0c\u5b78\u6821\u5c31\u958b\u59cb\u9700\u8981\u7528365\u5e73\u53f0\u9032\u884c\u5b78\u7fd2\uff0c\u4e00\u5e74\u904e\u53bb\u4e86\uff0c\u65b0\u7684\u4e00\u5e74\u53c8\u4f86\u4e86\uff0coffice 365\u4e26\u4e0d\u50cfgoogle \u90a3\u822c\u7c21\u55ae\u4e0a\u8f09\u4e00\u500bcsv \u4e0a\u53bb\u5c31\u5e6b\u4f60\u4fee\u6539\u4e86\u8cc7\u6599\uff0c\u800c\u662f\u8981\u4f60\u7528\u81ea\u5df1\u7684ad\u540c\u6b65\uff0c\u6216\u8005\u5c31\u662f\u4f60\u7528command shell \u4f86\u5927\u91cf\u4fee\u6539\uff0c\u5c0d\u5b78\u6821\u4f86\u8aaa\u9084\u771f\u662f\u4e00\u500b\u96e3\u5ea6\uff0c\u56e0\u70ba\u5f88\u591a\u540c\u5de5\u8a62\u554f\u5982\u4f55\u5927\u91cf\u4fee\u6539teams \u7528\u6236\u540d\u7a31\uff0c\u5728\u9019\u88e1\u5beb\u4e0a\u7b46\u8a18\uff0c\u5e0c\u671b\u5c0doffice 365\u5927\u91cf\u4fee\u6539\u7528\u6236\u8cc7\u6599\u63d0\u4f9b\u53c3\u8003\u8cc7\u6599\u3002<\/p><div class=\"rockf-content\" id=\"rockf-2724906560\"><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<p><strong>\u9996\u5148\u5b89\u88dd\u5fc5\u8981\u7684\u63d2\u4ef6\u652f\u63f4<\/strong><br \/>\n\u4e0b\u9762\u7db2\u9801\u4ecb\u7d39<br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/previous-versions\/azure\/jj151815(v=azure.100)?redirectedfrom=MSDN\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/docs.microsoft.com\/en-us\/previous-versions\/azure\/jj151815(v=azure.100)?redirectedfrom=MSDN<\/a><\/p>\n<p>\u9700\u8981\u5b89\u88dd<\/p>\n<p>Microsoft Online Services Sign-In Assistant for IT Professionals RTW<\/p>\n<p><a href=\"https:\/\/go.microsoft.com\/fwlink\/?linkid=286152\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/go.microsoft.com\/fwlink\/?linkid=286152<\/a><\/p>\n<p>Azure Active Directory Module for Windows PowerShell (64-bit version) <a href=\"https:\/\/go.microsoft.com\/fwlink\/p\/?linkid=236297\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/go.microsoft.com\/fwlink\/p\/?linkid=236297<\/a><\/p>\n<p>\u5b89\u88dd\u5b8c\u5f8c\uff0c\u5728windows 10 \u5c0b\u627ewindows powershell ISE\uff08\u9019\u500b\u65b9\u4fbf\u9078\u64c7\u6587\u4ef6\uff09, \u53f3\u9375\u9078\u64c7\u7cfb\u7d71\u7ba1\u7406\u54e1\u57f7\u884c<\/p>\n<p>powershell \u6709\u7279\u5b9a\u7684\u653f\u7b56\uff0cRestricted, AllSigned, RemoteSigned, and Unrestricted\uff0c\u9810\u8a2d\u662fRestricted<br \/>\n\u5047\u5982\u4f60\u7b2c\u4e00\u6b21\u9032\u5165\uff0c\u9700\u8981\u628a\u653f\u7b56\u4fee\u6539\u4e00\u4e0b\u70baunrestricted<br \/>\n\u8f38\u5165<\/p>\n<p>Set-ExecutionPolicy Unrestricted<\/p>\n<p>\u6309Y \u78ba\u8a8d<\/p>\n<p><strong>\u63a5\u8457\u958b\u59cb\u9023\u63a5\u5230office 365<\/strong><\/p>\n<p>\u8f38\u5165<\/p>\n<p>Connect-MsolService<\/p>\n<p>\u6309enter \u5f8c\u6094\u8df3\u51fa\u8ddfOffice 365 \u4e00\u6a23\u7684\u767b\u5165\u7a97\u53e3\uff0c\u4f7f\u7528office 365 \u7cfb\u7d71\u7ba1\u7406\u54e1\u767b\u5165<br \/>\n\u6210\u529f\u5f8c\uff0c\u53ef\u4ee5\u6e2c\u8a66\u4e00\u4e0b\u662f\u5426\u9023\u63a5\u6210\u529f\u4e86\uff0c\u8f38\u5165\u4e00\u500bcommand \u6e2c\u8a66<\/p>\n<p>Get-MsolUser -EnabledFilter EnabledOnly -MaxResults 20<\/p>\n<p>\u4e0a\u9762\u662f\u5217\u51fa\u7528\u6236\u540d\u55ae\u6700\u591a 20 \u500b\u555f\u52d5\u7528\u6236<br \/>\n\u5047\u5982\u80fd\u5217\u51fa\u540d\u55ae\uff0c\u8aaa\u660e\u4f60\u5df2\u7d93\u6210\u529f\u9023\u63a5\uff0c\u63a5\u8457\u5982\u4f55\u505a\uff0c\u9996\u5148\u53bb<br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/powershell\/module\/msonline\/?view=azureadps-1.0#msonline\">https:\/\/docs.microsoft.com\/en-us\/powershell\/module\/msonline\/?view=azureadps-1.0#msonline<\/a><\/p>\n<p>\u9019\u500b\u662f\u5b98\u65b9\u7684MsolUser \u8aaa\u660e\uff0c\u6240\u6709\u6307\u4ee4\u90fd\u5728\u9019\u88e1\u8aaa\u660e\uff0c\u4e0b\u9762\u4ecb\u7d39\u5e38\u7528\u7684\u5e7e\u500b\u6307\u4ee4<br \/>\n\u589e\u6dfb\u65b0\u7528\u6236 New-MsolUser<\/p>\n<p>https:\/\/docs.microsoft.com\/en-us\/powershell\/module\/msonline\/new-msoluser?view=azureadps-1.0<\/p>\n<p>\u6839\u64da\u5b98\u65b9\u8aaa\u660e\uff0c\u5f88\u7c21\u55ae<\/p>\n<p>New-MsolUser -UserPrincipalName &#8220;davidchew@contoso.com&#8221; -DisplayName &#8220;David Chew&#8221; -FirstName &#8220;David&#8221; -LastName &#8220;Chew&#8221;<\/p>\n<p>-UserPrincipalName \u9019\u500b\u662f\u7d93\u5e38\u6703\u7528\u7684\uff0c\u662f\u7528\u6236\u552f\u4e00\u8b58\u5225\uff0c\u9664\u4e86\u7528\u6236id\u5916\uff0c\u5c31\u662f\u7528\u6236\u7684\u767b\u5165\u90f5\u7bb1<br \/>\n\u4f60\u53ef\u4ee5\u770b\u5230\uff0c\u6307\u4ee4\u683c\u5f0f\u662f\u7528 \u201c-\u201d \u52a0\u201cParameters\u201d \u5728\u52a0\u4f60\u8981\u8f38\u5165\u7684\u503c\uff0c\u55ae\u4e00\u503c\u9700\u8981\u4f7f\u7528\u5f15\u865f\uff0c\u9700\u8981\u8f38\u5165\u4ec0\u9ebc\u5167\u5bb9\uff0c\u53ef\u4ee5\u67e5\u770b\u8aaa\u660e\u52a0\u4e0a\u53bb<br \/>\n\u4f8b\u5982\u8aaa\u660e\u662f\u5426\u5f37\u5236\u8981\u6c42\u7528\u6236\u4fee\u6539\u5bc6\u78bc[-ForceChangePassword &lt;Boolean&gt;]\uff0c \u9019\u500bboolean \u5c31\u662f\u4f60\u8981\u8f38\u5165true \u6216\u8005false<\/p>\n<p>New-MsolUser -UserPrincipalName &#8220;davidchew@contoso.com&#8221; -DisplayName &#8220;David Chew&#8221; -FirstName &#8220;David&#8221; -LastName &#8220;Chew&#8221; -Password &#8220;Bac12345&#8221; -ForceChangePassword $False<\/p>\n<p>\u4e0a\u9762\u5c31\u662f\u70ba\u7528\u6236\u8a2d\u7f6e\u4e86\u9810\u8a2d\u5bc6\u78bc\uff0c\u800c\u4e14\u7121\u9700\u7528\u6236\u767b\u5165\u6642\u4fee\u6539\u5bc6\u78bc<\/p>\n<p>\u5047\u5982\u4f60\u6dfb\u52a0\u5f8c\u767c\u73fe\u6709\u932f\u4e86\uff0c\u90a3\u9ebc\u4f60\u53ef\u4ee5\u4f7f\u7528Set-MsolUser \u4f86\u4fee\u6539<br \/>\nSet-MsolUser -UserPrincipalName &#8220;davidchew@contoso.com&#8221; -ForceChangePassword $True<\/p>\n<p>Set-MsolUser \u5fc5\u9808\u8981\u627e\u5230\u7528\u6236\uff0c\u56e0\u6b64\u7b2c\u4e00\u500b\u5fc5\u9808\u5148\u6307\u5b9a-UserPrincipalName \uff0c\u4e0a\u9762\u6307\u5f15\u8aaa\u662f\u7528\u6236\u767b\u5165\u6642\u5fc5\u9808\u4fee\u6539\u4e00\u6b21\u5bc6\u78bc<\/p>\n<p>\u4ee5\u4e0a\u662f\u55ae\u4e00\u4fee\u6539\u7528\u6236\u4f8b\u5b50\uff0c\u5982\u4f55\u4f7f\u7528csv \u6a94\u6848\u4f86\u4e00\u6b21\u6dfb\u52a0\u6216\u8005\u4fee\u6539\u66f4\u591a\u7528\u6236\u5462\uff1f\u65b9\u6cd5\u5c31\u662f\u4f7f\u7528Import-CSV\u548cForEach-Object \u4f86\u57f7\u884c\u532f\u5165\u5faa\u74b0\u67e5\u8a62\u4fee\u6539\uff0c\u4e0b\u9762\u662f\u4e00\u500b\u4f8b\u5b50<br \/>\n\u9996\u5148\u9700\u8981\u6e96\u5099\u4e00\u500bcsv \u6a94\u6848\uff0c\u4f60\u53ef\u4ee5\u4e0aoffice 365 admin \u532f\u5165\u7528\u6236\u90a3\u4e0b\u8f09\uff0c\u81ea\u5df1\u5efa\u7acb\u4e00\u500b\u4e5f\u53ef\u4ee5\u6709\u4e00\u4e9b\u7279\u5b9a\u7684\u6b04\u76ee\u662f\u5fc5\u9808\u7684\uff0c\u4f8b\u5982 UserPrincipalName\uff0c<br \/>\n\u6211\u5011\u5728csv\u6a94\u6848\u7b2c\u4e00\u884c\u6253\u4e0a UserPrincipalName\uff0cFirstName\uff0cLastName\uff0cDisplayName\uff0cNewPassword<br \/>\n\u7136\u5f8c\u586b\u4e0a\u9700\u8981\u7684\u8cc7\u6599\uff0c\u53ef\u4ee5\u5148\u6e2c\u8a662-3 \u500b\u8cc7\u6599\uff0c\u7136\u5f8c\u653e\u5230\u96fb\u8166\u88e1\u9762\uff0c\u4f8b\u5982C:\\\u6839\u76ee\u9304\u53eb365user.csv\uff0c\u5047\u5982\u4f60\u7528excel\u5efa\u7acb\u9019\u500b\u6a94\u6848\uff0c\u8a18\u5f97\u532f\u51fa\u6210\u70bacsv\u3002<br \/>\n\u7136\u5f8c\u6211\u5011\u5c31\u958b\u59cb\u57f7\u884c<\/p>\n<p>Import-CSV \u2013Path C:\\365user.csv | ForEach-Object { New-MsolUser -UserPrincipalName $_.UserPrincipalName -FirstName $_.FirstName -LastName $_.LastName -DisplayName $_.DisplayName \u2013Password $_.NewPassword -ForceChangePassword $False -UsageLocation &#8220;HK&#8221;}<\/p>\n<p>\u4e0a\u9762\u6307\u4ee4\u6211\u52a0\u4e0a\u4e0d\u8981\u6c42\u4fee\u6539\u5bc6\u78bc\uff0c\u9084\u6709\u52a0\u5165\u4e86-UsageLocation &#8220;HK&#8221; \u7528\u6236\u5340\u57df\uff0c\u52a0\u5165\u9019\u500b\u4e3b\u8981\u662f\u6dfb\u52a0\u6388\u6b0a\u7684\u6642\u5019\uff0c\u9019\u500b\u662f\u5fc5\u9808\u7684\u800c\u4e14\u9019\u500b\u8aaa\u660e\u662f{two-letter country code}<\/p>\n<p>\u5047\u5982\u6210\u529f\u532f\u5165\u5f8c\uff0c\u767c\u73fe\u8981\u4fee\u6539\u7528\u6236\u59d3\u540d\uff0c\u540c\u6a23\u9053\u7406\uff0c\u6211\u5011\u628aNew-MsolUser \u6539\u70baSet-MsolUser<\/p>\n<p>Import-CSV \u2013Path C:\\365user.csv | ForEach-Object { Set-MsolUser -UserPrincipalName $_.UserPrincipalName -FirstName $_.FirstName -LastName $_.LastName -DisplayName $_.DisplayName}<\/p>\n<p>\u6700\u5f8c\u4ecb\u7d39\u5982\u4f55\u6dfb\u52a0\u7528\u6236\u6388\u6b0a\uff0c\u9996\u5148\u6211\u5011\u5148\u700f\u89bd\u4e00\u4e0b\u81ea\u5df1\u6709\u4ec0\u9ebc\u6388\u6b0a\uff0c\u53ef\u4ee5\u4f7f\u7528\u6307\u4ee4\u700f\u89bd<br \/>\nGet-MsolSubscription<br \/>\n\u9019\u88e1\u6703\u5217\u51fa\u4f60\u7684\u6388\u6b0a\u540d\u7a31\uff0c\u5047\u5982\u4f60\u4e0d\u662f\u5f88\u4e86\u89e3\u7528\u6236\u7d66\u4e86\u90a3\u4e9b\u6388\u6b0a\uff0c\u4f60\u53ef\u4ee5\u5148\u53bboffice 365 \u7d66\u7279\u5b9a\u7528\u6236\u8ce6\u4e88\u6388\u6b0a\uff0c\u7136\u5f8c\u4f7f\u7528\u6307\u4ee4\u67e5\u770b\u4ed6\u62ff\u4e86\u90a3\u500b\u6388\u6b0a\uff0c\u4f8b\u5982<\/p>\n<p>Get-MsolUser -UserPrincipalName &#8220;davidchew@contoso.com&#8221; | select -ExpandProperty licenses<\/p>\n<p>\u4ed6\u5c31\u6703\u5217\u51fa\u7528\u6236\u5df2\u7d93\u7372\u5f97\u7684\u6388\u6b0a\uff0c\u7136\u5f8c\u5c31\u76f4\u63a5\u7d66\uff0c\u56e0\u70ba\u6388\u6b0a\u4e00\u822c\u662f\u55ae\u4e00\uff0c\u6240\u4ee5\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u820a\u7684csv \u6a94\u6848\u7528\u6236\u5e33\u865f\u76f4\u63a5\u8ce6\u4e88\u6388\u6b0a\uff0c\u4f8b\u5982<\/p>\n<p>Import-CSV \u2013Path C:\\365user.csv | ForEach-Object { Set-MsolUserLicense -UserPrincipalName $_.UserPrincipalName -AddLicenses &#8220;ABCDEFG:STANDARDWOFFPACK_STUDENT&#8221; }<\/p>\n<p>\u9019\u88e1ABCDEFG\u662f\u4e00\u500b\u4f8b\u5b50\uff0c\u6bcf\u500b\u6a5f\u69cb\u4e0d\u4e00\u6a23\uff0c\u5f8c\u9762\u7684\u6388\u6b0a\u540d\u7a31\u4e5f\u6839\u64da\u81ea\u5df1\u8cb7\u7684\u4e0d\u4e00\u6a23\uff0cSTANDARDWOFFPACK_STUDENT \u662f\u5b78\u751fA1 \u6388\u6b0a<\/p>\n<p>\u6539\u5230\u9019\u88e1\uff0c\u57fa\u672c\u4e0a\u7528\u6236\u7684\u64cd\u4f5c\u5230\u9019\u88e1\uff0c\u5047\u5982\u9084\u9700\u8981\u5176\u4ed6\u4fee\u6539\uff0c\u5efa\u8b70\u770b\u770b\u8aaa\u660e\u66f8\uff0c\u88e1\u9762\u6709\u4f8b\u5b50\uff0c\u4e5f\u5efa\u8b70\u770b\u5e7e\u500b\u6e2c\u8a66\u7528\u6236\u4f86\u6e2c\u8a66\u4fee\u6539\uff0c\u6210\u529f\u4e86\u624d\u5957\u7528\u5230\u6240\u6709\u7528\u6236\u4e0a\u53bb\u3002<\/p>\n<div class=\"rockf-after\" id=\"rockf-2127128001\"><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>\u7db2\u8ab2\u958b\u59cb\uff0c\u5b78\u6821\u5c31\u958b\u59cb\u9700\u8981\u7528365\u5e73\u53f0\u9032\u884c\u5b78\u7fd2\uff0c\u4e00\u5e74\u904e\u53bb\u4e86\uff0c\u65b0\u7684\u4e00\u5e74\u53c8\u4f86\u4e86\uff0coffice 365\u4e26\u4e0d\u50cfgoogl &hellip; <a href=\"https:\/\/www.rockfu.net\/blog\/2020\/08\/%e9%9b%bb%e5%ad%90%e5%ad%b8%e7%bf%92\/office-365-command-shell-%e5%a4%a7%e9%87%8f%e4%bf%ae%e6%94%b9%e7%94%a8%e6%88%b6%e8%b3%87%e6%96%99\/\" class=\"more-link\">\u7e7c\u7e8c\u95b1\u8b80<span class=\"screen-reader-text\"> &#8220;office 365 command shell \u5927\u91cf\u4fee\u6539\u7528\u6236\u8cc7\u6599&#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":[818],"tags":[861,858,856,857,843,860,859],"class_list":["post-3848","post","type-post","status-publish","format-standard","hentry","category-818","tag-bulk-edit","tag-command-shell","tag-office-365","tag-powershell","tag-teams","tag-860","tag-859"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/prNEE-104","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.rockfu.net\/blog\/wp-json\/wp\/v2\/posts\/3848","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=3848"}],"version-history":[{"count":1,"href":"https:\/\/www.rockfu.net\/blog\/wp-json\/wp\/v2\/posts\/3848\/revisions"}],"predecessor-version":[{"id":3850,"href":"https:\/\/www.rockfu.net\/blog\/wp-json\/wp\/v2\/posts\/3848\/revisions\/3850"}],"wp:attachment":[{"href":"https:\/\/www.rockfu.net\/blog\/wp-json\/wp\/v2\/media?parent=3848"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rockfu.net\/blog\/wp-json\/wp\/v2\/categories?post=3848"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rockfu.net\/blog\/wp-json\/wp\/v2\/tags?post=3848"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}