Intro to PowerShell for SharePoint

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
and today's show we're going to talk about getting started with PowerShell and sharepoint what fun but first our intro hi my name is Shane young with bold zeros those guys and today we're going to dive into using Microsoft's PowerShell and sharepoint server whether it's 2010 2013 2016 right it's all the same Bruce can kind of get in there and talk about the fundamentals of PowerShell and what you guys need to know in order to get started and feel comfortable not only running the scripts that you find all over the internet so I'm kind of scary by the way but also just a better understanding how you might make your own scripts and explore and learn I'm going to be very much you know teach you to fish type of topic so great let's jump right in okay so we're going to start over here with my SharePoint 2016 VM now remember this is AB cool weather 2010 2013 2016 maybe have SharePoint 2014 I don't know where that is but if you have it it probably worked for this either way we're going to jump on the 2016 VM this is the same one that I've built in the other video series so if you're interested in that at all it's right there but anyway alright so let's go down here and first thing I want to do is launch PowerShell so my Start button I'm gonna start typing in SharePoint and we're going to get the SharePoint 2016 management shell as one of the options now the first most important step for you right now is you've got to right-click on the school puppy and you've got to say run as administrator it does not work if you do not point a simple so I'm going to say run as administrator user account control is going to pop up will say yes and we're brought to a blinking green prompt if for some reason you get farm is not accessible you probably forgot to do run as administrator it happens a lot all right and before we dive into actually running things here what I want to talk about for a second is the actual shell itself we're actually going to slide it over here a little bit so it takes up some different real estate and so what I want you to do is I want you right-click on it and say properties and so here this gives you an option to kind of edit some of the settings to make it a little more comfortable for you the most important one being quick edit mode because that allows you to highlight stuff copy paste and that type of manipulation that you're used to being a Windows II person so quick edit mode is a must if you jump over to font you have lots of different font sizes and depending on the builder PowerShell you know so like you're using PowerShell on 2010 you might have some different options here but nonetheless you can do the different settings and pick a font that's kind of pleasing you as right size if you're making YouTube videos hint 36 there works and then finally for layout I usually don't mess with any of this stuff but you could change the buffer or the sizing probably not going to do that and then for colors set some colors that are comfortable for you for whatever reason I like black and green it gives me that real happy feel alright so say okay good news is when you come back all those will still be there okay so that's the first step the second thing I want you to do is you notice that I am logged in as SP underscore install and so that is the account that if you can follow my video series right that's the account I did all the installs as I do my patching as at skin I'm pretty much any time I have to remote desktop into my SharePoint Server that's the account I want to use so some people call it SP admin I used to call it SP and then I change the name all in the way don't know why but anyway that gives you a reference point of what account and that account does have to be able to administrate and all the security stuff we've done previously so we ran in as administrator we set the properties all right so first thing what you guys type in is start - transcript No all right so start - transcript needs to dinner what that's going to do is that's going to make us a log file everything that we do in this session it's going to save it tells us where it's saving it the pretty nasty location but nonetheless that gives us kind of a running log this is really important for two reasons one is if you break something you got an idea of what you did later but two when you're learning it's not a typical to go through a process and figure out oh you know I solved this problem today and then come back the next day and be like how did I get those templates again and really end up having to redo all of that learning again so faster the site it's not a lot of fun so I don't think I spend your time you know watching cat videos on YouTube or my videos on YouTube then relearning things you've done before so start - transcript he is very important to you alright so from there what we're going to do is you know it's the SharePoint talk so let's just start with the basics and we'll do a get - command and then we'll just do - noun SP star it helps if you spell now incorrectly that's why I suppose use tab complete chain boom so there is all of the powershell commandlets that are available right because what sharepoint team did was they started all theirs with an SP and i don't know how many that was let's see let's figure out real quick how many that was i'll put those in parentheses like so and then we'll do a dot count 830 - there's a lot of powershell that we learned but the good news is I don't want you to try and learn them all so let's do one that we know and that is our good friend get SP site okay so get SP site if you're good with a sharepoint monocular right that is a site collection SP web is the object that is the sub-sites your little guys are used to actually work with site is the site collection but you can see that when i ran this that i got a warning message more results were found and get SP site but they weren't returned using them at all to return all possible results great idea so we'll type in limit all and then we're going to get the 30 or 40 site collections i have so this is a good indication of why it's important that you run PowerShell as much as you can that comes from Microsoft vs. it comes from the evil internet right because what happened is when you typed in get SP site it's like hey this guy wants to see all the site collections in his farm but he doesn't realize that we have fifty thousand right if you tried to run get SP sign you've had fifty thousand site collections it'll work it's just going to drag your whole farm down for the 30 minutes it takes to compile and pull all those objects and put it out there so SharePoint tries to provide circuit breakers when you do things are well silly another thing that you'll notice if we read through this whole list let's see if we a little bit so look it got my my site stuff site master for the fast site collection creation and then it got all the ones in my portal which is my main one but what site collection is missing if you guessed right you guessed is central admin and so central MN is not included on purpose the reason for that is they don't want you to accidentally go and change it right maybe you're trying to update all the templates in your farm or you want delete all the site collections if you're feeling crazy right they don't want you to accidentally do anything to send ramen so they just don't include it by default it's a pretty good way for them to keep you from getting yourself in trouble because in reality you didn't mean to include Central Admin so what another ones nice features inside a SharePoint it really helps you on the way alright so one of the things I might do here so if you wanted to learn more right we could do a get - help and then get - SP site and I like to use the - online command and what this will do is it's going to open up a web browser and take us to get SP site one of the great things about powershell help if you scroll all the way the bottom and there's always example so if you find a new commandment and you're like I think I know what I want to do you'll be surprised how often the example actually has what you want to do now the other thing to keep in mind though is why all powershell commandlets must have examples there's no rule that says they have to be right all right they're just typed in by some intern in the corner doing this number dudududududu as fast they can so when you find typos and stuff in there just you know use your user tinker and work around those issues okay and if you're looking for more information on get coming and get help all that stuff right there is a link right here to the powershell basics video i did it's not sharepoint specific but it does go into more depth about how to use example could help get command that type of thing right so let's close out of that all right so get SP site so one of the things I might do is get SP site as I could then pipe it over to get SP web and so the idea here is this is going to give me a list of all the site collections right get SP site gets all those objects and then it's going to get a list of all the sub sites are involved there and you can see that's like right away we got these pop-ups like slash meeting slash wiki those are the different sub webs of the site collection that we didn't see and we just did get SP site but if you're really paying attention you also notice we got some errors up here and so this is one as annoying things when you're trying to get used to PowerShell as well and it's saying hey access is denied if we do just a get SP site right we didn't get access denied for the personal SP content my site or the site master but when did the get SP web we did right because it tried to go and open those site collections and found out didn't have access this is one of things where I'm going to kind of stray a little bit from the manual but if you go and look our what you really need to know is that in order for this PowerShell stuff to work the site account that you're logged in as in this case we know we're logged in as let's go down here SP install he needs to have access to the database and access the site collections in order for you to kind of do all the things you're used to so if we look over here in Central Admin what you're going to see is if we go to manage web applications and then if we go to my we've got a portal go to user policy we'll see the install I gave him a full control policy right that means he has complete SharePoint access to all the content database and everything that's in there all the site collections all the webs everything anything in that one he can do that's great for him if we look at the my sites we're getting that error I do not have such access so what I can do is I could add a user next SP install and then click full control and say finish and then click OK here if I forget to do this it wouldn't work so boom that's been updated now if we want our command and get SP site get SP web we still get an error message why is that well the other half of this equation we minimize SharePoint and we go over to our sequel server we'll go to our install account cuts who are logged in s and then user mappings and go look for the my site database right there we'll see that his access is just s data access in public give them DB owner quick okay minimize here back over to SharePoint again we'll hit her up arrow might enter again yay no error messages so it's not ideal but unfortunately for the PowerShell to work your account that you're running it as needs to be dbo and have full control of the webs or the site collections to be able to do anything and everything and this comes up a lot such reasons I pointed out now there is a can't command called ad SP shell admin now this command let what it would do is if you had all the permissions to a database in site collections you can then use this command what to give someone else access but B creates a real chicken and the egg thing because initially the only account that has all the access that would be necessary to run that commandment successfully on all your content is SP farm but SP farms a service account you shouldn't be logging into your server as SP farm so what ends up happening is for me anyway in the real world is I have to go through and manually give permissions to the first account using the database method and central admin and then if you know Bob called me up said hey I want to be a SP shell admin right he wants to run some PowerShell against the portal database no problem Bob alright then we can do at SP shell admin then we do Shayne's cows Bob and then - database and then for the database there you have to give it the good you can't just do WS s you can't just do a database name you actually have to do the database ID and so to get that what you might do is do get SP content database boom there's my database and so we know this is one of my portal so there you go I'll right-click on that and then right click on it which copies it right this is where that quick edit thing is that we talked about earlier and so then now it is at SP shell admin - username Shan Charles Bob and then - database oh not control-v but right click there's that good and then boom bang Ram oh now bob has access so it's it is that's a chicken and egg thing so reality whatever account especially in your demo environments and tests right espy install I just give him permissions manually until the cows come home and then if I have users or other people that want to be able to log in and run PowerShell and I trust them then I give the add shell admin I run the ad shell and then account access for them now the weird thing about that though so we minimize go back go to sequel real quick and we'll refresh our logins we'll see Bob now has a login if we double click on that and then go to user mappings and then go look at the this database you can see that they gave him shell access and SharePoint data access so they set up all the sequel permissions for hem we didn't have to mess with it you know do one but that's the way I look at it alright so let's give it a sequel and so that gives us a good overview absent one of the questions I already had from someone that prompts that answer this video is they said hey I want to be able get a list of all my site collections and put that a file that I can print out no problem right so we'll say get SP site - limit all oh sorry a tab all and then we're going to do is we're going to pipe that out - out - file and then site collections dot text press ENTER and so that's going to pull all site collections and so then now if we go over here open up our file explorer we say see users SP install and so now we have a site collections text file that has all of our site collections and our farm bam wham not too bad all right and now remember with that though you know that was maybe that wasn't exactly what they were looking for so maybe they wanted a little more information one of the things we could have done is we could screw up here and change this a little bit so get SP site - them at all and then we could say select and then when we want URL and owner maybe we'll hit enter test and see what that produces for us hey that seems kind of closer what I wanted so maybe though instead of a text we're going to say let's format - table URL and owner and - auto-size and so that's going to pull it and hopefully make it a little more readable and so unfortunately my screen width and because of the large site collections you'd have to kind of play with a little bit but you could get it down to a point where you got that so you could see everything that you wanted and then once you got all of that done right then we would just depend on here right can we just pipe keep piping then we'll pipe it over to site collections dot text again and then there's our site collections dot text I'll expand that out and so see it's still truncating it because it knows the width of the screen is X so you'd have to play with the pro but I'm not going to get lost there but that gives you the basic idea of how you'd work through the problem and there's also you know there's al CSV there's other types of apps that you can do right you could always just do get - command - verb out and so out file out - hosts out - printer out - string right there's different ways that you can take any of that or the other option you might look at since I misspoke just a second ago is verb and you could do look at export and so this is another way of pulling the data out so for example export CSV might be a better way to get that data out there either way all right the idea is you see it you can play with it and you can now learn kind of how that goes now when we did the get espy site let's hit up a couple times and I did the select URL an owner how did I know what that was well the way that I was able to know that's because I'm smart no um because those are actually just properties of that site collection object so if you wanted to figure out what properties were available what I would do instead is I'd do a get espy site just pick one so we'll just do portal not contoso not contoso that's my other VM I make that mistake a lot Shayne's Cal's calm and then we're going to pipe that over to yet member let's so that's going to take that one specific site collection pipe it over to get member and so what that's going to do and we covered this in the objects video so if you want to learn more about this in detail it's over there but what this is going to do is this is going to show us all the methods sorry scroll on the top there we go so it's an object type of SP site and so site collection here's all the methods all the things that you can do to that site collection methods you can delete it alright you can dispose it you can get URLs so methods are all the actions you can take on it right so if you think of a site collection or you take think of a site collection as a car right so car not start car let's stop car dot change two tires car dot paint you know all the different things you might do to a car and then you have the properties car dot number of tires is for car dot number of doors is two right you kind of have those different properties as physical attributes cars color is red I really described a pretty cool car there um but so all of the different properties available for that site collection are right here as well so now you could really start to dive in you want to figure out you know what is things like you know what quote has been applied to that site collection you know who's the owner you know there's all of these different properties and so this is where storage used these are all the different things that you can really go and dive in right this is back to the teaching you to fish I I've played with every one of those somewhere along the way because they just interest me what data is there in some properties you can edit some properties you can only read right and each ones you dive into it you can discover whether or not to read only property or an editable property a lot of fun to be had there and really it gives us this administrators a chance to you ate things that we couldn't manipulate in the past so in what you might do right so we could get us precise instead of get member and I'll see craziness do a select and star I mean select all the properties and give me their values yikes but there's everything that it knows about that site collection so I for example what I'm trying to figure out something I don't know what the property might be named I go I do a select star and I literally read through here right so for example I'm trying to figure out what web template it uses if we scroll long enough I'll find it in here somewhere and figure out what's going on right so there's the owner espy install there is no secondary owner got it got it now what are the pages it can use when was the last time is modified that's a good report to run when you're trying to prune out your environment what database is it part of right so if you had lots of different databases what's the route web I like how this says sage info it's really usage info and that property you have to kind of drill into you know is it read-only lots of fun things here for you guys to go and play with but we're not gonna do that today I'm just kind of showing you where these fun things are that you might want to play with you know what I think that actually does enough for this video so hopefully this gives you that first little off to figuring out the right permissions you need to have and kind of how to go and poke the bear in the next video I'm actually going to create I'm going to walk through some of the cooler you know that next level of things you can do so creating a list editing a list copying a list of meeting the list you know kind of different things you can do because one of the bummers of sharepoint is if you kind of walk through the object hierarchy right there's a farm concept there's a server concept there's database concept site collection web application webs but that's it so what you have to do is you actually have to go and find your web and then that's where you'll go and find your list right so if you do I'll show you one more thing do get SP web HTTP portal chains I wish this would autocomplete cows calm right always hit enter there make sure that's right that's good and so then what you can do or what I might do is I would then take this and we'll set this to a variable variable I'm variable variable dollar sign zebra right that's all you I do is setup variable is a sign it and so then now we'll just type in zebra to make sure it should tap complete okay so we know there's stuff in there so now you can do zebra remember I kept saying dot so then dot start typing in Li and then hit tab right and so then boom there's all of the lists and so what you'll find is if you go and look at if you do a get member you'll see there's a way to get the list and then you can just really start drilling down once you can get a pull list back then you can pull the items back once you pull items back utilize you can add them edit them delete them you can create views all of that stuff can be done by a powershell and that's really one of the lessons I learned here my hit control-c I'm tired of scrolling is it PowerShell opens the door for you guys to go in and manipulate things and that's one of the ways that we really like to learn about PowerShell is I'll go and figure out things right when we did get SP site type in again and you know I've got 30 site collections or whatever it is here do you think I literally went in and created site collection one site collection two site collection three no way that is not fun and that takes a long time to do I mean it literally takes the PowerShell like 30 minutes but whether there is there's a PowerShell command called new SP site right so that creates a site collection for me yeah no big deal but what you can do is do an import CSV so import CSV and it's dot test site CSV so I made a CSV file that has three columns a name file a column a URL and a template and then I just piped that over right so I said import CSV that gets all that data and then from there you can do write a new SP site now what actually you can't do it that way right you got to do a four for each object and then I just said new SP site and then - URL was boom and we go HTTP portal dot of Shane's cows comm / sites / and then we close the quotes and we said an add-on to that dollar sign underscore dot URL right and so the URL is the the field right there and then I close the parentheses okay so that's going to set the URL value and then I needed to set a name value and guess what that is its dollar sign underscore name right that's the name value out of our CSV and then finally I needed to set a template and you're smart people dollar sign underscore template because that's this third column whew and then I closed out the brackets just like that for each object new recipe site URL boom boom up you know what else I needed to set / owner alias and then we could set the owner alias to Shane's cows and Bob and then we close out the loop right so there you go something as simple as that I mean it takes ten minutes to run but then I had a bunch of filler data because that's what I needed in order to do my test so getting comfortable the looping concepts and power shells probably one of the most important things and that's why I made a whole video reverence it wants for reference again the working with objects because that's what you really after here you're in into getting the SharePoint finding the object that you want to manipulate using things that get member to dig in and figure out what that might be and then once you do running it through loops like the for the for loops and things like that so you can kind of go in and manipulate things or maybe you want to run a command you know where the owner of the site collection is Bob right that's completed possible and I can run a report when after you fire Bob right no more Bob you run a report and say where's all we're all the site collections he's the owner of those are the type of things that you open the door with a PowerShell that really encourage you guys to embrace and learn all right so now I must looking for today hopefully you've enjoyed this video and like I said next time we're going to cover working with lists so creating lists editing lists reading lists copying lists all those things you think you have to have a third-party tool for or an intern which is also a tool either way we're going to cover all that in the next video so hey do me a favor click the subscribe button right here to kind of keep me motivated create creep tape keep me motivated to create all this fun content and as always if you got any feedback leave me a comment or you can hit me up on Twitter Shayne's cals and then of course if you want to work together you need me to write some scripts for you or just help you there sharepoint or as your stuff in general hit me up through the old bold zebras alright thanks and have a great day
Info
Channel: Shane Young
Views: 64,963
Rating: undefined out of 5
Keywords: SharePoint, Bold Zebras, BoldZebras, SharePoint PowerShell, PowerShell SharePoint, SharePoint Server PowerShell, PowerShell SharePoint Server, SharePoint 2010 powershell, SharePoint 2013 PowerShell, SharePoint2016 PowerShell, Introduction to PowerShell, intro to Powershell, beginner PowerShell, beginner SharePoint powershell, intro SharePoint powershell, powershell, powershell scripting for beginners, powershell basics, powershell tutorial, sharepoint 2016 powershell
Id: zKeaGh5Z7Po
Channel Id: undefined
Length: 27min 22sec (1642 seconds)
Published: Wed Sep 28 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.