PowerShell Community
A place for the community to learn PowerShell and share insights
Latest posts
Borrowing a built-in PowerShell command to create a temporary folder
Q: Hey I have a question for you. It seems silly and I know I could probably put something together with Get-Random. But can you think of another way to create a temporary folder with a random name in PowerShell? Ideally, I'd like it to be in a user's own "Temporary Folder" is possible. A: We sure can! If Doctor Scripto was sitting here right now, I'd see that little green haired person shout out "Never fear, Scripto is here!" New-TemporaryFile Cmdlet Within PowerShell there is a built in Cmdlet called . Running this cmdlet simply creates a random 0 byte file in the in whichever platform you are working in. ...
Is a User a Local Administrator?
Q: Some of the things we do in our logon scripts require the user to be a local administrator. How can the script tell if the user is a local administrator or not, using PowerShell 7. A: Easy using PowerShell 7 and the LocalAccounts module Local Users and Groups The simple answer is of course, easily. And since you ask, with PowerShell 7! But let's begin lets begin by reviewing local users and groups in Windows. Every Windows system, except for Domain Controllers, maintains a set of local accounts - local users and local groups. Domain controllers use the AD and do not really have local accounts as such. You ...
Testing the connection to computers in the Active Directory
Q: As an administrator, I often have to do a lot of reporting on the servers in my domain. Is there a simple way to test the connection to every server in my domain or every server or client host in a specific OU? A: Of course you can do this with PowerShell! You can use the Active Directory cmdlets and , although it is not as simple as one might like. Using the module Microsoft has developed several modules to help you deploy and manage AD in your organisation or via Azure. The module is one which Microsoft ships with Windows Server (although not installed by default). You can also load the Remote Server Ad...
Can I Enable the Caps Lock Key?
Q: I have a script where users enter some information. This information needs to be entered in all capital letters, so my instructions say, “Please make sure the Caps Lock key is on before entering the information.” They don’t always do that, however. Is there a way to turn the Caps Lock key on and off using a script? A: I don't know how to run the key off and on, but with PowerShell, there is a way to mimic the effect of turning on the Caps Lock key. User Input Considered Harmful Let's start with the observation that all user input is harmful. One of my earliest IT heroes, Edsger Dijkstra, published a seminal...
A Reusable File System Event Watcher for PowerShell
FSWatcherEngineEvent module provides events of file system changes as powershell engine event
Determine if a folder exists
Q: Is there any way to determine whether or not a specific folder exists on a computer? A: There are loads of ways you can do this. The Test-Path Cmdlet The easiest way to do this is to use the cmdlet. It looks for a given path and returns if it exists, otherwise it returns . You could evaluate the result of the like in the code snippet below This is similar to the operator for IF statements in Bash. is returned if exists, otherwise is returned. For More Information And for more information on see the Test-Path help page. Summary So as you saw, tests the existence of a path and returns a boolean...
Reading a text file bottom up
Q: I have a log file in which new data is appended to the end of the file. That means the most recent entries are at the end of the file. I’d like to be able to read the file starting with the last line and then ending with the first line, but I can’t figure out how to do that. A: There are loads of ways you can do this. A simple way is to use the power of array handling in PowerShell. The Get-Content Cmdlet Before getting into the solution, let's look at the cmdlet. The cmdlet always reads a file from start to finish. You can always get the very last line of the file like this: This is similar to the co...
Lightning Fast and Easy Provisioning of Git with SSH Key Authentication on Windows
Maybe you have a team of Windows developers that are onboarding for your new Git server installation or maybe you've decided to drop http password authentication to your existing Git server (due to it's many problems). Your next steps may well be into a rough and rocky rabbit hole when you were holding out hope for simplicity (you know the kind you've fallen into before if you've been in tech for more than about 45 minutes). The common Internet guidance for setting up Git with SSH authentication on Windows are unnecessarily complex. My inner tool smith really loathes when the very first steps into something new...
Leveraging XML with New Employee PowerShell Scripts
using XML referencing to bolster up your new employee scripts with information.