Working with Strings and Regular Expressions in PowerShell

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
good morning everybody and welcome to our video on strings and regular expressions in Powershell uh once again my name is Mike and welcome to my Channel or welcome back to my channel so if you have not subscribed yet I'd really appreciate it if you could um so that way you get notifications whenever I drop a new video and also it helps on my subscriber count which allows me to have some more options when it comes to customizing what I can do with the channel right so if you could that would be awesome so let's uh let's get into it here so let me switch over to my lab environment and talk about about here what we're going to be doing with strings so strings represent basically pieces of text right and if you want to call it alphanumeric text uh stuff you could type in a notepad uh you know things like that and they're very popular for properties on a lot of objects and Powershell so like if for instance if I type get service uh maybe just grab the bit service here uh so we could see you know some output that comes back and if I take and type that over to get member we can look at some of the properties here and notice that some of them are in string format so string is an object out of the.net framework it's system.string and we can see here like display name machine name uh service name okay those are all in string format or or they're string objects I guess I should say right so with that we should be able or we should have in our our skill set here the ability to manipulate those strings so to kind of have a look at that we can put just a string into the pipeline and see what we get so the easiest way to do that is to just put in quotes here some text and if you hit enter on that believe it or not I mean you might be like well it just outputs what you typed yeah but it actually took this put it into powershells pipeline went through what normally happens with pipeline objects and then kicks it out to the screen because we didn't tell it what else to do with it so if you have an object in the pipeline by default if it doesn't know what else to do with it it outputs it to the screen so if I take this and pipe it to get member you'll see that just you know a couple things in in quotes here uh you'll see it does produce a string object all right now not to say that there's a lot to do with the object uh it really only has one property okay which is length so the length is just how many characters are in the string so in this case if I'm just doing my name that would be a length of 4. but there's a tremendous amount of methods that are available here okay so we're not we're not going to talk about all of these they'll be here all day uh but there's a lot of methods here that you could utilize with that string object okay so probably again the easiest way to work it is to take the string object and just put it in a variable so maybe I'll say dollar name equals Mike so now what's in dollar name is in fact that string object so if I pipe it to get member again I could see you know what's in here is a string object and I say a string object like singular you could also take and send this over to measure object right and you can see again you get a value of one all right so again there's one string object in here all right so now let's say I want to utilize some of these properties and methods so if I take dollar name and I look at length notice I get a value of 4 because that matches the length of the string how many characters are in there right and there's again there's a whole bunch of other methods available so for instance uh let's use one of the methods here let's use uh two upper uh uh on Tab complete to Upper right and what does that do it took the string and sent it all to uppercase right so that's using this two upper method right here okay there's also a substring method um substring and so let's say I want to start at the beginning of the strings that would be the zero and give me two characters all right so so this method takes those arguments where do you want to start and how many characters do you want I end notice out of the full string I get just those two right so so you could experiment with all of these different methods that are here all right so for instance like there's a replace method um so if I wanted to use that one we could do a replace uh what do I want to replace let's maybe replace the m uh with I don't know maybe uh an a something like that right and oh no sorry that didn't match capital M there we go all right so there we go and so not to say you'd want to do that but you know again you could use the the replace there the replace method uh there's also a contains method uh which you could potentially use to verify if something's actually in there right so let's say I don't know what's in dollar name and I'd like to know hey is is Mike in there and you can see it's true and if I put something else Mike got John uh that's not in there all right now what is interesting about contains though uh is if you use the contains method it is case sensitive okay so it doesn't tell you that right up front that's just kind of the experimenting to go along with it all right now with the methods though these are not let's say the only ways of manipulating the string object right so so I mean they are there don't get me wrong uh but there's also a bunch of other operators that you could use okay so like for instance you know you may have gotten used to let's say if I wanted to do something like uh get service and maybe bring this over to where object let's say property let's maybe do status and then equal and then let's say we want the ones that are running right so this would be a comparison operator so Dash EQ right there's and there's many of them so you could do n e for not equal uh GT for greater than LT for less than l e for less than or equal to uh g e for greater than or equal to uh and if we wanted to do a like uh like would allow me to work with properties and string and maybe use like wild cards or something right so these are all comparison operators you use them in commandlets where you're going to do filtering all right so so they're fairly common you know when we're working with that now with strings strings also have uh comparison operators as well like if you notice I'm using contains here well there's also a contains operator so I could say contains and then put that into there and away we go all right so I could use the operator now what's interesting you might be thinking well you know why would I want to use the operator the methods there you know why I have two different things well the contains operator actually doesn't care about the case so when you see that the contains operator it is not case sensitive however like most operators if you put a c in front of it it does make it case sensitive I also notice that doesn't like that and now it does all right so notice now that outputted to true all right so you could use that so there's again a few operators there now let's say I wanted to go the opposite way so let's say so let me just blank this let's put mic in dollar name guys so you could use the in operator if you you know want to just do the comparison the other way guy itself so you have contains on one side and you have in the other way okay so it's basically like is this value in this variable whereas does this variable contain this value right so it's two I guess two different ways of just looking at it in essence the same thing all right now what is interesting though about a lot of these string comp operators here is in a lot of cases they're looking at the entire string so like let's say for instance if I recast name let's say name equals uh my name is Mike all right so now that is still considered a single string right so if I you know look at Dollar name take that over to measure object okay it's still one string in there of which my name is just a part of that right so there's more characters there than just the four that make up my name so if I were to do something like dollar name uh contains uh Mike and we'll even you know give it the benefit of the doubt here and even maybe give it all all that we can right notice I get the false right because contains is doing a full match of a string not a partial match and you would get the same thing if you tried in as well so it's looking for complete matches not partial matches all right so we will uh if we if we wanted to get partial matches uh we could bring in an operator called match um and so if I say hey is Mike uh in there notice I get a true all right now with match you could also maybe try the lowercase and see how it's still matching as well so magic gives you these partial matches if you wanted to do that all right okay so now let's say um oh and we could also do replace as well um so let's do replace and we want to replace mic with uh which we replace Mike with how about uh John all right and so we could see that I've taken this this output I haven't recast the variable by the way I just took the output of it and replaced the these characters with these characters so you can now see my name is John all right so now let's say I wanted to do something with this right so let's say for instance let's maybe do like get service name bits actually let's let's grab a bunch let's maybe do B Star so that gives me a few services that that are here okay uh so now let's say for instance actually it's not a lot yeah and we'll go with it so let's say for instance um I see these names and maybe for whatever reason I want to convert them to uppercase right maybe right so what I could do is I can bring this over uh to let's say select object and we'll do some calculated properties so I I want to keep status as is so we'll list that uh then with name we'll do something with that so let's do a calculated property where the uh the actual property is going to be called name all right so we're just keeping the same whatever it's labeled as we're just keeping that and then a semicolon and then the expression is going to go in its own script block so inside of a script block I can reference the object by the variable dollar underscore or dollar PS item either way then a DOT and then I want to grab the name property and maybe we'll do the two the two upper method all right so that'll fix the the name Properties or just basically making a new version of name um and then we'll do a comma and then we want the display name property right so there we go so that converted just this one over uh using all uppercase right if I wanted to do that all right so uh so we have that ability now uh we could also let's say if I didn't want see the thing would select object is by doing these calculated properties you're working with the strings that are in a property of the original object that was in the pipeline okay so like if I you know started off with get service here or pipe this to get member I could see I'm working with a service controller all right so after select object you know there's the output if I pipe it to get member notice still working with a service controller okay so with select object specifically with using property uh you're keeping the original object in the pipeline I just used a method on the the name property which happened to be in string format right so I'm just using uh one of the string Methods on a property that's on the object in the pipeline but now if I wanted to do something with the string that was in the name property and just keep that string and got and get rid of everything else get rid of everything else in the service controller um I like to use a different commandlet for that all right so what I could do is I could use uh for each object so instead of Select object we'll use for each object and we'll use a process parameter because I want to use a script block and so inside the script block I can reference the object that's in the pipeline grab the name property and do the two upper method on it okay so now this time I look at the output if I pipe this to get member and notice you know what it's putting into the pipeline it's just string the original service controller has been blown away right so this produced a service controller object passed it over to this um and with what for each object does when you give it a property it grabs whatever kind of whatever type of object is in the property which in this case name is a string object puts that into the pipeline okay and then I told it to take those string objects and convert them to uppercase all right so that allows me to kind of work the pipeline that way okay so with uh so with select object you could use calculated properties to keep the original object in the pipeline and just to mess with a property that happened to be in string format okay but again you're keeping the original object that was in the pipeline and with for each object you're removing the object that was in the pipeline and replacing it with whatever in this case whatever strings you know we're in the name property all right so that allows me to work with that all right so that's a couple different ways we could manipulate this if we wanted to okay manipulation you know with with string objects here now when you are going to get into manipulation of string objects though in some cases it's not enough to just use uh some of the simple things that that we've shown here right so like for instance uh let's say if I had name here and I did replace right so so that was a pretty easy way to manipulate a string but it's not the it's not always going to be the most thorough way to do something right um so so where it comes into like like imagine if you're grabbing you're grabbing objects from somewhere right so so maybe I've got let's make a variable pi or personally identify identifiable info per pii I always call it Pi for short and let's say I put in there a social security number I apologize if that's anybody's social security number I hope it's not okay but let's say I have that in there right and I want to take that variable and I want to see if it has a social security number in it now if you're going to do like a contains not a c contains let's just do it contains uh if you're going to do a contains you have to match the exact number you know in order to get a true out of it right so let's say it was you know I was matching on a different number right and notice that comes back with false so programs that look for this kind of information they're not looking at it by hey let's run every possible social security number known known to mankind here and see if we get a match so it's not like I'm running like a billion different contains operations to see if there's a social security number in there that's not you know that's not what programs do like if you have an email program a document Management program a database program that's looking for Social Security numbers or bank account numbers or driver's license numbers or whatever that's not how they do it so there is an entire language that is reserved for looking at patterns in string data okay so patterns and Text data okay and we call this regular expressions or regex r-e-g-e-x all right so regular Expressions is the full proper word for it right so I'm going to talk a little bit about that here I'm not going to cover everything about regular Expressions because literally this could be like a five day video like 40 hours so if you ever wanted to learn a lot more about regular Expressions uh probably the website that I would recommend you just kind of Google search for regular Expressions you'll come out eventually uh to let's see uh bing does not want to show that interesting um Regular expressions info there you go this one right here okay so this website regular Dash Expressions dot info and if you go to tutorial uh you have probably the most detailed if you look kind of on the left side here you have the most detailed free tutorial on regex that I've ever found I have somebody else knows of one that's better uh you're you're welcome to it right so or welcome to mention it you know in the chat for other people to have a look at but um but yeah so this is a fairly popular one a website that that you could use another one just to have um regex 101 is also a fairly good one to know about uh because it does have a quick reference down here uh but it also allows you to put in text Tech test strings and a regular expression query and see if they match or have an idea of how they're matching all right so that could be of use as well right so those would be two websites that I'd probably say you know you'd probably want to know about so let me switch back to my slide here um let's go back to PowerPoint and let me index the slide here and so with regular Expressions this could kind of be a just a Joe Joe Schmo simple cheat sheet if you wanted it uh where you're looking at uh what some of the symbols are okay so like a period for one of any character so that's like a wild card uh and then a plus sign a one or more of the preceding character and asterisk zero or one of the preceding character uh question mark zero or one of any character uh a backslash and a little W any word character uh backslash capital W any non-word character uh Little D for digit capital D for non-digit over on this side you have um the the carrot that's uh shift six on your keyboard I think that's called a carrot uh start of string a backslash a little s for space character backslash capital S for non-space uh any named characters uh any characters in a Range so this one here would match any character that would be a b c d e or F uh then you've got oh one to three so this would uh allow a preview of the previous character I can allow one or three of them one through three okay and then a dollar sign kind of representing the end of the string all right so what can we utilize this with well the the operator that I showed you uh at the very end there when I was matching on on the name so if I did dollar name Dash match and I said Mike uh I had mentioned that this does partial matching right so again if I look at Dollar name this is what's currently in there right so with match it matched partial names now you can also use regular expressions with match so if for instance with with name here if I do match um hey is there a word character in there oh why yes there is all right um is there um forward characters in there why Shore there is right so so it can do partial matches that way all right so I could also do something like if I want to match the literal characters um my name is and then four characters hey that matches as well all right and if I want to make let's say I don't want to do it like that let's say I'm looking for a character and then I'll say I'm looking for uh four of them right so hey there's this character find four of this character all right so that might be a better way than doing like something like this all right so I could do you know something along those lines all right so that gives me the ability to match up using regular Expressions if I wanted to do that so now let's let's bring this back to our variable with the social security number in it and let's set this back to here and let's do dollar pii and there's our social security number now even though it might be numbers uh because it was put in here as double quotes that would still be considered a string object right so if I take this and pipe it to get member um you can see again I'm working with string so string will have alpha numeric characters in it so numbers are going to be allowed so uh so now let's say I want to see if that has a social security number in it so I could do a match and what's a social security number look like well it's got a number a number a number then a dash then another couple numbers Dash then four numbers right so does that match why yes it does hey there's a social security number in there okay now that's probably the easiest way to do it right so now let's say let's say though we wanted to clean this up a little bit right let's make the regex look a little bit easier so maybe on this last one here we'll say hey it will have four and here it'll have two right over here it'll have three all right so something like that all right so notice that gives me a match right now here's where though uh we need to get maybe a little fancier with the regex right so let's say for instance here let me put the the social security number out in quotes here so that way we can so we're not using a variable so let's do one two three four five six seven eight nine all right so does that match yes it does right so now me being the enterprising sort that I am well maybe I'll I'll con try to confuse you know the thing that's looking for Social Security numbers and I'll put a space there instead you know and now notice the regex doesn't match okay so so my regex is relying on dashes to be there right it's literally looking for that exact character right a dash so what I could do with the regex is that's where I could do a character set so in in brackets I could say hey the next character is going to be either a space or a dash and then over here I could do the same thing all right so it's either going to be a space or a dash all right oops there you go so something like that and notice that that now matches um and if I fix the social security number again so let me put the dashes back in I could do something like that right all right so that covers me for if someone decides to to make it with spaces instead of dashes well okay I I could still ruin this though I I could still ruin this so how can I ruin it just don't put either right and so I hope that doesn't match now so remember let me flip back to my slide here uh remember that there is one of these see this this asterisk character here C 0 or 1 of the preceding character right so there might be a space or a dash or there might not so that's the one I want to utilize here right so let's go back to the lab and after the the brackets there where I'm looking for the next character would either be a space or a dash I'm going to put a wild card there an asterisk there so that would mean 0 or 1. so there could be a space or a Dash as a character or Nothing at All and then let's go fix that over here as well that right and now notice that matches right so and let me fix it or let me fix it let's change the text test the test string notice oops that's me typo and my bad hold on there we go so that matches and then with spaces now you notice that that matches as well guys so this regex can find a social security number and this format into this format or this format notice all of them returned true all right so that could be a way of utilizing you know that particular aspect of it so so you're only you know you can match whatever you could identify the regex query string as right now what might be some other possible uses of this stuff well like let's say for instance uh let's say I go let's say to active directories let's let's say you know get 80 user um filter star all right so I'm going to list out all of my users here all right now remember that uh with get 80 user it only returns 10 properties it doesn't return all of the properties uh so we see you know who's here to work with all right so I have a John Smith account I actually have an account for myself too all right um Jeff uh let's see what else do I have the Kerberos account guest administrator I think I've got a couple intern accounts in here as well all right oh user one user two and turn one and turn two yeah I'm very original with my names all right so I had a uh I had a project once uh or a consulting job where I needed to take a bunch of information out of a customer's active directory and put it into a different system um so as like some type of like HR System so basically we needed to take uh the users out of active directory and Export out to a CSV file and we needed very specific information from it all right um that wasn't normally there by default Okay so so what we needed was I'm not going to go over everything but but let's say we needed like the name the department uh the OU where the object was in and let's say maybe a few other things right so if you look at though like just a regular user um so let's say I do identity and uh jsonth right so if you just take like one user here and if I look at all of the properties on it let's let's Force active directory to bring back all of the the the properties here if I could spell property star so if I look at all of the properties uh this user happens to be in the user's container um so that's where they're at so let's say that's what I want to return right users um and if I kind of go look there's there's nothing that just comes right out and says the OU is is users or the container is users right there's we look at all of these properties there's not one that just has that value in it I I mean there's ones that have it but it's got a whole bunch of extra stuff to go along with it all right so that's not really what I'm looking for so the one that I always found to be the closest if I just want the OU is canonical name because that has the name of your domain then the OU or container and then like the actual user themselves right so so I would want this piece and I want to toss out the rest let's say okay so let's say that's you know what what I'm looking for all right now again how do I identify just that piece well regex could help you with that all right so so that might be what I want to pay attention to right you know something along something along those lines all right so so that might be you know we'll take canonical name and do a calculated property out of it to return just let's say the OU part of the actual uh of the actual value okay so so let's say you know we want to do that right so let's let's first of all go grab all the users and then let's bring this over um oop and I need to tell it to return that property canonical name and then bring that over to like select object and then property about we want uh name and canonical name all right so there's where everybody lives right um so in this case um I wanted to you know keep like this part you know and get rid of the beginning and you know get rid of the end like I want to make a property called um OU all right so uh what we would need to do is we would need to identify uh the different parts of the string okay so so like let's say for instance um I want to let's grab this just to work with so let's put that in quotes all right and we want to again get this piece out of it all right so what we're going to do is first of all um we could do a replace uh replace will also allow me to use regular Expressions it's kind of cool so if I want to say replace uh chassytack.com uh with with I don't know with uh the letter a notice how that works right now one of the neat things we'll replace though is you could tell it to replace with nothing so notice I could just kind of remove it right out from there okay at least that part of the string all right but that's not really getting the job done here so what we want is we want to identify uh the string in regex right so so we're going to start at let's say the beginning of the string I will take any character a multiple of them all right and then we're going to come to a a forward slash and then we have um any character multiple of them and then we've got another forward slash and then any character a multiple of that all right um and then maybe to the end of the string all right so so notice um actually I should have probably done a match on that okay so that identifies as true all right um so now let's say uh I want to grab the piece that I want so with replace I'm going to take the piece that represents like the the thing in the middle between the backslashes and I'm going to put a set of parentheses around it okay so this is what's called making a capture group in regex so I could tell it the whole thing represents one like capture if you will like captured the whole string and then this inside the parentheses represents a different capture so notice that that's inside of these uh these forward slashes here so I want to grab everything that's between those forward slashes um so now how do I call that uh in the replace I call a capture Group by using a single quote rather than a double and then I call I want capture group one and that is how you call a capture group it also uses a dollar sign but it's not a variable in Powershell it's a capture group in regex and notice I identified that piece okay so that allows me to take this whole string here and then just select the piece that I want out of it right so that could be used to kind of make this OU property that I want all right so let's say here let's uh let's bring back up the select right so for select object um let's say let me carriage return this down to the ah hold on here trying to make this so it's easier for you guys to see it let's do the carried return and then we'll put the select object on its own line so property we wanted to keep name and then we're going to make a calculated property so the name of our calculated property is going to be OU and then semicolon and then the expression we're going to grab the objects canonical name and we'll do a replace with uh this right here and there we go all right so so we have um users and we have interns that's exactly let's say what I was looking for right so that allows me oh and sales so Jeff Kent was in the sale so year so that allowed me to pick that one up as well all right so that uh that allows me to get you know what we were looking for here okay now I would have to get a little more fancy with the regex uh because like in sales here uh this is grabbing whatever the most immediate OU is so notice in turn one and intern 2 uh show is interns and Jeff Kent who is in sales so that's just grabbing um you know so so again we're taking this we're grabbing that immediate piece right there all right um so again that's the antenna what I wanted if for whatever reason down here if I wanted you know this text string to match on sales I would have to get into using operators that were not uh greedy as in grabbing as much as they possibly could um so so that's when you look at some of these like you know these these ones one or you know uh zero or one or more of a character uh in a lot of cases regex is greedy about it it'll grab as much as it can so notice like here it blew through the first forward slash and stopped here it grabbed as much as it could okay so that's what's called a greedy operator so you could actually take these wild cards here and make them not a greedy by putting a question mark after them all right so so that's uh what you might want to research a little more into that all right so now so last thing that I wanted to show here is let's say for instance we wanted to use regex to create or we wanted to create let's say users from a CSV file so I have ready made up here um just kind of a demo CSV file uh users.csv so if I open it up I have just a bunch of random names that I got from a random name generator on the internet um so if this is anybody's name I apologize uh but it showed up in a random name generator so I have the this information let's say I got this from like I don't know like HR or something or my registrar system or whatever and I want to make users in active directory out of it okay so first of all I could take that file and I can bring it into Powershell by using a get content right so that's users.csv now um actually not get content that brings the text in but I actually want objects so I'm going to do an import CSV um to do this there we go so import CSV and I I have a user uh here I have a department and I have a city right so so it actually made objects out of it if I pipe it to get member you can see it's a PS custom object I've got City department and user all right or what I have available now let's say in my environment um I have the need to make the users and the format of first initial last name okay so let's say that's what I wanted to do right first initial last name now obviously that's not in this format here right but can I turn it into that you know and the answer is yes I can't okay so ultimately what I want to do is I want to kind of change this over and I want to match it up with uh the the properties on new 80 user so if I look at like the help on new 80 user um so I need to supply a name that's the mandatory parameter um I have a I have uh let's see where is it where is it uh Sam account name even though that that's that's seen as an optional parameter it pretty much is mandatory right you need to specify the same account name so usually I just send them to the same um and then we might also want uh let's see where is it in the list here uh display name all right so I might also want that right so name Sam account name display name um and we had city right side the city that's that's pretty much in just a city so I don't need to change that at all uh and Department um department so that's like right there right so again I don't have to change that either so the data you know in here we have city right so that matches that we have Department that matches that and then user that one I'm gonna need to change right I'm going to need to take what the data that's in there and make a name property uh display name property and a SAM account name property so that's what I need to do to that data all right so can I uh potentially get away with this well let's see all right let's see so first of all just to make it easier for everyone I'm just going to take this and put it into the ISE just so I could have the text all out here so let's see colon demo okay so first of all um our first uh we're gonna do uh an import CSV uh where we're grabbing uh users.csv right so if I run to the just that piece bye that brings everybody in away you go all right so now we want to bring this over to select select object and we're going to be doing a few things to this so so we're going to do some properties here and the first property we wanted uh name all right so remember how the names looked right here okay so basically using this concept of capture groups what I want to do is I want to isolate the last name the first initial and then the rest of the first name all right until the end of the string right so that's you know basically what uh what I'm what I'm looking for all right now um so that would mean I get a bunch of text uh then a comma space then a single word character and then a bunch of text right is basically what I'm going to be isolating off of here all right so with uh with select object let me bring this down onto its own line here just so it's easier to read so select object property so we're going to make a calculated property uh let's do n equals we're going to call this name and then semicolon and then the expression we're going to grab the object in the pipeline uh the original stuff is in a property called user so I'm going to use dollar user and then we'll do a replace so in the replace for the regex we're starting at the beginning of the string we're grabbing any character multiple of them uh then a comma space a word character and then any character multiple of them all right so that's my uh that's identifying uh the pieces now what do I want to capture out of that so I'm going to take this part here and so that would isolate the last name this would isolate the first initial and then this would isolate the rest of the first name so in my replace I'm going to use again single quotes because I have to call dollar signs I want first initial last name so that would be capture group 2 and capture group one all right is what I'm going to do there okay so let me take this and run it just to make sure that this works and notice it did work right see Jay Vasquez D Nicholson R Phelps R Hutchinson a Hicks right so that part worked cool so now let's do a comma and let's make another property I'm going to just bring that down to the next line here uh just so it's easier to look at because I'm basically going to duplicate a lot of what was already there so in this case we're making a property called Sam account name and I also want that one to look the same right so let's run to this and cool deal all right so notice we've got a property called name and then same account name so now I want a property called display name so again I'm going to just duplicate a lot of this and change this one out for display name now with display name I want something different I want the first name space then the last name so what I'm going to do in my replace here the first name would be capture group two right so this is capture group one this is capture group two and this is capture group three okay so again they're each in their own sets of parentheses so I want capture group 2 and capture group three that would be the first name and then a space and then capture group one that would be the last name all right so let's see if that works run it and there we go so name same account name and display name all right so kind of cool right that you could take you know this this original string and then look at the different ways I can manipulate it right so uh so let's see so we also wanted let's continue here we wanted City we want to keep city as is and we wanted uh Department all right so that should finish up what I needed to do to prepare the data so there we go um so name same account names my name City department now you might be wondering well well Mike when you ran that when it did it when hold on when it did it up here when you just had name Sam account name and display name it just did it did a table right and then when you added it went to this well what happens with Powershell because I didn't tell it how else to do the data if there's an object in the pipeline that has four properties or less Powershell will display it in table format and if there's an object in the pipeline with five or more properties Powershell will display it as a list again by default there's plenty of ways to to manipulate Powershell to do something else but that's what's known as just default outputting all right so anyway so that's how you could use a regex here to manipulate a CSV file you know that has the information in it right so this is my original CSV and then here's the code here that could take the data that was in the user property in that CSV and make a name make the same account name make a display name for what we wanted to do and again this would be all set now for me to now be able to pipe this right over to you know new 80 user and literally have this you know create some users an inactive directory in fact let me just see if it might blow up but let's see I oh yeah okay because I'm not running this I'm running this in a regular ISE hold on hold on let me uh let me let me run to this and an administrative level ISE because I need admin rights obviously to create users so let's dump that code in there uh the formatting could be better again I just tried to list each property kind of on its own line just to make it be a little better but let's take this and run it all right oh and I have one last thing CD c colon demo all right let's try that again there we go so if I were to go now look I have all these extra users that I that I don't want also helps so I can open the right tool here all right and yeah so there's Hicks there's Nicholson um there's uh Vasquez Phelps Davidson and again if I open any one of those notice the display name um and we've got the uh the Sam account name value set correctly there all right so anyway so that's that is that so any questions uh feel free to leave something in the chat um again if you appreciate the video or the other ones that I've posted up on my Channel please please uh subscribe if you could if you already are no problem then don't worry about it so I'll leave you with that and uh thanks for watching and we will see you in the next video
Info
Channel: Chasse TAC
Views: 1,037
Rating: undefined out of 5
Keywords:
Id: dw0LDkllwjY
Channel Id: undefined
Length: 56min 28sec (3388 seconds)
Published: Tue May 30 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.