Creating an array using Select-Object with the ‘Switch’ option

A sample scenario:
We start off with an array of users that we have collected from Active Directory. We need to correlate the data with another array that contains additional information about the users.
The first array we will call $users – and we get this by running

And we have a spreadsheet (in CSV format) with user’s hours, rates and employee numbers like below. We have added the ‘dept’ column, but this only has a number.

We can import the CSV by using

What we want to output is an array with the user’s name, employee number, hours worked, rate of pay, the total gross pay and their department name based on the number from the timesheets. (This is only a sample idea just so you get the idea of how it will work)
Using the command below we can generate a new array called $payroll with all the required data from above

Note the SWITCH part

This will replace the number with the corresponding data as you can see below:

As always, have fun playing around with this and hopefully it helps you out in your scripting and feel free to comment.

One comment

  1. This is very fascinating, You are an excessively
    skilled blogger. I have joined your feed and stay up for in the hunt for extra of your wonderful post.

    Also, I have shared your website in my social networks

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.