[UPDATE 16.05.2015] Made the code more robust and simplified.
This is the function I mention in this post, which wraps the DOS dir command. (more…)
A while back I wrote a post about handling files in PowerShell. In it I describe the different ways you can read and write files. You can read it here if you like: Working with files in PowerShell. This time I will discuss how to find files. You have undoubtedly been in a situation where you need to locate a file on your disk, but didn’t know exactly where to look. Or perhaps you need to get all log-files in a share? Or document how many mp3 files you find on the server hosting all your users profiles? (more…)
These two small functions can be used to convert a specific Time Zone into a DateTime object. The returned DateTime object represents the current time in the specified Time Zone. This can be useful if you need to know what time time is right now in a different Time Zone. (more…)
Have you ever needed to write some file, but the need for making sure the file size didn’t get out of hand made you have to write a ton of extra code? This is a very typical scenario when writing log files for instance. Out-File2 got you covered! (more…)
This function will take an IP address and either a subnet mask, or a mask length, and return a custom object with information about that subnet. The information you get is basic stuff like network address, the first and the last usable addresses, the broadcast address etc. But it will also tell you the class of the address, as well as if it’s a private address or not. If run without any parameters it will try to get the needed information from the host you are running it on. (more…)
When writing advanced functions with two (or more) parameter sets, sometimes you need to use conditional logic based on what parameter set is in use. This can be achieved easily by using the built-in PSCmdlet variable. (more…)
Creating and using variables in PowerShell is simple. Unlike most other languages you don’t need to initialize a variable before use – you don’t even need to type them; PowerShell will attempt to set the type based on the value you give it. Because they are so simple to use, it’s easy to forget that we actually have a set of cmdlets for working with variables. (Get/Set/New/Clear/Remove-Variable) But that’s ok, they are seldom needed. But in this quick tip I will show you how to create and use variables dynamically, and then they come in handy indeed. (more…)
I’m back with another set of small helper functions. This time it’s all about timing your script. Sure, it’s not that difficult to do manually – just get the time when it starts, and when it ends, and calculate the running time. It might not look pretty, but it works. With this functions though, it’s even easier! (more…)
This is just a little helper function that will help you if you have a prerequisite of certain 3rd-party functions being loaded for your script to work. It will either give you are TRUE/FALSE, or a list of the missing functions. Stick it in somewhere at the beginning of your script, and give it an array of functions to test for, and handle the result however you like. (more…)
In the process of learning PowerShell it is customary to hear people say that you shouldn’t re-invent the wheel; if there is a native command for it, you should use that. And I agree. But there is a case to be made for taking the time to properly explore all the different options available to you. For instance when coding for a specific version of PowerShell, or if speed is important. This post will discuss the latter; specifically a comparison of the native command for generating random numbers (Get-Random) and using the .NET class System.Random. (more…)
Share what I know or discovered when working with Windows PowerShell.
C#, Game Design, Performant Programming, .NET, Vulkan, Multithreading
Spreading the gospel of powershell scripting
Flynn Bundy
psjjw - een opbergkast meer niet
Automate, Accelerate, Accurate
de parvis grandis acervus erit
What is this Powershell of which you speak?
Just Another PowerShell Blog
up in the trees
My WordPress Blog
Just another WordPress.com site
Totally addicted to PowerShell