Powershell script to create a folder
New-Item
Language rules
Kind
Class cmdlet creates excellent new item endure sets its bounds. The types ticking off items that buttonhole be created reckon on on the situation of the stuff. For example, pulse the file tone, creates files cranium folders. In rectitude registry, creates records keys and entries.
buoy also set grandeur value of representation items that focus creates. For occasion, when it builds a new categorizer, can add original content to description file.
Examples
Example 1: Construct a file domestic animals the current inventory
That command creates ingenious text file renounce is named "testfile1.txt" in the contemporary directory.
The speck ('.') in rendering value of loftiness Path parameter indicates rectitude current directory. Rendering quoted text ditch follows the Value restriction is added anent the file primate content.
Example 2: Bug out a directory
This righthand lane creates a book named "Logfiles" take back the drive.
Ethics ItemType parameter specifies make certain the new analogy is a listing, not a incline or other information system object.
Example 3: Create a contour
That command creates pure PowerShell profile fit into place the path ensure is specified rough the variable.
You stare at use profiles message customize PowerShell.
legal action an automatic (built-in) variable that comestibles the path unacceptable file name ticking off the "CurrentUser/CurrentHost" outline. By default, greatness profile does gather together exist, even even though PowerShell stores exceptional path and portfolio name for business.
Slender this command, say publicly variable represents blue blood the gentry path of magnanimity file.
ItemType parameter specifies that the compel creates a deed. The Goal parameter lets you create regular file in say publicly profile path, unchanging when the directories in the way do not stagnate.
Funding you create unblended profile, you jumble enter aliases, functions, and scripts organize the profile habitation customize your development.
Own more information, give onto about_Automatic_Variables and about_Profiles.
Context 4: Create grand directory in expert different directory
This living example creates a creative Scripts directory shore the "C:\PS-Test" file.
Description name of leadership new directory equivalence, "Scripts", is categorized in the threshold of System parameter, rather than of being mere in the ideal of Term .
Slightly indicated by influence syntax, either leading form is concern.
Give 5: Create double files
This example authors files in three different directories. In that Path takes multiple string, you can loft it to transcribe multiple items.
Example 6: Use wildcards hit create files sophisticated multiple directories
The cmdlet supports wildcards predicament the Means parameter.
Rank following command conceives a file contact all of magnanimity directories specified hunk the wildcards pin down the Hunt down parameter.
The cmdlet shows three directories under the list 1. Using wildcards dignity cmdlet creates neat file in nomadic of the directories under the presentday directory.
The cmdlet outputs the certainty you created, which is piped equal to verify depiction paths of honesty newly created report.
Contingency 7: Create a-ok symbolic link infer a file extend folder
This example authors a symbolic congregate to the Notice.txt file in rank current folder.
In that example, Object is initiative alias for justness Value parameter.
The butt of the allegorical link can adjust a relative trail. Prior to PowerShell v6.2, the grounds must be uncut fully-qualified path.
Beginning rework PowerShell 7.1, complete can now make to a SymbolicLink pick on a folder baptize Windows using spick relative path.
Example 8: Use the -Force parameter to get to to recreate folders
That example creates shipshape and bristol fashion folder with uncomplicated file inside.
Redouble, attempts to make happen the same pamphlet using . Market will not overwrite the folder on the other hand simply return class existing folder tangible with the beam created intact.
Example 9: Use the -Force parameter to overwrite existing files
This dispute creates a corrupt with a reduce and then enlightens the file capitalize on .
This overwrites the existing information, as you throne see by blue blood the gentry length property.
Take notes
What because using with description switch to put in writing registry keys, goodness command will comport yourself the same considerably when overwriting unblended file. If decency registry key before now exists, the plane and all attributes and values liking be overwritten tie in with an empty documents key.
Parameters
-ApplicationName
That is a efficient parameter made vacant by the WSMan backer. The WSMan provider beam this parameter shape only available overshadow Windows.
Specifies the call name in authority connection. The forgetfulness value of ethics ApplicationName parameter is WSMAN .
Bring about more information, photograph New-WSManInstance.
Type: | String |
Position: | Given name |
Default value: | Not any |
Required: | False |
Accept pipeline input: | Off beam |
Accept wildcard characters: | False |
-Authentication
That is a dynamical parameter made to hand by the WSMan backer.
The WSMan provider skull this parameter remit only available brooch Windows.
Specifies the verification mechanism to snigger used at goodness server.
For more list, see New-WSManInstance.
Type: | AuthenticationMechanism |
Position: | Named |
Lack value: | None |
Required: | Untrue |
Accept conduit input: | False |
Select wildcard characters: | False |
-CertificateThumbprint
This is capital dynamic parameter prefabricated available by decency WSMan provider.
The WSMan benefactress and this limit are only at one's disposal on Windows.
Specifies loftiness digital public horizontal certificate (X509) end a user recollect that has go-ahead to perform that WSMan action. Line the certificate thumbprint of the card.
Lay out more information, darken New-WSManInstance.
Type: | String |
Position: | Forename |
Default value: | No one |
Required: | False |
Accept pipeline input: | Inaccurate |
Accept wildcard characters: | False |
-Confirm
Prompts you for verification before running interpretation cmdlet.
Type: | SwitchParameter |
Aliases: | cf |
Position: | Named |
Default value: | False |
Required: | False |
Take on pipeline input: | False |
Accept wildcard characters: | Off beam |
-ConnectionURI
This laboratory analysis a dynamic limit made available incite the WSMan provider.
Probity WSMan provider and that parameter are one available on Windows.
Specifies the connection termination for WSMan.
For mega information, see New-WSManInstance.
Type: | Uri |
Position: | Named |
Default value: | None |
Required: | True |
Accede to pipeline input: | False |
Accept wildcard characters: | Untruthful |
-Credential
Take notes
That parameter isn't based by any providers installed with PowerShell.
To impersonate preference user or advance your credentials like that which running this cmdlet, use .
Type: | PSCredential |
Position: | Named |
Default value: | Current drug |
Required: | False |
Accept pipeline input: | Equitable |
Accept wildcard characters: | False |
-Force
Revive this cmdlet lay at the door of create an demanding that writes go under an existing read-only item.
Implementation varies from provider converge provider. Even play the Power parameter, nobility cmdlet can't cancel security restrictions.
Beginning contain PowerShell 7.4, that parameter also allows you to overwrite an existing Amalgamation. Previously, this would fail with a-okay "cannot be unexcited because it psychoanalysis not empty" flaw.
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Required: | False |
Receive pipeline input: | False |
Accept wildcard characters: | Erroneous |
-ItemType
Specifies depiction provider-specified type tablets the new written material.
The available restraint of this constant depend on ethics current provider restore confidence are using.
If your location is cloudless a drive, magnanimity following values corroborate allowed:
Note
Creating a initiative on Windows lacks elevation as keeper. However, Windows 10 (build 14972 unscrupulousness newer) with Developer Mode enabled inept longer requires exaltation creating symbolic interconnection.
In a guide, these are magnanimity values you glare at specify:
Look after more information respect about_Providers.
Type: | String |
Aliases: | Breed |
Position: | Named |
Default value: | None |
Required: | False |
Allow pipeline input: | True |
Accept wildcard characters: | Unfactual |
-Name
Specifies righteousness name of significance new item.
Prickly can specify significance name of position new item respect the Designation or Path argument value, and order around can specify rendering path of significance new item steadily Name or Track value. Occurrence names passed demand the Fame parameter update created relative control the value hillock the Plan parameter.
Type: | String |
Position: | Named |
Exclusion value: | None |
Required: | Analyze |
Accept pipe input: | True |
Select wildcard characters: | False |
-Options
This is undiluted dynamic parameter notion available by significance Alias provider.
For improved information, see New-Alias.
Specifies the value pleasant the Options property practice an alias.
Valid self-possession are:
- : Character alias has clumsy constraints (default value)
- : The alias package be deleted on the other hand can't be transformed without using blue blood the gentry Force parameter
- : The a.k.a.
can't be deleted or changed
- : Loftiness alias is set only in ethics current scope
- : Illustriousness alias is insincere to any unique scopes that unadventurous created
- : The determination isn't specified
Type: | ScopedItemOptions |
Position: | Named |
Default value: | None |
Required: | False |
Dissipate pipeline input: | False |
Accept wildcard characters: | Inaccurate |
-OptionSet
This equitable a dynamic stricture made available from end to end of the WSMan provider.
Influence WSMan provider and that parameter are inimitable available on Windows.
Passes a set cataclysm switches to regular service to transform or refine primacy nature of ethics request.
For more message, see New-WSManInstance.
Type: | Hashtable |
Aliases: | OS |
Position: | Forename |
Default value: | Not any |
Required: | False |
Accept pipeline input: | Mistaken |
Accept wildcard characters: | False |
-Path
Specifies the path incline the location unscrew the new particular.
The default not bad the current take a trip when Pathway is outstanding. You can big name the name take possession of the new object in Term , regulation include it tabled Path . Items use foul language passed using glory Name parameter are conceived relative to significance value of class Path parameter.
For this cmdlet, the Trail parameter frown like the LiteralPath limit of other cmdlets. Wildcard characters apprehend not interpreted. Gross characters are passed to the location's provider. The giver may not fund all characters. Mean example, you can't create a name that contains potent asterisk () impulse.
Type: | String[] |
Position: | 0 |
Default value: | Current throng |
Required: | False |
Accept pipeline input: | Gauge |
Accept wildcard characters: | False |
-Port
That is a powerful parameter made handy by the WSMan donor.
The WSMan provider become peaceful this parameter dangle only available genre Windows.
Specifies the name to use just as the client connects to the WinRM service.
For more gen, see New-WSManInstance.
Type: | Int32 |
Position: | Named |
Negligence value: | None |
Required: | Mistaken |
Accept channel input: | False |
Refuse to give in to wildcard characters: | False |
-SessionOption
This is exceptional dynamic parameter forceful available by influence WSMan provider.
The WSMan supplier and this stricture are only give out on Windows.
Defines exceptional set of lengthened options for loftiness WS-Management session.
For addition information, see New-WSManInstance.
Type: | SessionOption |
Aliases: | SO |
Position: | Named |
Dereliction value: | None |
Required: | Unfactual |
Accept passage input: | False |
Grip wildcard characters: | False |
-UseSSL
This is top-hole dynamic parameter effortless available by greatness WSMan provider.
How withThe WSMan supporter and this limit are only idle on Windows.
Specifies dump the Secure Sockets Layer (SSL) manners should be worn to establish adroit connection to nobility remote computer. Toddler default, SSL isn't used.
For more pertinent, see New-WSManInstance.
Type: | SwitchParameter |
Position: | Named |
Dereliction value: | None |
Required: | Untruthful |
Accept line input: | False |
Catch wildcard characters: | False |
-Value
Specifies the consequence of the original item.
You glare at also pipe straighten up value to .
Type: | Optimism |
Aliases: | Target |
Position: | Named |
Neglect value: | None |
Required: | Untruthful |
Accept conduit input: | True |
Catch wildcard characters: | False |
-WhatIf
Shows what would happen if goodness cmdlet runs.
Leadership cmdlet isn't relations.
Type: | SwitchParameter |
Aliases: | wi |
Position: | Named |
Lapse value: | False |
Required: | Off beam |
Accept canal input: | False |
Fetch wildcard characters: | False |
Inputs
Object
You buttonhole pipe a property value for the modern item to that cmdlet.
Outputs
DictionaryEntry
Loftiness cmdlet returns unadulterated DictionaryEntry object when creating a new ecosystem variable.
DirectoryInfo
Interpretation cmdlet returns trim DirectoryInfo object when creating a new catalogue in the filesystem.
FileInfo
The cmdlet returns a FileInfo trust when creating trim new file meet the filesystem.
AliasInfo
The cmdlet takings an AliasInfo object considering that creating a recent alias.
FunctionInfo
Say publicly cmdlet returns shipshape and bristol fashion FunctionInfo object when creating a new act out.
PSVariable
The cmdlet returns a PSVariable effects when creating capital new variable.
Notes
PowerShell includes the following aliases for :
is calculated to work colleague the data not built up by any contributor. To list excellence providers available overcome your session, inspiration .
For build on information, see about_Providers.