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…)
Tag: Custom Function
Time your script
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…)
Test-Function
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…)
Get-MacAddress
Another small function from me today. And another one that I can’t take credit for. I found this one on poshcode, and just did some minor tweaking to it. It sends an ARP request to get the MAC address from an IPv4 address. (more…)
Get-MacAddressVendor
This little function uses the free API from www.macvendorlookup.com to lookup vendor information for a MAC Address. It’s really quite simple, and easy to use. It only have the one parameter; MacAddress, which defaults to the MAC address of the first network interface that is in use. (more…)
Encode/Decode Base64Url
As is often the case, when working on a project I end up needing some sub-task done and search the web to see if someone have done it before. In this particular instance I couldn’t find any ready-made solutions for PowerShell, but I did find that someone had written a couple of functions in c# that did exactly what I needed. Luckily, translating from c# to PowerShell isn’t that hard, so I thought I’d share the functions I wrote (translated) with you. (more…)
Invoke-SqlCommand
In several previous posts I have presented functions to create different kinds of database connections. But a connection to a database is just the first step. The function I’m presenting here will let you use the connection object you get from those functions and send SQL commands to the database. If you expect data back you can indicate that by using the GetResults parameter, and you will get a DataTable object returned to you. (more…)
New-OdbcConnection
This function will let you create a database connection object for connecting to a database using ODBC.
It supports using DSN as well as setting up a DSN-less connection, and will return a database connection object. (more…)
New-OracleConnection
This function will let you create a database connection object for connecting to an Oracle database. It supports the usual parameters; DatabaseServer, DatabaseName, Port and Credential and will return a MySqlConnection object. (more…)
New-MsSqlConnection
This function will let you create a database connection object for connecting to a Microsoft SQL Server database. It supports the usual parameters; DatabaseServer, DatabaseName, Port and Credential and will return a database connection object. (more…)