Command Shell Wizardry: IT Admins' Key to Remote Management of Windows clients/servers

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello my name is lowell vanderpool and this channel is dedicated to it students i.t professionals and anyone who enjoys learning technical subjects gaining advanced remote administrative skills is crucial for today's it professionals because of covid which has pushed all of our workers back into their homes we are growing companies now with entirely or a large majority of remote workers where they're all over the country we're seeing companies with global workforces data centers that are far removed from where you work at and hosted infrastructure where you've got a ton of your equipment applications and services that are not even close to where your location is yet in spite of this we're faced with just as complex or even more complex problems that we have to be able to solve every day and they have to be solved remotely let's take a look at a scenario a real help this problem where we're going to attack the problem remotely now you could solve this problem with remote powershell and you could solve this problem with command shell or cmd there are still some great command shell utilities that are so powerful helping us troubleshoot every day in the workplace let's take a look at our problem i've got john who's a board member and he's on the 10th floor with the executives i'm working with my helpdesk team and i'm the supervisor of that group and we get a call from john the board member and he's having problems with his laptop he says it's real unstable he's had to reboot it a couple times this morning can't seem to get anything done lockups etc and i asked john because the help desk are terrified because it's a board member they bring me in on the conversation and i'm listening to john talk to help desk and i asked john i said did anything happen the last few days that would lead to this problem he said oh yes last night i was using the laptop and it froze and so my grandson took it pulled the battery out restarted the laptop and it's been this really funky way since then i love grandsons so my gut instinct is we've probably got a corrupted file system and we need to run check disk i want to do this remotely so i'm going to use a cool tool called win rs it's a remote shell tool that i can remote in run command shell tools like check disk against his computer but i know check disk is going to be running this against his c drive and won't finish the process until we restart the computer and check disk will if there's a problem fix those during the reboot so what are we going to do with scenario one well first we're going to do this remotely because i'm not going to send help desk in the executive suite we're going to do check disk we're going to restart i'm going to show you also how to chain multiple commands together in what's known as sequential processing all on the same command line and then i'm going to show you how to chain multiple commands together to get conditional processing now this whole process is going to step us right into the mud of command shell syntax if you don't understand syntax with command shell commands just like you have to learn syntax with powershell you're going to spend a lot of frustrating time so we're going to review our command shell syntax so if you forgot what syntax is it's basically rules you have to know to play the game if you don't play the game right it doesn't work you can either learn syntax now or waste for the next 10 years learning the command line syntax if you haven't learned by now command line shells whether powershell or command shell cmd are very unforgiving you do it right or you do it again and again and again you you've got to do it right so let's get the syntax correct now windows has two basic command line shells one is power shell and the other one is command shell or cmd both are case insensitive it doesn't matter whether it's uppercase lowercase it doesn't matter now having said that microsoft loves to throw in that one or two exceptions so you must be willing to go to your reference documents also look at your online help because every once in a while a command line utility will slip in a case sensitive parameter or a case sensitive switch watch out for them remember powershell is both a command line shell and a scripting environment it is microsoft's go-to task automation and configuration management program many it professionals get into the field and they're having to learn the craft of syntax but you've got to learn it okay mr vanderpool we know that you just go the command prompt you type in forward slash question mark and voila your your syntax problem is gone no i'm here to tell you if you're not using your online command line reference in conjunction with your syntax online help you are going to have problems so here's a quick rundown of syntax we're going to find brackets we're going to look at braces we're going to look at backslashes we're going to look at the slash we'll have angle brackets we'll have a vertical bar or many programmers will know that as a pipe symbol we'll have space man forget your spaces and you're in trouble text without brackets or text without braces all of these make up the syntax for command line utilities now i haven't forgotten about john our board member on the 10th floor with the executives and we're back on the fifth floor working with help desk haven't forgot about this problem we're going to get to in a minute let's cover a few more items of syntax before we go back to john's problem with most of microsoft's command line utilities run in the command shell they use a slash character to indicate a parameter now there are some microsoft documentation that still refers this not to a parameter but as a switch now this is different from unix and linux what uses the dash in the command line to indicate a parameter so if you're dealing with linux and unix you typically use as dash to indicate a parameter not a slash but there are still a ton of microsoft command shell utilities that use the dash not the slash so on this slide i've listed a few that i found there's many more but this is a few that i found and i've put them on this list on the slide now when we get into powershell powerstyle chose to use the dash to indicate the parameter so we'll see that break from the traditional command shell parameter indication to to back to the linux unix world a dash indicates a parameter going back to the command reference page of check disk one of the tools that we want to use on john's laptop and if you'll notice it's got a long list of slash and some character indicating what microsoft calls parameter in the past these were often called switches in fact there's microsoft documentation on their website indicating these are switches not parameters now why microsoft is calling them parameters it's their product they can call them whatever they want so just be aware you will see terms like switch argument and now microsoft is now calling them parameters it's somewhat confusing but that's the way it is so back to our john the board member with his unstable laptop we suspect it's a corrupted ntfs file system and so we're going to execute winrs which is a remote shell program that's going to load up a service on john's computer is going to redirect any console information back to our command prompt shell then it's going to execute one command but i'm going to throw a trick in there i'm going to add a new character and that character is going to allow me to add additional commands on the same command line it's called sequential processing after we run check disk then i'm going to say i want you to run shutdown let's take a look now keep in mind when rs is going across the network to the machine that we're focusing on it's going to install a service and you can see it is called when rshost.exe it will then launch a cmd and then whatever command shell utility that you've asked to execute on the remote host notice that it runs in session zero on the remote computer that user will never see what's going on remember session zero is reserved for protected processes and services there is no user interface to session zero so whatever you're doing using the win rs utility as they can never see what's going on so back to our online documentation i see when rs in a space bracket a slash indicating there's a parameter coming and then again angle brackets a command this would be any utility that will run in the command shell and here's the caveat that is non-gooey totally non-gooey i tried a few they didn't work because they have some element of that's graphical it must be a command shell utility that is strictly console based let's take a look at our syntax any text with without brackets or braces are items you must type as shown so when rs must be typed as shown spaces if you find a space in the command syntax you've got to use it while executing the command when rs space right here we've got after the parameter if you use a value those are optional between winrs and your parameter you must have a space and then whatever command shell utility that you're going to run miss those spaces and you'll do it again and do it again until you get it right notice the first parameter is slash remote that is basically saying i'm going to connect to a remote host you can use a netbios name as i scroll down to the examples of the command you can see slash r so you can use a truncated value a parameter rather than type the entire remote word you can simply use r and then colon and you can put in https so it's very flexible on how you describe your remote hosts allows you to use alternate credentials so you can type in a username and a password make sure you get your syntax don't forget that colon but the key to this is you can execute one command but we don't want to execute one command we want to sequentially process more than one command and i'm going to show you how to do that now i've carefully taken you to the online reference material for microsoft's commands and i've showed you how to use winrs using those commands and parameters let's go to the command prompt and look at the online help so i'm going to go to my prompt forward slash question mark we'll pull up the online help wait a minute what is all these dashes doing here here is one of the problems if you look at the online help all of the parameters are based on dashes not slashes that we just saw on the reference documentation the good news is everything that you type in based on the reference document online will work with this command even though the online help is showing truncated we're using abbreviations rather than the full name we're using dashes i caution you don't say i'm going to use the online help only i'm going to forget the online documentation that will get you in some real frustration you must use both the good news is they made both work so you can use the dashes and the abbreviations as well as exactly as stated in the online reference material both will work perfectly it is very clear that microsoft's developers do not talk with the website documentation people and by the way the online help right here that i'm showing you shows some really cool different ways of connecting to remote hosts jump back now check disc is a utility that most of you are really comfortable with but let's just look at a few syntax issues remember check this space and all of the parameters require a space between them pay attention to that notice under the volume which is in angle brackets is a value you must put in angle brackets you must put in so this is going to be a drive letter followed by a colon notice no colon is shown if you don't read the description uh we're going to use forward slash or slash f which is going to fix errors on the disk but look a message will ask you if you want to check the drive on the next time you restart and that is typical of what's going to happen on c drive because the disk has to be locked in order to run check disk so we're going to watch for that message when we work with john just as a side note don't forget about check this don't interrupt check disk after you've initiated although microsoft says it shouldn't cause you a problem if you interrupt it and you only need to go ahead and run check disk on the rest of the drive should you interrupt it they warn you bad things can happen when you interrupt check this so don't we're also going to execute shutdown even though our winrs only allows one command utility i'm going to show you how we can put many more command utilities after the first one notice in shutdown in our brackets we've got parameter i parameter l parameter s parameter sg and notice the bar the vertical bar the pipe indicates one or the other you can't just type shutdown you have to have a parameter we're going to use the parameter slash r so that we're going to restart the computer but i'm also going to do a slash f because i don't know if john has got any applications running so i'm going to force those applications closed i hope john doesn't have a word document open that he spent an hour on it because i'm going to probably lose his data that's your choice on help desk and i'm going to also use the slash m which will give me the right to connect to a remote computer so remember i told you about sequential processing now winrs only allows me to execute one command and in this case i'm going to execute check desk for john with the ampersand symbol on the command line i could execute check disk the ampersand and then execute shutdown which i normally couldn't do because the amper sign will allow me to sequentially process on the command line the command interpreter is going to see that ampersand say oh he finished command a let's go ahead and do command b and if i put another ampersand i could do command c i hope that's opening your eyes to some cool things you could do to solving problems in your workplace all right so let's get into the the work over here i've got john's laptop running i've got a pdf reader running in the background so that we have to close out that open application i went ahead and ran process explorer so as we execute against john's laptop you can actually see what's going on over here and then over here is my administrative workstation and i'm going to execute the following command winrs forward slash remote colon and then the net bias name for that computer and then i went slash user name put in the admin account and i'm going to execute my only command shell utility which is check disk and i've asked it to do it on volume c and i've asked it to fix any errors that it wants to fix now we know what'll happen it'll simply come back and say um i can't do it right now i'll have to do this upon the next reboot well i don't want to be there all day and i don't want to walk up to the 10th floor so here's where i'm going to get my ampersand signal or i'm going to do conditional processing i want this one to finish and upon finishing check disk go ahead i'm telling the command interpreter with this symbol go ahead and run shutdown to the same computer reboot it and go ahead and force any applications close so when i execute it against this computer we should see all that take place let's go it's now prompting me for my password it's going to execute it against the box if you look over there the green went win rs host it's launched the cmd over here and this will happen pretty quickly so we'll slow it down a little bit with video magic now notice it's a remote shell so it sent back the information back to my command shell and it says check disk cannot run because the volume is in use by another process well with a windows operating system would you like to schedule this volume to be checked at the next system restart now i'm going to send my yes back to the remote computer and we're going to get this done so i'm going to say yes now what's going to happen is check disk will be done the command interpreter will then come up and look at that amper sign and say oh there's another command to do shutdown so let's watch we'll say yes enter so that goes back information still comes back to me from the command shell you can see here we're getting ready to reboot john's laptop on the 10th floor it should close out foxit which is the reader in the background and reboot that computer will also watch it as it starts to correct any check desk errors upon reboot so here we go restarting now is when check this can actually begin to do some repairs on the volume as it begins the reboot process and we can see john the board members laptop rebooting and coming back up here you see we're actually running check disk so that is exactly what we wanted to do on john's computer remotely so that we can correct any mistakes on his file system and boot up and then see if that solved our problem and we're complete so now john can log on and validate is the problem been resolved now keep in mind when rs allows you to go to a remote computer and execute one command shell utility but i showed you how we can use the ampersand and the command interpreter will see that character on the command line and say okay when i finish this one i'll go ahead and do this one very cool and i could use another one and say okay but do this one and you get it but there's more if i use two ampersand symbols i could do command one is successful then command two runs so if you notice on my row there my top row if i use two ampersands then it will say if command one is successful then and only then command two is run i could also use two vertical bars or two pipe symbols and if command one fails then command two runs so now i'm getting conditional processing of my commands so this is very powerful so look at my chart down here under group sets of commands notice this is getting cool here i've got command three is run only if command one and two are successful look at my command syntax command one it's in parentheses so i've got parentheses command one ampersand which means command one then command two parentheses two amper signs which is the conditional part and then command three on all one command line command interpreter then we'll say command three is run only if one and two are successful i hope that's just giving you all kinds of cool ideas to solve your daily problems and again at the bottom we could do command two and three run only if command one fails and you can see the syntax i'm using just a great addition to your tool set for solving everyday problems in the workplace now there will be some of you that will need more than just one or two commands and a conditional processing what you need is then maybe a batch file to execute and you can do a lot more with just a batch file you can run windows scripting using c scripts or w scripts which give you a powerful environment to do even more things alright last but not least you get errors in command line how do i deal with these errors in command line how do i figure out what they're telling me many times you're working in command line and you get a funky error message and you really need to know what does that mean so you can also use the microsoft error lookup tool just make sure you keep it up to date it changes version on a regular basis so you can download that and install and it will help you determine what your error code is if you run debugging tools for windows there's a number of ways that you can also get your error messages there's also a pdf or doc file that you can download over 497 pages of searchable error messages so you've got lots of things to look up those errors here's an example of using the error tool it's error underscore 6.4.5.exe you put in the hexadecimal code of that error and it gives you some idea as to what generated that error [Music] you
Info
Channel: TechsavvyProductions
Views: 5,272
Rating: undefined out of 5
Keywords:
Id: o-nIM6LRkjM
Channel Id: undefined
Length: 22min 42sec (1362 seconds)
Published: Thu May 26 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.