Get the O365 Onedrive for business list using PowerShell

Source: Internet
Author: User

Year is over, it's time to start today, and then share a script about O365, before sharing a script that can open a user's OneDrive for business in bulk, which is helpful for doing some migration work. Let's share one today. How to get the user to turn on OneDrive for business scenario, this script is very helpful to see the user turn on OneDrive for business before the O365 Admin Portal launches the report feature. Now we can also use this script to view real-time status information.


The approximate use of the method is very simple, the script is officially provided by Microsoft, will call some of the SharePoint API, the logic itself is not very complex


The modification of the script is basically done within the script, so when it's run, it's basically just a direct execution.


Then you can see the end of the run.


Then go to the designated location to see the results, and you can see that the people who are currently on OneDrive for business are the following, consistent with the situation in my current environment



Below is the specific code

# specifies the url for your organization ' s spo admin service$ adminuri =  "Https://your organization name-admin.sharepoint.com" # specifies the  User account for an Office 365 global admin in your  organization$adminaccount =  "Global admin account" $AdminPass  =  "password  For global admin account "# specifies the location where the list  of MySites should be saved$LogFile =  ' C:\Users\youralias\Desktop\ ListOfMysites.txt ' # begin the process$loadinfo1 = [system.reflection.assembly]:: LoadWithPartialName ("Microsoft.SharePoint.Client") $loadInfo 2 = [system.reflection.assembly]:: LoadWithPartialName ("Microsoft.SharePoint.Client.Runtime") $loadInfo 3 = [system.reflection.assembly]: : LoadWithPartialName ("Microsoft.sharepoiNt. Client.userprofiles ") # convert the password to a secure string, then  zero out the cleartext version ;) $sstr  = ConvertTo-SecureString  -string  $AdminPass  -AsPlainText –Force$AdminPass =  "" # take the  adminaccount and the adminaccount password, and create a credential$ Creds = new-object microsoft.sharepoint.client.sharepointonlinecredentials ($AdminAccount,  $SSTR) # add the path of the user profile service to the  SPO admin URL, then create a new webservice proxy to  access it$proxyaddr =  "$AdminURI/_vti_bin/userprofileservice.asmx?wsdl" $UserProfileService =  New-WebServiceProxy -Uri  $proxyaddr  -usedefaultcredential false$ userprofileservice.credentials =  $creds# set variables for authentication cookies$strauthcookie =  $creds. Getauthenticationcookie ($AdminURI) $uri  = new-object system.uri ($AdminURI) $container  =  new-object system.net.cookiecontainer$container. Setcookies ($uri,  $strAuthCookie) $UserProfileService .cookiecontainer =  $container # sets  the first user profile, at index -1$userprofileresult = $ Userprofileservice.getuserprofilebyindex ( -1) write-host  "Starting- this could take a  while. " $NumProfiles  =  $UserProfileService. Getuserprofilecount () $i  = 1# as long as  the next user profile is not the one we started with   (at -1) ... while  ($UserProfileResult. nextvalue -ne -1)  {Write-Host  "examining profile  $i  of  $NumProfiles "# look for the personal space object in the user profile and retrieve  it#  (Personalspace is the name of the path to a user ' s  Onedrive for business site. users who have not yet created a  # onedrive for business site might not have this property  set.) $Prop  =  $UserProfileResult. Userprofile | where-object { $_. name -eq  "Personalspace"  }  $Url =  $Prop. values[0]. value# if  "Personalspace"   (which we ' ve copied to  $Url)  exists,  log it to our file...if  ($URL)  {$Url  | Out-File  $LogFile  - Append -force}# and now we check the next profile the same  way $UserProfileResult  =  $UserProfileService. GeTuserprofilebyindex ($UserProfileResult. NextValue) $i ++}write-host  "done!" 



You can see that there are some content that needs to be modified, such as the admin URL, account password, save location, etc., can be modified according to their actual situation, because the script needs to modify the content is not much, so did not take the time to change him into a parameterized form

Get the O365 Onedrive for business list using PowerShell

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.