PowerShell's New-Item is a
versatile cmdlet particularly good for creating files and folders.
New-Item typifies PowerShell's simplicity coupled with power, added to
versatility.
In the case of Windows 7 and Server
2008, you don't need to download any extra files, just 'Add Feature' Windows PowerShell.
However, for older operating systems, installing can be confusing because
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, I recommend choosing the
ISE (Integrated Scripting Engine) version, it
will save you buying a text editor.
Note: As usual with my -path examples, I
introduce a variable mainly to remind you to change its value if you
want the script to work on your machine!
Note: The -itemType parameter can be abbreviated
to plain -Type. Also "Directory" does not have to be in quotes.
Note: If the script succeeds PowerShell gives you
a summary of what the script achieved, however, I still like to open
Windows Explorer to checkout my new folder.
Note: If your version of the script fails, start
troubleshooting with value of $Location.
Note: That it's a case of New-Item file by name
and -type "file" by nature. By that I mean check your -type (or -itemType)
string value.
Guy
Recommends: WMI Monitor and It's Free!
Windows Management Instrumentation (WMI) is one of the hidden
treasures of Microsoft operating systems. Fortunately, Solarwinds
have created a
Free WMI Monitor so that you can discover these gems of performance
information, and thus improve your PowerShell scripts. Take the guess work out of which WMI counters to use when scripting the
operating system, Active Directory or Exchange Server.
Guy Recommends: A Free Trial of the Network Performance Monitor
(NPM)
Solarwinds'
Orion 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.
Perhaps the NPM's best feature is the way it suggests solutions to network
problems. Its
second best feature is 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 take advantage of Solarwinds' offer.
Examining New-Item's parameters is particularly fruitful. It
emphasises the variety of objects that you can create, and how you can
employ parameters to modify the new article and even give it initial
values.
Checking the help file may reveal additional useful parameters, for instance
-force and -credential.
Alias for New-Item (Ni)
New-Item has an alias of Ni. In addition, Mkdir or Md mimics
New-Item and creates a directory.
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 Item Cmdlet Research Clear-Host
Get-Command -noun Item
This reminds me that there is a Remove-Item
cmdlet, which can be useful for removing
your failed experiments, but go carefully, Remove-Item can lead to
disaster, so before use even Gung-ho Guy backs up at least some of the
File structure of registry. PowerShell -noun or -verb research
always throws up at least one surprise.
Work in Progress - Investigate
Registry Provider accepts :: Get-PsProvider
»
Summary of PowerShell New-Item
Sooner or later everyone needs
new stuff. Whether it's a file, folder or registry key, New-Item can
deliver just the article that you need for your PowerShell project.
If you like this page then please share it with your friends
See more PowerShell examples for syntax constructions
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 one of the hidden
treasures of Microsoft operating systems.
Fortunately, Solarwinds
have created the
Free WMI Monitor so that you can actually see and understand these gems of
performance information. Take the guess work out of which
WMI counters to use for applications like Microsoft Active Directory,
SQL or Exchange Server.