PowerShell Remoting to One to Many Sessions with Example Script

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome back in this short lecture we will be learning similar things what we have done so far with the invoke command and the pa session similar things we would be doing but a little a bit advanced with uh within a script where we would like to write so let's let's open the isc uh in this isc uh you can check out here that the this blank script now for now but what we can do is we wanted to get the computers the computers names we would like to input into a text file so what i've done is i have actually created a text file let me show you the text file by opening notepad like it it's in the root of the c drive let me open that file so here at the root of my c drive which is here the c column i have a computers so this is where i have placed my computer names one by one now uh now i would like to see or i would like to get the computers automatically loaded in my powershell commands to do that what i'm going to do is i'm going to define a variable again called a computer uh like computers and then i'm going to setting you to equine to i want the file uh should be read or should be loaded to the computer's variable so to do that i have to get the content from the path so the path would be in this case it would be c colon uh computers uh is the path so which we have given here so i need to give has in a double quote so that it knows that the proper path now uh what i have to do is i wanted this the files whatever it is there inside this as a line by line i need to read as a line by line so for that for that i need to use as each for each of uh line up that's each uh each of my line for example i need to define any of the value like here uh the line is the one which i can see in the variable call computers so here the value should be reading now so what would happen is here everything is a reading from this text file one by one line by line now here my other script which is coming out in this block uh for example i want to i want to do some i want to invoke some kind of commands so let's type invoke command specific so and woke sorry yeah invoke uh it's not the assumed so anyway command harvey the computer name so in this case the computer name is again which is coming from the line because uh line by line what we wanted to read and from the script block uh either you create either you give it or not it doesn't matter script block but you can you know put any kind of command here we'll have to put here as the get service specific service uh by typing in hyphen service with the bit specific so if i start executing this it is actually uh pulling out the values from these two of the computers that's good so the problem is as i said in the uh previous lectures uh we we talked about the invoke command the drawback of the invoke command where once the session is closed it's gonna close that so how would i maintain a persistent connection so for that uh as you know already we need to use ps session so ultimately we have to depend on the p session so for that uh we're gonna actually do a little bit of modifying this existing script or this script as you know uh for writing of any of the uh uh session like in a peer session how we we just go with the new peer session and the computer name uh that's what we tried so what what we're gonna do is now i'm gonna define this into a different variable that's how we tried in the previous uh previous lectures also so similar thing we can try like maybe here uh session e client so this should be put it into a variable so the new session is coming here as the computer so instead of the here the value of the computer i would actually put it here computers so that it's actually going to execute here so what are the computers are coming up is the computers are coming from this content where it has these value and the later point the value whatever we are trying to do on the computers we are going to line by line during this session so now this looks good how we can start the session by running this script so it should be running this so since i have not saved it is showing all this information and it has started so just you know find out whether really are there any sessions are still maintained or not as i said you know get session or the environment or the variable what we have used so in this case this is already maintaining still available so this is how you would be modifying a little bit uh further to advance your scripting skills and get it benefited out of it i hope this is useful for you thank you for watching this
Info
Channel: Paddy Maddy
Views: 3,960
Rating: undefined out of 5
Keywords: PaddyMaddy, Powershell training, Get-Content, invoke-command, powershell script, windows powershell, powershell scripting for beginners, How to Run PowerShell Script on Remote Computer, Connecting to multiple computers with Invoke-Command, Run Powershell Script on Remote Computers, Running Remote Commands, powershell, windowsPowershell
Id: ggeCxJ4LOJg
Channel Id: undefined
Length: 5min 23sec (323 seconds)
Published: Wed Sep 29 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.