 All right. Hello everybody. My name is John Hammond. Welcome back in the YouTube video We're looking at PowerShell video number four in the series checking out variables and some data types and ps drives So let's dive into it. I'm gonna fire up PowerShell Alrighty, there we go. So What we need to do because we are so close to scripting and trying to do some really cool automated PowerShell stuff But we need to dive back into what we mentioned just briefly in the other video on what variables are and what we can do with them So you've probably seen variables in tons of other languages, right? PowerShell has support for them because it's a language So the prefix that we need to specify this is a variable within PowerShell Is that simple dollar sign symbol and we can call a variable literally anything in fact I'll just call mine the word anything and we can set that equal to with their equal sign any value that we want so I'll just use a simple string here the classic and Now that is created and available throughout the rest of the scope that we're gonna be using PowerShell for So I could go ahead and echo that out. Remember echo is an alias for right-host Profile I don't know why I'm thinking about that that was just the last video our variable that we just created it was Anything right if we were to actually use a variable that didn't exist It would just return nothing for us because that variable we haven't created it We haven't set a value to that it's there as nothing as just an empty string and a string Is that bit of text or kind of English or variable? Variables wrong word because that is in fact what we're using here at the dollar sign The value doesn't need to just be English text as a string It could be maybe bytes or kind of opcodes or any other letters that we might end up using or digits, etc etc Or it could be something else like an integer right we could just check out Integer we can set that to 100 or negative 100 or even a decimal sort of thing like Negative 10.1 However, that's no longer an integer right what is the type of that we can find out by any of the variables that we create By using that kind of C style syntax my mouse is just sitting here annoying us. I'm sorry we had that integer and then if we had a period and that Control space to help us autocomplete or suggest what we could be using what we might want to do with that We could see some of this information. We could run a get type method or kind of a function relative to that object Right because PowerShell is object oriented for us with all those C sharp and dot net kind of back and stuff that we see when we Use command. Let's like get child item or other things get type We'll return the type for us and we can actually convert it to other types We could to string or to integer or to decimal, etc, etc So let's check out what we're working with here. This is get type and Because it's a method or a function called what we're using it's going to have those two parentheses that will kind of invoke it Or call that so opening parentheses and it doesn't take any arguments or so we saw And that's a handy thing that we can actually see when we're looking at that helpful autocomplete suggestion stuff inside of PowerShell for us So get type doesn't take any arguments and if we return that is in fact now a double It's not a decimal number an integer. There's actually a lot of properties that comes with this which is really cool So if you wanted to you could get type and then as we've done earlier that FL star or format list to now retrieve Everything that came out of it. There's a lot of information. This can hold for us Scrolling through a lot of nonsense some of it might be useful to us But it actually has some fields and other information that might be valuable So those are some of the data types and the types of variables We could actually end up supplying or using with our values inside of our variables I'm not going to be able to cover all of them So what I want to show you if I hop over to my Firefox over here I wanted to bring this down so we can see it if I actually get it on the right screen. Thank you Okay, this is a SS64.com Which is an awesome resource for sort of a command line and system languages in this case It says this link is a SS64 slash PS for PowerShell and then hyphen syntax I'm sorry forward slash syntax hyphen data types dot HTML So we could use a string type or a character or bite or integer or longer boolean or decimal or any of those things that we've Already saw or some other neat things like XML or an array or a hash table kind of like an associative array or dictionary And it actually actually has some other kind of built-in variables true and false Which are those boolean values that we're used to Python you see them with the capital T true or capital F false In this case, it's just dollar sign in the lower case for us And you can actually cast some of these variables to that specific type or to note This is what it's actually going to be so that way when I say enter a number with like a kind of a read-in command It won't store that value as a string. We can specify. Hey, I actually wanted to be an integer I really want to get that real value. You can see they do that as an example here int around the string 0064 so that's really known as a number 64 or we can take the integer of false Which will just be zero etc. Or we can even create bytes based off of the 0x syntax And that's kind of neat and interesting again. You can define these with that declaration with that type kind of attached to the variable int even before the value or On this side, however When deciding to value to a variable you can cast either side of the expression. So this is not quite the same as that interesting arrays and They even have some data types like date or things that power show will give us that are much more interesting So let me show you that while we were able to run it just off of our anything variable, right? We had anything that was a string so far run get type on that You can see okay. That is a string. We can get the name out of that or Dot name just get that value But there's another command let in power shell that will show us get types and get type data That's the full command let there that'll return a ton of stuff And we can scroll through this and see some interesting things And these are kind of variable types that power shell has already created for us Or it knows just because it's managing our computer in a programmatic way, right? We have a system diagnostics process like even a process itself that you might see within Kind of get process as a commandlet. Let's try that make sure I'm not talking to my ear. There's a ton of stuff Let's go ahead and select index Let's get first one good and Let's go ahead and run just get type off of that So I'm gonna wrap that in parentheses so I can check get type and you can see the name is a process If you wanted to kind of get more information out of that, I think it's a full name. Is that right? Yeah, system diagnostics process and that's the string that we just saw when we ran get type data There are a lot of really cool ones with this. There is a system.net mail mail address There's one for IP addresses And if you actually wanted to filter some of this and see what is it really going to show me or what are some My options for some specific kinds of data like a system.net IP address will have PowerShell Automatically figure out whether or not this information that you provided is a valid IP address or is a valid email address as we saw So you don't have to do that yourself I see a lot of other people that might be trying to write PowerShell scripts And they're doing all this like string splitting and cutting and trying to verify Okay, is this really within the range of 0 to 255 blah blah blah PowerShell can do that for you Because of this awesome data type that it's created, right? If we can access it with just IP address Let's find out and you notice those square braces are what allowing us to actually specify This is the type that I want to use so I'll specify a string just after that We'll do 10, 0, 0, 1 and that is created for us and it even has properties already Gives us kind of an address family whether or not it's a local address or not if I were to change that to like 104 It says okay That didn't help me bad example But it will give us the value and other information that we might want Let's run a FL star on that to see everything that might carry for us. There's not a whole lot else apparently select star everything It's like string my bad Let's just use select that's all there is to it But if I were to try and create that IP address with something that wasn't real like a 256, right? It says hey, that's not a valid IP address or maybe I had the right amount of octets or I had the wrong amount of octets Okay, I guess that one figured it out on its own for me. I Guess that one will just do it automatically fill in zeros as needed But maybe if something was out of range it would say that's not quite right. That's interesting how it's doing some of that math It knows okay with four octets. It's not gonna be able to do that correctly. So That's an IP address Kind of data type you can use within PowerShell or we could use. What was that that mail? If you ever forget it, you can get type data and search for mail Systemnet mail mail address. So maybe we could just run mail address. Will that work? Yeah, now? Let's run like John at Gmail.com or whatever it'll actually display our user kind of before the at sign and the host Just after the at sign and the full address and of course if I were to have that wrong John gmail.com or however typos I want to throw in there Notice it'll error for us because we don't have our at symbol. It's not a real email address Handy right that way you don't have to do the processing PowerShell can do that for you if you know is okay. There's a wrong spot here. This isn't a real email address It's not in the required form So you don't have to do that processing PowerShell can do that just as well for you now We've created some of these variables that we've created this anything and we created what was the other one integer, but What I want to show you is that these are not the only variables that PowerShell is going to end up keeping track We've already seen profile. We've already seen that that is a variable that just created or was in existence We didn't have to create it. It was there before we started PowerShell So there's other already some variables that are in existence in scope that maybe we want to know what they are Just to explore and learn about PowerShell more we can figure out what those are so I want to introduce to you a new thing called PowerShell drives or ps drives and That is how PowerShell is going to kind of manage the context that you're working in within the shell within PowerShell Right now. We're inside of our file system, right? but PowerShell could also allow us to work inside of the Windows registry or even kind of knowing the variables that we're working with and Treating it like a file system, right when we were able to run new item or move item or copy item It's called item because it's not always the file system that we're working with maybe when we get child item We get all this information out in our current directory But maybe it's not so much a directory that we're looking at but what if it's a hive in the registry or some specific scope for variables in their existence So that's a thing Called ps drives or PowerShell drives if I run a get hyphen ps drive It'll tell me all the different things that we can go ahead and navigate in and look around it aliases we've seen those before with gal and get alias of course our file system or Maybe some certificates that we have installed in the machine Maybe another drive that's accessible to us environments functions that are created and of course registries and There's one for variables So if I were to move into that PowerShell drive We can explore these variables and work with them as if they were files just running LS commands or get child item So we can hop into the context of that PowerShell drive by kind of using the provider here that PowerShell provider and Specifying a colon following it so it just looks kind of like our C colon for our file system object But instead it would be variable colon. So let's do that. Let me cd to variable colon I'll hit enter and you see that my prompt has changed now I'm inside a kind of a variable context if I were to LS or get child item We can see all of the variables that have been created thus far Some of this is kind of ones that we've seen. We know true is going to evaluate to true, right? We actually have our version table for PowerShell. We have our to scroll up here. Maybe the profile that we've seen Yep The process ID for what we're working in No, we even have our integer variable that was created earlier Or if I scroll all the way up. I Don't know why my scroll bar isn't that good for my virtual machine We even have those special variables like what was the previous command that we ended up running the dollar sign dollar sign The dollar sign question mark What was the kind of error code or exit code that we were working with that last one our previous command or? Anything that's that variable that we just created There's others that exist in here Maybe errors that were happening earlier that we saw the very very last error while we were running PowerShell can't convert that value When I was trying to showcase that email address it stored that error And now we could actually view that maybe if we were creating a script or writing something that might need to know what that error message was So if I were to create a variable z 100 or whatever if I were to LS check those it again now I have z as a variable that exists and that value there and Of course if we want to zoom in on one of those we could let's select the last one and If I could select everything out of it, it tells me the drive and provider that it's in Maybe a value whether or not it's accessible if it came from a module Will FL star give me any more information? I guess not But that's that You might have noticed though One that I kind of glossed over was this ENV drive or the environment drive and this one stores environment variables or variables that are kind of across the machine or accessible for Really the host and system that you're working with so if I were to CD into environment Okay, sorry, it's not called a fully environment. It's called ENV The name is what should be Switched into not the provider that just tells us kind of what it is. So if I move into ENV Now if I were to LS check out what we have here We have some more Information about this system that we hadn't seen before or some of those variables that you might be used to in kind of old-school CMD with we were to echo like oh when dir and that's wrapped around in those percent signs these that were environment variables are now stored in that kind of dollar sign ENV When dir you can see that's that value that shown to us right in this listing here Sending with our username or user profile or more information where program data is where program files are Where is our module path? What is our actual path for binaries or scripts or things that we try to run? Straight from the command line app data common users computer name etc. Etc. That is how we can view all that information That's where we can kind of navigate with it and modify them inside of the ps drive that PowerShell drive And we can set those with specific types that we might want so If I were to hop back to my variable drive if I were to create Z make that now and IP address We'll make it local host If I were to just check out what we have here, we have Z set to that value But we can go ahead and grab that last one kind of zoom in on it. Let's check out all of his properties It tells me that it's just a variable. It won't tell me the actual type Maybe there's a way that I just don't know about yet Hope you guys can teach me a little bit help me learn Wonder if I can just grab that and see some other information with that the period Nope. Oh That was odd. I want to do control There's nothing there. It won't let me I can't can maybe I can get member out of this and see what else what other informations there To string we can still run get type on that that works just as well Tells me it's a PowerShell variable not the specific type that it's actually in is their full name now Interesting so maybe within the context of variable that ps drive. We won't be able to see it work all that well Now because I created that variable in there. Is it still accessible for me inside of see? yes, which it is and then Can I run get type on that and will it tell me it's an IP address? It will Interesting. Okay. I'm learning to this is a very exploratory thing when we're using PowerShell So that's that that's really all that I wanted to show you in this video was what these variables are how they can store information Data and the types of data that can come with it that SS64 reference is awesome You should check that out see what more you can learn from there and know if you scroll through that get hyphen type data There are other kinds of PowerShell types that you might be able to use and some of your later scripts or code They'll kind of minimize the work that you need to do like trying to validate is this really an IP address Or is this really an email address? That's nice and handy for us and these things live and you can access them within some of those PowerShell drives PS drive or we can navigate around our registry or other file systems or even certificates and aliases So that's kind of neat. I hope you guys enjoyed this video if you did please do like comment subscribe all those YouTube algorithms stuff I'd love to see in the discord server. There is a link in the description You want to come hang out tons of smaller people in there so much smarter than me? It's a really awesome community And I would just love to see there Part of that so love to see you on patreon. Let's go on PayPal. Love to see you on Instagram Twitter Facebook's all the things Thanks for watching. See the next video