It’s a function. So in order to use it you either have to load it in your PowerShell User profile, or creating a new script, and dot source the Get-ComputerDetails.ps1 file.
To use it immediately, try to open up PowerShell ISE, and paste the function in the script pane. After that select all the code and then press F8. The function is now loaded in memory, and you can use it in the current PowerShell session (the console below the scriptpane).
If you want to use it in all your PowerShell sessions, put the function in your PowerShell profile. Remember, PowerShell.exe and PowerShell_ise.exe use different profiles.
The profiles exists in this path: %username%\My Documents\WindowsPowerShell\
If you want to dot source it in a script, you have to do this:
Windows doesn’t specifically track the last logged-on user. On a server computer, people are authenticating constantly to file shares and other resources, so the OS in general doesn’t keep track. If you’ve enabled security auditing, you could query the most recent event log entry for logons.
I’ll note, with bias, that a lot of what you’re trying to do with functions and such is very thoroughly covered in “Learn PowerShell Toolmaking in a Month of Lunches.” That might be an easier way to learn some of this stuff without feeling like you’re banging your head into a wall :).
In a way, yes. But it’s not really trustable. As long as you didn’t specify in your GPO’s that the last logged on user should not be cleared in the login box (the one you see when you need to login into the computer), then this addition is more or less acceptable:
There are many ways to do the same thing, your end goal is to create a single object with all properties. I see that system info has the most properties, so I just use Select-Object to get those properties and use calculated properties to cover the last 3 properties. I try to use this method first and if there is a need to order the results or it’s a bunch of single properties from separate sources, then I would use New-Object or a similar method. Here is the excerpt: