Getting Started with VMware PowerCLI and Automation | vmworld

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome to Train Signal you're watching automation using power CLI so first of all the word of caution power CLI is really cool it's also very powerful but it can get complex and that can be a problem on an exam like this so it's a deep topic and it really goes further than what I expect you to see on the exam on the exam I don't expect you to have to sit down and write out a power CLI script I don't expect you to have to be a power CLI expert but I would expect you to be able to at least kind of look at a script and understand what it does and see if there's an error in the script when you run it which is fairly obvious because it throws a big red air up in front of you but I want you to be able to understand those fundamentals if you want to learn more about power CLI I highly recommend how Rotenberg scores he he has a vSphere power CLI training a trained signal and I sat through this course a while back it was my introduction to power CLI I'm not an expert in power CLI by any stretch but you know I didn't really have any issue with power CLI questions on the exam like I said I don't really sit down and write these scripts all the time but I can understand them and you know and muddle my way through them and if you've never touched power CLI that's kind of what I hope for you to be able to do after this lesson but again this is one single kind of short mixed lesson against an entire course that how it's done so if you're a full-on vSphere administrator and you really want to learn how to script and automate go sit through house course you'll be really really glad you did so what is power CLI C for power C lies a simple C sharp in PowerShell interface to be a more vSphere api's long and short of it is it's that Microsoft provides PowerShell which is a really really good scripting language it's easy it's simple you can just almost read through a script and completely understand what something does with almost no PowerShell experience power CLI is VMware is kind of addition to that so they leverage PowerShell and they give you a bunch of what you'll learn are called commandlets that let you access you know many common features within vSphere and the cool thing is is they're very simple like one command --let is like you know get VM and it'll go to the V center of your connection to and pull your list of VMs you can do get snapshot you can do you know get cluster you can do all kind of stuff then you can set them view them create them whatever you want to do all using these little commandlets and you can gather information and script all sorts of different things and the nice thing is if you go out on google there's a ton of pre-written scripts so if you want a script you know sort out all your snapshots or you know sort out all types of VMs or automate creation or movement of VMs people have already done a lot of these so maybe it doesn't do exactly what you wanted to do but you can start with a pre-written script and then kind of you know work on it from there couple of requirements for installing power CLI you need net - oh and Windows PowerShell 100 or - of supported OS is Windows 7 - k-8 vista XP sp2 in 2003 sp2 I haven't tried running on like 2012 it seems to work I haven't tried running on well I guess I have running on Windows 8 cuz I'm doing it right now but it seems to work just fine as well so but that's the official list anyway so remote signing so by default PowerShell is set to require code signing for scripts and this is a problem as many downloaded scripts are not signed for security so you want to disable that you'll get a warning message when it pops up and we have to do a set execution policy that'll probably be the first command that you run in power CLI and I'll show you that here in a second so let's do it first - a quick lab confirm requirements will install PowerShell will install power CLI and will enable remote signing I'm gonna tell you now we're not gonna install PowerShell because I'm doing this lesson under Windows 8 and it's already installed but installing PowerShell is actually very simple if you have an older OS that doesn't have it included like Windows 8 does then you go download powershell 204 microsoft you go next next next couple times and you're done and then we move on to power CLI so that was going up to the lab so I've got the install files right here on my desktop so I'll just double click power CL I say yes and it's gonna look like every other installation you've done and it's gonna say look your execution policy of this computer is not set to remote sign this prevents execution of PowerShell scripts and will result in errors when power CLI is invoked so we will change this using the set execution policy here in a second next next read that License Agreement it's all power CLI there's also a vCloud director power CLI if you want to use that not part of the exam but it does have some vCloud director commandlets and will say install once that's installed the next thing I'm going to go ahead and install is this right here which is Update Manager commandlets so we'll talk about those in a slide in a minute but I figured we'll go ahead and do the install now while we're here all that does is kind of what it sounds like is it gives you some commandlets to manage Update Manager baselines patches things like that that is noted on the blueprint so I want to make sure you know how to do that I don't really see a lot of people doing it but it's on the blueprint it'll say do you want to restart and we're gonna say no and let's do Update Manager and it's basically going to be the same thing next next except yeah yeah and it'll do that and it runs some scripts in the background and you're finished so to start it you got two options 32-bit and regular 64-bit I'll start 64-bit it'll grind here for a second and it's gonna say hey we can't install the power CLI environment cannot be loaded because running scripts is disabled on this system for more information blah blah blah so we do set execution policy policy remote sign say yes oh that's right I gotta run as admin we have to set that because it's a system-wide setting so sad execution policy and you can do tabs so like if I do set - X and it'll do the rest if you just want to do set - it'll walk through all of your possible options so you'll see me use tab complete a lot and I'll also do it on a lot of the parameters as well which is pretty handy there we go so let me exit out of this real quick and restart it and I don't have to restart an admin mode and there we go and so if you get the red message you've got a set execution policy remote sign and then close it open it and you should see this so a couple of quick commands um while we do this so first thing you want to do is connect to a vCenter server or an ESX I host I'll connect to V Center and I just give it the IP and it'll give me a warning about the certificate which is normal and it wants me to specify credentials if you own a workstation that is part of a domain and you have admin privileges and all that stuff you don't have to enter that my windows 8 box is not part of my domain for no good reason I need to do that so there you go if you want to get help you can do get power CLI help so you get power CLI community actually that's kind of a good one if you do that it'll pop up a web browser and take you to the power CLI community page from VMware which is actually kind of cool get power CLI help it'll pop the help up but to give you an idea of a command actually you can do get VI command and I'll show you all your commandlets so study those and note every one of them for the exam right no not so much but it gives you a list of all of them so then we can do something like get VM let it query and it'll pull back all the VMS in my environment and then you can start doing things with those so that's the real quick thing so know how to install power CLI you know double click the icon next next know how to enable scripts so it's a set execution policy space remote signed because if you don't do that you can't even run power C live because really power CLI is it's kind of like a script that gets run immediately and sets up this working environment for you so you got to be able to do that not to mention scripts that you're going to download from the internet and use as well so do that know how to get some help and I'll show you how to do some more command help here in just an another lab but that'll get you started so let's talk a little bit about command lick concepts have you already seen a couple because we just ran a few commandments but let's go back over everything so PowerShell commands are called commandlets command let's use a consistent what we call verb noun structure verbs specifies the action get VM for example noun specifies the object to operate on so we can do all sorts of stuff with that command let's have a they take parameters and arguments and this is pretty much like every other command right you'll do a command - parameter 1 - parameter 2 argument argument just like we do with say esxcli commands or say ESX top where we do ESX top batch mode and then we set the animals in the delays so it's pretty common stuff very simple to use the nice thing is that Commandments are named very descriptively so again get VM for example new VM host if you want to add a new vSphere host new datastore to create in your datastore it's all pretty simple and there's some very good help inside the system as well you can also do environmental variables they store information about the operating system environment and basically these are things like the local environment so get item - path and all the environment variables let me show you that so get item - path and it shows you all the environment variables for the system I don't usually use these maybe for some pathing statements but it's mentioned in the blueprint but while I'm in here I just talked about some of the command line and the command line help so to see a list of all the commands you can do get VI command that'll show you everything and some things to keep in mind anything to retrieve information normally starts with get so get inventory get hard-disk get baseline from the update manager list get esxcli get ESXi image profile all those get and show you information then there's there's a few minor ones import install invoke but to move things it's move move cluster move data store move vm4 be motioning things to create a new object it's new so new cluster a new CD drive a new folder new via new template new VM etc the opposite of new to create is remove so we have removed CD drive remove cluster remove hard disk for a movie app remove VM etc and then we scroll down and there's set is used to set like parameters or options so set deploy options set data store set data center set date set cluster set DRS rules then you've got a start and stop for like starting and stopping VMs or VM hosts suspend there's some test commands and a few others but those are the major things so if your get confused on something you can at least start well if I want to find something I probably use a get command you can do get help and then do like set VM and it'll give you the information on that command so it gives you an overview of it and then all the options and parameters a description and then there's related links so one it's its online help and then it's got other commands that you might use with this one so since we're modifying a VM you may want to get VM mu VM new VM etc and you can look at that to see examples of using this command you do get help set VM examples and it will spit out a few examples okay so you can apply a custom spec revert the VM virtual machine to initial state snapshot upgrade the virtual machine hardware using set VM dash vm name and version v7 so it shows you that if you look here at the bottom you can do detailed which shows you a whole lot of information it splits out all these options and parameters and tells you what to do whether they're required and what their options and settings are you can do full which takes it even further so it does show you everything required position default value accept input and accept wildcard characters it tells you everything so it's not hard to get help on these commands so if you want to know what a command does you're not sure what strings you need to pass it use the get help command so again very useful Update Manager we already installed this so the vmware vsphere update manager app our CLI kit I guess provides a set of Commandments for modifying things you download that there and you install it like I showed you to see a list of all your commands for update manager you run the get command PS snap in so again get command be a snap in VMware thumb automation and those are all your options for managing update manager you can set baselines get baselines get patches scan inventories all that stuff I would demo this but it seems to crash PowerShell under Windows 8 the rest of the command and the standard power CLI seem to work fine but if I run a get patch it'll crash PowerShell but those are again are just Commandments that you can do to pull information things like that don't expect them to have you modify this stuff via power CLI on the exam but it does mention the power CLI options in the blueprint so know how to install it and know to run get command - PS snap in VMware Dom automation to make sure it installed correctly because if you don't and so it correctly you run this it won't give you anything so make sure you get this list of commands back and then using commandlets I just walked you through get help so get help in the command Lent like ad VM host - fool for more info or - detailed or examples you've seen me connect to a local server so we connect - VI server and the name of the server you can connect to a beast or host you can connect to a vCenter server whichever you want to manage and even if you are a power sale expert you can usually understand a script as you see the commandlets are fairly informative on the names and will sometimes pipe things in like get VM and will pipe that in to get snapshots with a pull list of VMs to get snapshot and show you a list of all the snapshots from those VMs so it's something that you can usually follow along and I think that's important for the exam again I'm not a PowerShell expert you'll see me fumble around in here at times but you know the idea is to be able to look at existing stuff and modify it I don't think they're gonna ask you and say hey go write a script that does this I would be very surprised not going to say they won't but I'd be very surprised and even one item in the blueprint is modify an existing script so I think that's what they'll have you do and running a script is pretty simple I have a script actually here on my desktop actually no I don't it's on my C Drive called snapshot so if we open this guy oops a little bit big but it's basically just a command now you can get really detailed in these scripts I mentioned that you can go in the internet and download scripts and look at examples and they can get really detailed this is about as simple as you can get because this is just one command line but it's stored in a script file and these are just files with dot ps1 which is the powershell extension so it gets a list of VMs dumps them in to get snapshot which will list out a snapshot format list command will just kind of format the stuff so if you're curious about that command that's not the right command there so let's do not a whole lot but basically it just formats out a list and you can do things like expand group by view certain strings and you kind of format it how you want it just kind of modifies a little bit so if we do get VM into get snapshot oh I'm not connected to a PS sir really need to add this guy to my domain so do you get VM in to get snapshot and it'll go through all my VMs dump that list of the Eames and VM objects in to get snapshot and then pull back your snapshots which I think I have one which I do and then we'll dump that into format list and it formats it in a much better way and you can pick and choose how you want things displayed so that cleans it up and then the out file command just dumps the format actually knocked HTML that's wrong dumps it to text and so that will dump this to a text file that looks like this onto my desktop so that's what that command does and to run these commands you just give it to path snapshot and it'll run it and give it a second and here it is and it's again the output that we just saw so you know also know how to look at these things so if I like to get snapshots which kind of makes sense and I run that it's gonna kick back in error so the term get snapshot is not recognized as a name of a command lit so you're like well there's got to be a way to get a snapshot so there's a couple of ways to figure this out one google it but let's say you're on the exam and you can't but you know there's a way to get them I mean you want to retrieve information it's probably a snapshot if you hit tab it's get snapshot not snapshots and then it wants a value but it'll tell you real quickly where there's a problem in the existing script that you can go change or the way that you're doing something I mean just look at the error here that you need so I mean maybe there's it's like this or they don't even give you it's just you think okay I just need to I want it to run through and get all my snapshots well it's gonna say hey get snapshot value cannot be found for the mandatory parameter VM meaning it needs one or or VMs to know which which ones to hit for snapshots so you could go in here and specify a VM or if you want to do it on all of them we would just do get VM and pipe it in so what I'm trying to get across is look at the error message if you get an existing script on the exam and it's probably gonna be one of two things either add a function to it or fix an error with it and when you fix errors just look at the error output one other common use for this is so we have out file you can also do convert so there's a couple of help there's convert to commands - there's CSV which would conduct this out to a CSV format and then there's HTML which will dump it to HTML format so there's a couple of those I think that's all of them oh there are a few more secure string XML it's gonna say XML HTML and just text output or CSV is it's probably the most common so that will allow you to dump that out so we could take that instead of out we could format list pipe that in to convert to HTML pipe that into something like out file and it'll dump out an HTML file so again pretty neat stuff let's see if that easily works format listen to convert - it's always two T's off' and it'll dump out an HTML table which again you can push out to a file now I don't think it likes me running that through the list viewer oh well but you can use that commandment to dump that to HTML so the key here is figuring out which command let's use looking at the options for it and like I've said if you do get VM and you're confused on options you can do a dash and tab through them so related objects IDs verbose debug anything that you want to do get VM name server datastore and that's all the VMS that live on datastore or one so you can do this so if I want to do that and say which you know VM is owned a store want to have snapshots same thing so it's just a way to pull information of her down that's why this gets very large and very complex is because you can go up a thousand million different ways with this scripting engine so I just want you understand how to find what you need and how to figure out how to use the right command let so we've looked at some of these you can list the aims on the target system you can get the M so you can say the name and power state of the VM in a resource pool to a file so you can do things like this is a variable dollar sign res pole for resource pool equals get resource pool space in the name of the pool the reason we do this is we want to store the object in that resource pool variable so that we can use it in another command like get VM - location and the object is resource pool we dump that into select object name comma power state so basically this is going to say get VM and then only show the name and the power state so I'm not gonna do a variable because I just don't need to but how to get the em-dash data store data store I want into select object and it's gonna be named comma power state and or just show those two fields and again we can dump that out to something else oh that's right it doesn't like that directory so see users administer jason desktop Windows 8 okay and you can do it like that and again you can also do format list and what you want to output it to but again useful commands you can start a VM seeing to get VM mail server and dump that in to start VM that's one way to kind of chain commands and restart or actually start a VM host management again more commandlets so if you want to add a beast or host vCenter add VM host the name the location and the user and a password put a host in maintenance mode we use a number of variables here so host variable is get VM host in the name cluster is get my cluster name where that VM lives so we're chaining things again get cluster VM host and we're using the host variable which says find me the cluster where Jetfire lives then we can update host tasks equals set vm host so we're setting a parameter on which host the one in the host variable we're setting the state to maintenance which is maintenance mode and then we're telling it to run asynchronously meaning go start this task but don't wait for it to finish before moving on to the next thing then you can do get DRS recommendations for that cluster and then in this host cluster where the reason is host is entering maintenance mode apply those DRS recommendations because we just said apply DRS recommendations it would apply all of them whether it's for that host or not but this is a way to say look if the host is in maintenance mode we can apply the DRS recommendations if they're not set to do it automatically what I want you to get is just understand you can push things into variables and then use those variables as you go through other commands you can create objects connect to V Center and then get the root folder and then create a folder under called earth so dollar sign folder equals get folder no recursion so it'll get in the top folder and then create a new one called earth you can create new data centers again location in the name you can create new VMs synchronously a synchronous tasks mean I'm gonna wait to this finishes before moving to the next thing in the script that way if you want to refer back to this VM it has to be created first so new VM give it the name give it the host give it a resource pool disk and memory also wants datastore I meant to add that in this slide so you want to do - datastore and tell it where to store the files else it's not going no and throw an error but you can also do it asynchronously like I mentioned on the last slide where it'll start this create VM tasks and then move on to the next thing in your script because you may want to create a whole bunch of the imps before doing something you don't want to wait for each one to finish so again run async by default as you see since there's no option it is synchronous and then you can do asynchronous web service access commandlets this is one of those things that I think got copied and pasted from an older blueprint because they're now known as API access commandlets and these are used if the regular commandlets cannot provide the functions you need which you kind of have to be moving to something pretty advanced before you get out of the space of the regular commandlets there are two of them get view and get VI object by VI view to really use these you need to understand underlying API calls so I don't think you're gonna see this on the exam I think this is one of those topics that they threw in there for you to be familiar with or as I sometimes say these these are ideas that a person who is doing the vcap should probably be familiar with but honestly these aren't something you probably use on a day-to-day basis they're very advanced and again it's just not something I expect you to see there are such a thing as datastore providers days for photos gives you access to files on the data stores it's called them datastore and when you connect to a server with connected VI server you can access what we call to default drives one is VM store which displays the data stores available in the last connected server vSphere server and VM stores with an S plural that contains all day stores available on all the servers connected with the current session so this is pretty simple CD space VM stores : do it LS and I'll show all my V centers so I connect to the first one do an LS data center and then don't show my data stores and I can walk my data stores CD and walk through and access the files it's just a way to access the files on the data store there are commands you can do to modify the files and change them but I mean this is great if you need to write a script to do all this and walk through and do some things but normally if you're just doing one z2z file changes it's better to do it through the UI along with the data store provider is an inventory provider basically lets you walk the wrong inventory that say vCenter sees called the vehm inventory provider and when you connect to a server you have to commandlets VI and VI s so doovy is : notice my prompt changes type LS go to my V Center and it's just basically to let you walk through everything again so you can walk to VMs do an LS and I'll pull all the VMS host it'll pull all the hosts actually just does cluster then it does the host and does my host and you can just walk through different things and pull information that may not be available through the regular commandlets I don't expect to see this on the exam just because this is a more advanced power CLI you would have to have a fairly complex script to provide output that could be graded and tested so I don't expect to see that what I do expect you to have to know and this wraps up the lesson by the way what I do expect you need to know is how to install power CLI how to set the execution policy to remote sign how to install the update manager commandlets which is easy just you run them and then run the command - to the PS snap in to make sure that you actually see them know how to run an external script and remember I showed you that it's just the path and the script name know how to interpret any errors that come out of a script and they're pretty you know I don't expect you to know every power CLI error that you'll see but no to read those errors and fix any problems in a script if you have to add some functionality to it then figure out which command light to use and again you can you know to get VI commands if you want to command and gives you all of them and remember you can do get help and the name of the command so you know stage patch it'll give you that and if you need some examples to walk you through it or you want to know all the options which required which are not what order you can do - full and it'll give you all that so there's a lot of places to get information this is probably when I took the V cap it was the most daunting because it's so wide open of an option I mean most of the things that we've learned are fairly defined tasks within the VMware environment so this is a little daunting but don't let it worry you I haven't you know I don't think you're going to be too involved on this so just know the things that I just went over feel comfortable moving around a bit in the environment and really if you're vSphere admin it's worth spending time learning power CLI and looking at some of the community scripts even if it's not for this exam they can be very very useful so that's it for this lesson and I look forward to seeing you on the next one
Info
Channel: VMworld 2018
Views: 32,371
Rating: 4.7880793 out of 5
Keywords: PowerCLI, vmware, vsphere, free vmwarer training, vsphere video training series, vmware administrator interview, vmware horizon view administrator, how to use vmware, vmware training video, kernel training, vmware horizon, vmware tutorial, vSphere 5.5, vsphere ha, vsphere high availability, hot cold migration, vsphere getting started, vsphere 6.0, ESXi 6.0
Id: rL-rKyEC7Kc
Channel Id: undefined
Length: 31min 41sec (1901 seconds)
Published: Mon Feb 06 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.