Compare commits

...

12 Commits

Author SHA1 Message Date
Alexandre B
361c206a4c
Update powershell.md
Some checks are pending
Deploy Jekyll with GitHub Pages dependencies preinstalled / build (push) Waiting to run
Deploy Jekyll with GitHub Pages dependencies preinstalled / deploy (push) Blocked by required conditions
2024-09-14 16:44:19 -04:00
Alexandre B
9eb9be3af2
Update powershell.md 2024-09-14 16:42:10 -04:00
Alexandre B
bf14cecdac
Update powershell.md 2024-09-14 16:38:39 -04:00
Alexandre B
fc989a489f
Update powershell.md 2024-09-14 16:37:40 -04:00
Alexandre B
31614eccec
Update powershell.md 2024-09-14 16:33:27 -04:00
Alexandre B
19ae31359c
Update powershell.md 2024-09-14 16:32:37 -04:00
Alexandre B
305678d5ec
Update powershell.md 2024-09-14 16:32:27 -04:00
Alexandre B
53b049d9ef
Update powershell.md 2024-09-14 16:32:15 -04:00
Alexandre B
61f9773d5c
Update powershell.md 2024-09-14 16:32:02 -04:00
Alexandre B
60ec8d656b
Update powershell.md 2024-09-14 16:31:46 -04:00
Alexandre B
a507040d39
Update powershell.md 2024-09-14 16:29:54 -04:00
Alexandre B
2d1727cecb
Update powershell.md 2024-09-14 16:29:38 -04:00

View File

@ -1,30 +1,136 @@
# Get-Help
# Working with Files and Folders
# Get-Children
## Get-Help
## Get-Children
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
## 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`
```
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`
```
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.
## 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
```
## RenameItem
__Rename-Item__ Cmdlet is used to rename things in Windows. This Cmdlet can
rename files, folders and registry keys. This command will rename
weekly_file.txt to monthly_file.txt
```
Rename-Item -Path C:\logfiles\weekly_file.txt -NewName monthly_file.txt
```
## Export-Csv
__Export-Csv__ converts a set of string into CSV and saves in a file. This Cmdlet
is very important in reporting.
```
Get-Command -Verb Export
```
```
Get-Command -Verb Export | Select-Object CommandType, Name, Version, Source | Export-Csv -
NoTypeInformation -Path C:\NewFolder\ExportCommands.CSV
```
# Managing Processes
## Get-Process
This PowerShell Cmdlet lists all the processes running on a local computer. If
you use the ComputerName parameter, you can display the processes on a
remote computer.
### Start-Process and Stop-Process
The __Start-Process__ Cmdlet can start a stopped process while the __Stop-Process__ Cmdlet
can stop a running process.
To start a process, pipe the output of __Get-Process__ command to the __Start-Process__ command.
As an example, to stop a process with ID 10500, use the command below.
```
Get-Process -Id 10500 | Stop-Process
```
# Getting Computer Information
## Get-WmiObject
__Get-WmiObject__ has a parameter called -Class this allows you to specify the WMI object you wish to access. The command below will get a list of WMI
classes, Get-WmiObject -List -Class Win32*
Once you know the name of the WMI class, you can execute __Get-WmiObject__ to return useful information from a local or remote computer. Below is a list
of the most important WMI classes you may need:
- Win32_PhysicalMemory - information about available memory
- Win32_Processor - Processor information
- Win32_LogicalDisk - Logical disk drive information
- Win32_DiskDrive - Physical disk information
- Win32_OperatingSystem - Information about the operating system
To get information about the operating system, run the command below:
```
Get-WmiObject -Class Win32_OperatingSystem
```
## SYSTEMINFO
__SYSTEMINFO__ displays operating system configuration information for a local or remote computer.
```
SYSTEMINFO /FO LIST
```
## DRIVEQUERY
__ DRIVERQUERY__ displayS a list of installed device drivers on a local or remote computer.
```
DRIVEQUERY /FO TABLE
```
While the Copy-Item Cmdlet copies items from one location to another the
Move-Item Cmdlet moves the item.