ProVal is going through how we can utilize a lesser-known function 'Console Shell' to grab the logged-in user's profile path variable and utilize this further in our scripts.
Step by Step:
Today I wanted to go over how you can grab the current logged-on user profile and pull that back into Automate let's get into it.
So what you want to do is you want to make a new script or maybe you've already got a script and you just kind of want this logic.
So what I’ve done in here is - ideally you would want to resend the system information first that would then ensure that you have the latest up to date. You can also double verify that there's a user logged in under this line too by under here if you want to do is, console, logged on and if you leave this blank basically anything in Automate as long as they're logged in.
So like if in this case if I open up this machine that I ran the script on if anything is showing in here inside the database whether it's accurate or not sometimes it's not it just hasn't checked in recently or anything like that but this would be the check of that first initial if statement.
So if anything is there then run the next script or run the then statement.
So inside of here I’m doing a secondary check just because I’m doing it all with inside the then statement. If you don't do it this way and you do it in the top here. Make sure that you do include something here at the bottom in the else statement because if nobody's logged in and it is actually up to date that's current then you want something down here that says if nobody's logged in run this not the then section.
But to keep things simple in the then section here I’ve added the if console logged on left that same username blank and I’ve skipped ahead a couple steps so I can do the if no user is logged on the next step is just going to exiting script.
And then what I would want to do is inside of here run like a script exit with error so that way it would show up as a failed script not just a successful kind of weird logic.
So if no users logged in log a statement said no users logged in exiting script failed.
If they did if they are logged on and it is currently up to date because you do want to include this recent system information, so all of that's true you want that logged in user's system path which you can then kind of utilize is this console shell scripting function it's very limited what you can do but you can do you can kind of push it to your own limits. All this is sampling doing is just running up of command so command prompt like the old style so if I open up that here basically what I’m doing is I’m running a PowerShell through the original command prompt here so powershell.exe loading that up and then I’m running this command through and that will actually grab my current user's path.
So I'm doing that same thing except I’m running it on the logged in user and just grabbing that console number from that if statement so inside of here in this if statement.
So if console user is logged on if somebody's logged in this will work for most of the time if it's just a single person servers if you have like an RDP it's going to be a little different it's going to be a little tricky but in most of the time it's one to one for one person to one workstation.
So if they're logged in then set their console number here at this very top to this variable uh percent console number percent and then we can utilize that to then in this say on that console number run this command.
So we're kind of emulating that user grabbing that user's profile path and when we do that you can do whatever you want with that from here.
In this case I’m just logging it inside of the script log and if I open the script log here I can see it was successful and then in the script log message current user profile path is just what I typed and then the c colon you know wax users wac test that that would be the Windows 11 machine that I was using as the dev environment I was trying to use some other PowerShell methods here that's why it looked a little weird but I’ve removed those to make it clear on the video of what we're actually doing.
So you can do lots of things from here, this top section is going to be the logic that you're going to need, and then everything beyond that is whatever you're going to do with that information whether you're pushing an install pushing maybe a temp file you can do lots of stuff from there.