Update powershell.md

This commit is contained in:
Alexander 2024-09-14 16:29:38 -04:00 committed by GitHub
parent eed0f3807d
commit 2d1727cecb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,26 +5,36 @@
Gets items in a specified location. To list the folders in my drive C, I will run
the command below:
`Get-ChildItem c:/`
`Get-ChildItem c:\`
This will list all the top-level folders. To list all files, folders include subfolders use the -Recurse parameter.
This will list all the top-level folders. To list all files, folders include sub-folders use the `-Recurse` parameter.
# Copy-Item and Move-Item
You could use the Get-ChildItem Cmdlet to list items in a folder, then pipe
the result to Copy-Item Cmdlet to copy the items to a new location. The
You could use the __Get-ChildItem__ Cmdlet to list items in a folder, then pipe
the result to __Copy-Item__ Cmdlet to copy the items to a new location. The
command below will do the job:
`Get-ChildItem C:\Dropbox | Copy-Item -Destination C:\NewFolder`
The above PowerShell command will only copy the top-level folders and
files - it will NOT copy sub-folders and files. To copy all files and folders
including sub-folders, include the -Recurse parameter in the Get-ChildItem
including sub-folders, include the -Recurse parameter in the __Get-ChildItem__
command as shown below:
`Get-ChildItem C:\Dropbox -Recurse | Copy-Item -Destination C:\NewFolder`
While the Copy-Item Cmdlet copies items from one location to another the
Move-Item Cmdlet moves the item.
While the __Copy-Item__ Cmdlet copies items from one location to another the
__Move-Item__ Cmdlet moves the item.
# RemoveItem
# NewItem
__New-Item__ can be used to create files, folders and registry keys and entries. The command below creates a text
file called weekly_file.txt in c:\logfiles folder:
`New-Item -Path c:\logfiles -Name weekly_file.tx`