Вы находитесь на странице: 1из 6

**********************

Windows PowerShell Transcript Start


Start time: *****************
Username : *****************
Machine : *****************
**********************
Transcript started, output file is C:\FolderManagementP2.txt
PS C:\windows\system32> get-help new-item

NAME
New-Item

SYNOPSIS
Creates a new item in a namespace.

SYNTAX
New-Item [-path] <string[]> [-force] [-credential <PSCredential>] [-itemType <string>] [-value
<Object>] [-whatIf]
[-confirm] [<CommonParameters>]

New-Item [-path] <string[]> -name <string> [-force] [-credential <PSCredential>] [-itemType <string>]
[-value <Obje
ct>] [-whatIf] [-confirm] [<CommonParameters>]

DETAILED DESCRIPTION
Creates a new item in a namespace. The type of items that can be created depend upon the Windows
PowerShell provide
r used. New-Item is used to create files and folders when using the FileSystem provider and creates new
registry ke
ys and entries when using the Registry provider. The cmdlet can also set the value of the new item. When
creating a
new file, for instance, you can use New-Item to add initial content to the file.

RELATED LINKS
Get-Item
Set-Item
Remove-Item
Clear-Item
Invoke-Item
Rename-Item
Move-Item
Copy-Item
about_namespace

REMARKS
For more information, type: "get-help New-Item -detailed".
For technical information, type: "get-help New-Item -full".

PS C:\windows\system32> get-help remove-item -detailed

NAME
Remove-Item

SYNOPSIS
Deletes the specified items.

SYNTAX
Remove-Item [-path] <string[]> [-recurse] [-force] [-include <string[]>] [-exclude <string[]>] [-filter
<string>] [
-credential <PSCredential>] [-whatIf] [-confirm] [<CommonParameters>]

Remove-Item [-literalPath] <string[]> [-recurse] [-force] [-include <string[]>] [-exclude <string[]>]


[-filter <str
ing>] [-credential <PSCredential>] [-whatIf] [-confirm] [<CommonParameters>]

DETAILED DESCRIPTION
The Remove-Item cmdlet deletes one or more items. Because it is supported by many providers, it can
delete many dif
ferent types of items, including files, directories, registry keys, variables, aliases, certificates, and
functions
.

PARAMETERS
-path <string[]>
Specifies a path to the items being removed. Wildcards are permitted. The parameter name ("-Path") is
optional.

-recurse <SwitchParameter>
Deletes the items in the specified locations and in all child items of the locations.

The Recurse parameter in this cmdlet does not work properly.

-force <SwitchParameter>
Overrides restrictions that prevent the command from succeeding, just so the changes do not
compromise security
. For example, Force will override the read-only attribute or create directories to complete a file path,
but i
t will not attempt to change file permissions.

-include <string[]>
Deletes only the specified items. The value of this parameter qualifies the Path parameter. Enter a path
elemen
t or pattern, such as "*.txt".Wildcards are permitted.

-exclude <string[]>
Omits the specified items. The value of this parameter qualifies the Path parameter. Enter a path
element or pa
ttern, such as "*.txt". Wildcards are permitted.

-filter <string>
Specifies a filter in the provider's format or language. The value of this parameter qualifies the Path
paramet
er. The syntax of the filter, including the use of wildcards, depends on the provider. Filters are more
efficie
nt than other parameters, because the provider applies them when retrieving the objects, rather than
having Win
dows PowerShell filter the objects after they are retrieved.

-credential <PSCredential>
Uses a credential to validate access to the file. <Credential> represents a user-name, such as "User01"
or "Dom
ain01\User01", or a PSCredential object, such as the one retrieved by using the Get-Credential cmdlet.
If you t
ype a user name, you will be prompted for a password. This parameter appears, but it is not supported
in any Wi
ndows PowerShell core cmdlets or providers.

-literalPath <string[]>
Specifies a path to the items being removed. Unlike Path, the value of LiteralPath is used exactly as it
is typ
ed. No characters are interpreted as wildcards. If the path includes escape characters, enclose it in
single qu
otation marks. Single quotation marks tell Windows PowerShell not to interpret any characters as
escape sequenc
es.

-whatIf
Describes what would happen if you executed the command without actually executing the command.

-confirm
Prompts you for confirmation before executing the command.

<CommonParameters>
This cmdlet supports the common parameters: -Verbose, -Debug,
-ErrorAction, -ErrorVariable, and -OutVariable. For more information,
type, "get-help about_commonparameters".

-------------------------- EXAMPLE 1 --------------------------

C:\PS>remove-item C:\Test\*.*

This command deletes all of the files with names that include a dot (.) from the C:\Test directory.
Because the com
mand specifies a dot, the command does not delete directories, or files with no file name extension.

