名前 New-Item 概要 Creates a new item. 構文 New-Item [-Path] [-Credential []] [-Force] [-ItemType []] [-Value []] [-Co nfirm] [-WhatIf] [-UseTransaction []] [] New-Item [[-Path] ] [-Credential []] [-Force] [-ItemType []] [-Value []] -N ame [-Confirm] [-WhatIf] [-UseTransaction []] [] 説明 The New-Item cmdlet creates a new item and sets its value. The types of items that can be created depend on the loc ation of the item. For example, in the file system, New-Item creates files and folders. In the registry, New-Item c reates registry keys and entries. New-Item can also set the value of the items that it creates. For example, when it creates a new file, New-Item can add initial content to the file. パラメーター -Credential [] Specifies a user account that has permission to perform this action. The default is the current user. Type a user name, such as User01 or Domain01\User01, or enter a PSCredential object, such as one generated by t he Get-Credential cmdlet. If you type a user name, this cmdlet prompts you for a password. This parameter is not supported by any providers installed with Windows PowerShell. 必須 false 位置 named 既定値 none パイプライン入力を許可する True (ByPropertyName) ワイルドカード文字を許可する false -Force [] Forces this cmdlet to create an item that writes over an existing read-only item. Implementation varies from pr ovider to provider. For more information, see about_Providers. Even using the Force parameter, the cmdlet canno t override security restrictions. 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -ItemType [] Specifies the provider-specified type of the new item. Starting in Windows PowerShell 5.0, you can create symbo lic links by specifying SymbolicLink as the value of this parameter. 必須 false 位置 named 既定値 none パイプライン入力を許可する True (ByPropertyName) ワイルドカード文字を許可する false -Name Specifies the name of the new item. You can specify the name of the new item in the Name or Path parameter value, and you can specify the path of t he new item in Name or Path value. 必須 true 位置 named 既定値 none パイプライン入力を許可する True (ByPropertyName) ワイルドカード文字を許可する false -Path Specifies the path of the location of the new item. Wildcard characters are permitted. You can specify the name of the new item in Name, or include it in Path. 必須 true 位置 1 既定値 none パイプライン入力を許可する True (ByPropertyName) ワイルドカード文字を許可する false -Value [] Specifies the value of the new item. You can also pipe a value to New-Item. 必須 false 位置 named 既定値 none パイプライン入力を許可する True (ByValue, ByPropertyName) ワイルドカード文字を許可する false -Confirm [] Prompts you for confirmation before running the cmdlet.Prompts you for confirmation before running the cmdlet. 必須 false 位置 named 既定値 false パイプライン入力を許可する false ワイルドカード文字を許可する false -WhatIf [] Shows what would happen if the cmdlet runs. The cmdlet is not run.Shows what would happen if the cmdlet runs. T he cmdlet is not run. 必須 false 位置 named 既定値 false パイプライン入力を許可する false ワイルドカード文字を許可する false -UseTransaction [] Includes the command in the active transaction. This parameter is valid only when a transaction is in progress. For more information, seeIncludes the command in the active transaction. This parameter is valid only when a transaction is in progress. For more information, see 必須 false 位置 named 既定値 false パイプライン入力を許可する false ワイルドカード文字を許可する false このコマンドレットは、次の共通パラメーターをサポートします: Verbose、 Debug、ErrorAction、ErrorVariable、WarningAction、WarningVariable、 OutBuffer, PipelineVariable、および OutVariable。詳細については、 about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216) を参照してください。 入力 System.Object You can pipe a value for the new item to this cmdlet. 出力 System.Object This cmdlet returns the item that it creates. メモ New-Item is designed to work with the data exposed by any provider. To list the providers available in your ses sion, type Get-PsProvider. For more information, see about_Providers. Example 1: Create a file in the current directory PS C:\>New-Item -Path . -Name "testfile1.txt" -ItemType "file" -Value "This is a text string." This command creates a text file that is named testfile1.txt in the current directory. The dot (.) in the value of the Path parameter indicates the current directory. The quoted text that follows the Value parameter is added to th e file as content. Example 2: Create a directory PS C:\>New-Item -Path "c:\" -Name "logfiles" -ItemType "directory" This command creates a directory named Logfiles in the C: drive. The ItemType parameter specifies that the new item is a directory, not a file or other file system object. Example 3: Create a profile PS C:\>New-Item -Path $profile -ItemType "file" -Force This command creates a Windows PowerShell profile in the path that is specified by the $profile variable. You can use profiles to customize Windows PowerShell. $Profile is an automatic (built-in) variable that stores the path and file name of the CurrentUser/CurrentHost profile. By default, the profile does not exist, even though Wind ows PowerShell stores a path and file name for it. In this command, the $profile variable represents the path of the file. ItemType parameter specifies that the comma nd creates a file. The Force parameter lets you create a file in the profile path, even when the directories in the path do not exist. Windows PowerShell creates them. After you use this command to create a profile, you can enter aliases, functions, and scripts in the profile to cus tomize your shell. For more information, see about_Automatic_Variables and about_Profiles. Example 4: Create a directory in a different directory PS C:\>New-Item -ItemType "directory" -Path "c:\ps-test\scripts" This command creates a new Scripts directory in the C:\PS-Test directory. The name of the new directory item, Scripts, is included in the value of Path parameter, instead of being specified in the value of Name. As indicated by the syntax, either command form is valid. Example 5: Create multiple files PS C:\>New-Item -ItemType "file" -Path "c:\ps-test\test.txt", "c:\ps-test\Logs\test.log" This command creates files in two different directories. Because Path takes multiple strings, you can use it to cre ate multiple items. 関連するリンク Online Version: http://go.microsoft.com/fwlink/p/?linkid=293886 Clear-Item Copy-Item Get-Item Invoke-Item Move-Item Remove-Item Rename-Item Set-Item