Office365PowerShell

טעינת 365 ב-PS

הנהלת האתר לא תישא באחריות לכל נזק שייגרם מעבודה לפי מדריך זה. המשתמש נושא באחריות הבלעדית לכל שינוי ועבודה שבוצעה. אין לראות בדברים משום המלצה.

רוצים להגדיר הגדרות מתקדמות ב-365 אך נדרשת לכם לשם כך גישה ל-365 ב-PowerShell? רוצים לפתור תקלות ב-365 דרך שימוש ב-PowerShell. המדריך הבא בשבילכם

מתחילים

נכנסים ל-PowerShell כמנהל.

ראשית נתקין את המודול:

Install-Module MSOnline

התוצאה נראית כך:

PS C:\> Install-Module MSOnline
NuGet provider is required to continue
PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based repositories. The NuGet
 provider must be available in 'C:\Program Files\PackageManagement\ProviderAssemblies' or
'C:\Users\administrator\AppData\Local\PackageManagement\ProviderAssemblies'. You can also install the NuGet provider by
 running 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet to install
and import the NuGet provider now?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): y
Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its
InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from
'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): a

לאחר מכן, על מנת לטעון את ההרשאות לכניסה לשירות 365, מכניסים את הפקודה הבאה:

$Cred = Get-Credential

יוקפץ החלון הבא. נא הכניסו את שם המשתמש (admin) והסיסמה שלכם לכניסה לשירות 365:

הזינו שם משתמש וסיסמה לכניסה אל שירות 365

התוצאה ב-PS לאחר מכן תיראה כך:

C:\> $Cred = Get-Credential
cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
Credential
PS C:\>

לאחר מכן נכניס:

Connect-MsolService -Credential $Cred

שימו לב: במידה ובשלב זה וקופצת הודעת שגיאה- שימו לב שאתם לא מנסים להיכנס לשירות דרך שרת או מאחורי Proxy כלשהו.

בשאלה שקפצה נלחץ על A ואנטר:

יוקפץ החלון העליון הבא:

Installing package 'MSOnline'
Downloaded 3.83 MB out of 7.63 MB.
[ooooooooooooooooooooooooooooooooooooo ]          00:00:05 remaining. 

אם יש צורך להיות מחובר גם אל AzureAD הקלידו:

Connect-AzureAD -Credential $Cred

לאחר מכן, על מנת להתחבר אל Exchange online יש להקליד:

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $Cred -Authentication Basic -AllowRedirection

ולסיום נקליד:

Import-PSSession $Session

בסיום המעבד שלנו יעבוד חזק ויוקפץ החלון הבא:

Creating implicit remoting module ...
Getting command information from remote session ... 661 commands received
[ooooooooooooooooooo                    ]          00:00:01 remaining.                                                                                             

כאשר הפקודות נראות כך:

# Store your credentials - Enter your username and the app password
$Cred = Get-Credential
# Connect to Msol
Connect-MsolService -Credential $Cred
# Connect to AzureAd
Connect-AzureAD -Credential $Cred
# Connect to Exchange Online
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $Cred -Authentication Basic -AllowRedirection
Import-PSSession $Session -DisableNameChecking

והתוצאה הסופית נראית כך:

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Try the new cross-platform PowerShell https://aka.ms/pscore6  
PS C:\> $Cred = Get-Credential    
cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
Credential
PS C:\> Connect-MsolService -Credential $Cred
PS C:\> $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $Cred -Authentication Basic -AllowRedirection
WARNING: Your connection has been redirected to the following URI:
"https://ps.outlook.com/PowerShell-LiveID?PSVersion=5.1.18362.145 "
PS C:\> Import-PSSession $Session -DisableNameChecking
ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     1.0        tmp_uktm0cc0.l0y                    {Add-AvailabilityAddressSpace, Add-DistributionGroupMember...
PS C:\>

כעת יש להקליד פקודת PS המותאמת ל-365- לדוגמה:

Get-MsolUser

שימו לב: פקודה זו לוקחת זמן טעינה רב בטננט ענק.

כאשר התוצאה נראית כך:

PS C:\> Get-MsolUser
UserPrincipalName                           DisplayName
-----------------                           -----------
user1@k.com                                 David Shau
user2@k.com                                 Ariel Dou
office@k.com                                Kobi Sec

ואם נרצה למשל לייצא רשימת משתמשים של דומיין מסויים בטננט אחד, נשתמש בזה:

Get-Recipient -RecipientType usermailbox  | where primarysmtpaddress -like "*@domain.com" | Export-csv C:\temp\domain.csv -nti

בהצלחה!

Admin

איש סיסטם ואבטחת מידע. אוהב בירה מסוג Corona, וויסקי Crown Royal, גיימר בדם, ובעל חוש הומור.

מאמרים קשורים

Leave a Reply

Your email address will not be published. Required fields are marked *

אתה תאהב גם את זה
Close
Back to top button