How To Upload Files To SharePoint Online Using PowerShell | Office 365

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's going on guys welcome to the channel uh today i'm going to show you how you can download and as well upload a file to sharepoint online in office 365. okay so once you learn uh the basics of uploading a file from local storage or from your local computer to sharpen online you will be able to implement even more complex scripts uh or script that can be able to do the upload and as well download of files to sharepoint online for example you might have a requirement to listen for a change uh when you download a file in the downloads folder and you want whenever you download a new file you upload that file to a sharepoint uh online storage somewhere okay so we with what you're going to learn today is the basic of uploading a file and as well downloaded the file from sharepoint online document library back to the local storage so the requirement is you need to install a partial a module and as you can see from this screen there this is the module that you're going to use it's called sharepoint pnp partial online so you need first to download this module the way you do that it's just you can come to this site i will share the link to this module on the video description so that you can just go directly and install the module from that open powershot that's administrator that is so that you can access it uh with administrative level uh permissions and then now you can pass that uh sorry it does not copy a door so that's copied and then now you can pass that and then you hit enter it will start downloading the module for you okay so once you have the module installed uh we can write the script so you get that uh prompt um uh to accept installation of the module from untrusted repository you just uh key in wire for yes and you press enter and it will start installing so this module is an open source module it's not basically developed by microsoft themselves but it works very perfect okay so is the module installed so you can just hold on for it to complete so as the module downloads um i can show you my sharepoint site so here i'm logged into my tenant and i've accessed one of my site i have a site named test site and in the document library i have a folder named test okay and inside that folder i have a file named test xls this is an excel file you can see i modified the file five hours ago what i need to do is we will upload the file to this document library inside the test folder so currently we have only one file uh but we will be uploading another file from the current working directory where i'm in and the file that you're going to upload is the user post xls this it's an excel file so the user posts or we can also uh upload this one but for the purpose of the tutorial and that's all to save time we're going to upload the user posts uh it works for any other file that you have it doesn't matter which file basically you just specify the path of the file and then it will be uploaded automatically okay so we can begin i can create uh the name of our working file so i'm going to name it main.ps1 that is a passion file okay we can verify the modulus as installed guys we're getting a big error and as you can see i had already installed this module so it it seems that it's not able like to override the one that is currently in the system but as you can read from the error we have the following commands are already available on the system so you can just ignore that so just cls to clear my screen and then now we can go back to of our main file where we're going to write our script okay so the first thing that you need to specify or the first variable i'm going to create is a url for our site i hope you can see my screen let me just try to zoom out here okay guys i believe you're able to see now so we need first to define uh the url for our sharepoint site so we can go back to office 365 sharepoint site and um so the way you get the url of your site it's just from the url field uh there at the top so we can just go like click the name of the site itself just by clicking the name of the site itself i'm able to get the url of the site so that's how sharepoint online work so i have the name of the site so that's how you grab it so you need to copy that and you go back to the script and you add two double quotes and you pass the url for your site there the next we need to define variables for our credentials to log into sharepoint online and the way we do that we're going to create a variable for password i'm going to leave it blank as of now so we're going to fill it later the next variable is always password so we are going to evade these credentials inside our script all right so let me just create the next variable going to call it password as well but for the first i'm going to add underscore just there just to spray the two so the first i'm going to specify the password in um though it looks like the way i usually add it so for example if your password is something like uh test uh maybe perhaps 20 22 and then something also so that's how you need to specify your password in plain in plain text and then the next variable what it does it converts that password into a secure plane uh uh it converts the password into a secure stream we're going to call a command let for that we do that is called convert type converts you need to specify the curves it's actually i've missed something convert to secure string type the command list that we're going to call and then here we need to call in now the password there at the top the plain one and then we're going to call another parameter as plain text and then we're going to false all right by this line we are able to convert the plain text password into a secure string the next we're going to define a variable for our upn the one you use to login to sharepoint online so if for example your email they usually log in to sharepoint online is by adding an email like test at your domain dot com that's how you're going to specify your upn moving to next so i can just add a comment here vpn to login to 365 and as well password the first one i can add a comment and specify these is the url share one site so the first script is to upload the file and then we're going to write the next one to download the file okay so i will be replacing my credentials with the actual credentials that i usually use so these are dummy credentials so you need to populate yours with the actual or the real credentials the next um i'm going just to add a comment here and call it like for example automated login just call it automated login and then i'm going to create a variable that is going to host both uh our upn and our password so to match the two so we're going i'm going to call it app credentials and then from there i'm going to specify new or just called this command let new objects called system dot management go to automation dot ps credential it's a function then i'm going to pass in two parameters and the first is the upn and the next is now the password so here you're going to specify the secure password like that not the first one so let me just wrap my code so that you can be able to view everything just like that so now we are combining the two or we imagine the tools that we make access one by one so moving next we need now to call in the core uh pnp purchase commandlet for accessing our sharepoint and the way you do that um we just call add so this is the commandlet that you're going to call first for pnp called rpnp stored credential first parameter is going to be a name for our url and this accepts the url that you want to access in sharepoint username you're going to grab username from our credentials or our merge credentials variable the way you do that is call up credentials dot user name just like that the next is password so password parameter there and then we call in a variable there should be app app credentials dot password just like that so once uh you are able to add your credentials by calling add pnp stored credentials um line we can move next and now we're going to connect now to sharepoint uh online the command led for that is connect pnp online so let me just add a comment here and call it again to share on online okay we need to specify the url that we're going to access the url is the name uh is the variable that has our site so we want to access that site once we log in to sharepoint okay so moving next um we need to specify uh now the file path that we want to upload to sharepoint online document library i told you guys we're going to experiment with this one so just need to click the file or right click and then copy path go back to our script and i'm going to create a variable to host the path so we can call it file path and then pass in the path of our file just like that the next thing that we need to do now we need to call the command let from pnp module that will now upload the file to the document uh library so we need uh to call a command let and it's add p n [Music] file should be pnp sorry guys pnp file and then it accepts a parameter of forwarder we're going to specify now the document library itself so the format for the document library if you can just go back to the site itself when i click documents for that site that we want to upload the file as you can see after test on the url there at the top after test underscore site that is the name of the site we have shared and then a percentage simple 20 documents okay this is space this represents space when we are defining the document library we start with the shared documents and then now the name of the folder that you're going to upload that file so that's what we're going to do so for the document library just add two double quotes and type shared documents and then forward slash the name of the folder that you're going to upload so test is the folder name and we have the shared document if you haven't created this uh the test for order then any file that you're going to upload it will just appear the root of the directory or the root of the document library next we call in the path parameter and here we're going to specify the file itself so it should be file path the one that you want to upload and just by that guys the script is done so now we can uh run our scripts and test to see if we can upload uh user posts excel file to the sharepoint site named test underscore site okay and just before i run the script i just need to specify my actual credentials you can type yours so these are the same credentials that usually used to log into office 365 once you key in your credentials just need to copy a script and then wait for the magic okay guys as you can see uh the file has already been uploaded so it went successfully no errors and then now we can go and verify we have the file so i'm just going to hit refresh there and then open test folder and there we go you can see a few seconds ago so we have the file users user posts i can open the file if i want to but now you can see it's working so we didn't receive an error message uh we have we have a script working so um i just need to emphasize on something that i noticed with um this module uh the first time that you're trying to authenticate to sharepoint online uh you might get an error like the one that i'm just presenting there so you can see the error that i'm showing you you might get something that looks familiar to this and they have actually specified what you need to do so we need to call in this parameter when we are first trying to authenticate with our device to sharepoint online so the way you do that if you get this error message and the command line once you run the script for the first time just go back to your script and on this line 19 where we have connect pnp online and we have the parameter for the url for our site you just need to add another parameter named pnp should be pnp management shell just like that so what will happen is that and then you can rerun the script again so you will get a code and a url uh and as well an instruction so what you need to do is to copy that url to the to your browser and then you add the code that you'll get as well and you can assign permission uh to your application so basically they consider your script as an application trying to authenticate to sharepoint online so you need first to add permission or to allow permissions to give the application permission to be able to uh authenticate to your sharepoint site or sharepoint online so once you verify and add the required permission for your application you can omit uh these uh parameter and then now you can continue working without your script so that's just an emphasis that i noticed something that i noticed and it assumed that they had the solution uh within the error itself okay so guys that's how simple we can upload a file to a sharepoint uh site in office 365. so the next uh video will be now how to download the file that we have just uploaded back to our local storage ok thank you guys for watching bye bye
Info
Channel: Bernard Mwanza
Views: 11,556
Rating: undefined out of 5
Keywords:
Id: WceeMca_vwY
Channel Id: undefined
Length: 23min 2sec (1382 seconds)
Published: Sun Jun 19 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.