-------------------------- EXAMPLE 2 --------------------------

C:\PS>remove-item * -include *.doc -exclude *1*

This command deletes from the current directory all files with a .doc file name extension and a name that
does not
include "1". It uses the wildcard character (*) to specify the contents of the current directory. It uses the
Inclu
de and Exclude parameters to specify the files to delete.
-------------------------- EXAMPLE 3 --------------------------

C:\PS>remove-item -path C:\Test\hidden-RO-file.txt -force

This command deletes a file that is both hidden and read-only. It uses the Path parameter to specify the
file. It u
ses the Force parameter to give permission to delete it. Without Force, you cannot delete read-only or
hidden files
.

-------------------------- EXAMPLE 4 --------------------------

C:\PS>get-childitem * -include *.csv -recurse | remove-item

This command deletes all of the CSV files in the current directory and all subdirectories recursively.

Because the Recurse parameter in this cmdlet is faulty, the command uses the Get-Childitem cmdlet to
get the desire
d files, and the pipeline operator to pass them to the Remove-Item cmdlet.

In the Get-Childitem command, the Path parameter has a value of *, which represents the contents of the
current dir
ectory. It uses the Include parameter to specify the CSV file type, and the Recurse parameter to make the
retrieval
recursive.

If you try to specify the file type in the path, such as "-path *.csv", the cmdlet interprets the subject of the
se
arch to be a file that has no children, and the Recurse fails.

-------------------------- EXAMPLE 5 --------------------------

C:\PS>remove-item hklm:\software\mycompany\OldApp -recurse

This command deletes the OldApp registry key and all of its subkeys and values. It uses the Remove-
Item cmdlet to r
emove the key. The path is specified, but the optional parameter name (Path) is omitted.

The Recurse parameter deletes all of the contents of the OldApp subkey recursively. If the key contains
subkeys, an
d you omit the Recurse paraemter, you are prompted to confirm that the you want to delete the contents
of the key.

REMARKS
For more information, type: "get-help Remove-Item -detailed".
For technical information, type: "get-help Remove-Item -full".
PS C:\windows\system32> new-item -path "c:\powershell\" -type "Directory"

Directory: Microsoft.PowerShell.Core\FileSystem::C:\

Mode LastWriteTime Length Name


---- ------------- ------ ----
d---- 4/16/2009 7:35 PM powershell

PS C:\windows\system32> set-location "c:\powershell"


PS C:\powershell> new-item -path "c:\powershell\text.txt" -type "File"

Directory: Microsoft.PowerShell.Core\FileSystem::C:\powershell

Mode LastWriteTime Length Name


---- ------------- ------ ----
-a--- 4/16/2009 7:36 PM 0 text.txt

PS C:\powershell> new-item -path "c:\powershell\text.csv" -type "File"

Directory: Microsoft.PowerShell.Core\FileSystem::C:\powershell

Mode LastWriteTime Length Name


---- ------------- ------ ----
-a--- 4/16/2009 7:36 PM 0 text.csv

PS C:\powershell> new-item -path "c:\powershell\text.config" -type "File"

Directory: Microsoft.PowerShell.Core\FileSystem::C:\powershell

Mode LastWriteTime Length Name


---- ------------- ------ ----
-a--- 4/16/2009 7:36 PM 0 text.config

PS C:\powershell> get-childitem

Directory: Microsoft.PowerShell.Core\FileSystem::C:\powershell

Mode LastWriteTime Length Name


---- ------------- ------ ----
-a--- 4/16/2009 7:36 PM 0 text.config
-a--- 4/16/2009 7:36 PM 0 text.csv
-a--- 4/16/2009 7:36 PM 0 text.txt

PS C:\powershell> remove-item -path "c:\powershell\*" -exclude "*.txt"


PS C:\powershell> get-childitem

Directory: Microsoft.PowerShell.Core\FileSystem::C:\powershell

Mode LastWriteTime Length Name


---- ------------- ------ ----
-a--- 4/16/2009 7:36 PM 0 text.txt

PS C:\powershell> set-location -path "c:"


PS C:\powershell> set-location ..
PS C:\> remove-item -path "c:\powershell"

Confirm
The item at C:\powershell has children and the Recurse parameter was not specified. If you continue, all
children will
be removed with the item. Are you sure you want to continue?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): a
PS C:\> set-location -path "c:\powershell"
Set-Location : Cannot find path 'C:\powershell' because it does not exist.
At line:1 char:13
+ set-location <<<< -path "c:\powershell"
PS C:\> stop-transcript
**********************
Windows PowerShell Transcript End
End time: *************
**********************

Вам также может понравиться