The
Import-CSV cmdlet is often employed for changing the format of the data.
Another use is for creating users by bulk importing their data from a csv
file.
In the case of Windows 7 and later, you don't need to download any extra files, just: 'Add Feature'
--> Windows PowerShell.
However, for older operating systems, there are different versions of PowerShell for XP, Windows Server 2003 and
Vista. For such legacy systems only, you need to
download PowerShell from Microsoft's site.
Once you have installed PowerShell 2.0 or later, I recommend choosing the
ISE (Integrated Scripting Engine) version, it
will save buying a text editor.
Simple Scenario: We want to examine
the properties of Windows services. The technique is to first
export the data, then import and finally, apply Get-Member.
Note 1: One reason that I have used a variable to control
the path, is that I want to remind you to change its value before
you run this script on your machine.
Note 2: I recommend launching Excel and using it
open the file to check
if exporting achieved what you expected.
Note 3: Save Frustration You cannot use
Format-Table with the Export-CSV cmdlet. However you could use
Select-Object to choose just the properties or columns that interest
you. See
Example 2.
Excel Spreadsheet Screenshot
Note 4: #Type System.ServiceProcess in the first row
is the .NET Framework type of the object.
Import users from a spreadsheet. Just provide a list of the
users with their fields in the top row, and save as .csv file.
Then launch this FREE utility and match your fields with AD's
attributes, click and import the users.
This is a clumsy example, its sole purpose is to show how you can
extract data with a foreach loop. I hope that it gives you ideas
for your project. As ever, do send me a better example if you have
one.
Checking the help file may reveal useful parameters, for instance you
can adjust the delimiter from the default comma to the semicolon. Append
the -Full parameter to see the examples. Get-Help
Import-CSV -Full.
Guy Recommends: A Free Trial of the Network Performance Monitor
(NPM)
SolarWinds'
Network Performance Monitor
will help you discover what's happening on your network. This
utility will also guide you through troubleshooting; the dashboard will
indicate whether the root cause is a broken link, faulty equipment or
resource overload.
What I like best is the way NPM suggests solutions to network
problems. Its also has the ability to monitor the health of individual VMware
virtual machines. If you are interested in troubleshooting, and creating
network maps, then I recommend that you try NPM now.
With Microsoft, there are always at least
three ways of doing everything, what seems like redundancy when you are an
expert, seems like perspective when you are a beginner. One obvious
example is that you can abbreviate Format-Table to ft. As you increase
your range of PowerShell commands, keep an eye out for another
PowerShell Alias, for example gci (Get-Childitem).
Researching Similar PowerShell Cmdlets
# PowerShell CSV Cmdlet Research Clear-Host Get-Command
-Noun CSV
As expected there is an Export-CSV cmdlet, but you may not realize there
is a ConvertFrom-Csv cmdlet. PowerShell -Noun or -verb research
always throws up at least one surprise.
Import-CSV works hand-In-glove with Export-CSV. Possible usage for
this cmdlet include manipulating formats and bulk-import of users into
Active Directory.
If you like this page then please share it with your friends
Please email me if you have a better example script. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.
Windows Management Instrumentation (WMI) is
most useful for PowerShell scripting.
SolarWinds
have produced this
Free WMI Monitor to take the guess work out of which
WMI counters to use for applications like Microsoft Active Directory,
SQL or Exchange Server.