# powershell

* [aliases](#aliases)
* [Basic](#basic)
* [disk](#disk)
* [zip folders](#zip-folders)
* [list top processes sort by memory](#list-top-processes-sort-by-memory)
* [sum memory of all processes](#sum-memory-of-all-processes)
* [list and grep process members](#list-and-grep-process-members)
* [query process by WMI](#query-process-by-wmi)

## aliases

```
% = foreach = ForEach
? = where = Where-Object  # ?{ $_ -NotMatch "regex" } 
```

## Basic

```
Set-ExecutionPolicy RemoteSigned
Enable-PSRemoting -Force

Import-Module ServerManager
Add-WindowsFeature RDS-Virtualization
```

## disk

```
GWMI -namespace root\cimv2 -class win32_volume | FL -property DriveLetter, DeviceID
```

## zip folders

```
Get-ChildItem -Directory | ForEach-Object {
    Compress-Archive -Path $_.FullName -DestinationPath "$($_.Name).zip" -Force
}
```

## list top processes sort by memory

```
Get-Process | Sort WorkingSet -Descending  | select-object  Id, Name, 
@{Name='WorkingSet(Mb)';Expression={"{0:N2}" -f ($_.WorkingSet / 1Mb)}}, 
@{Name='PrivateMemorySize(Mb)';Expression={"{0:N2}" -f ($_.PrivateMemorySize / 1Mb)}}, 
@{Name='PM(Mb)';Expression={"{0:N2}" -f ($_. PM/ 1Mb)}}, 
@{Name='NPM(Mb)';Expression={"{0:N2}" -f ($_. NPM/ 1Mb)}}  `
-First 10 | Format-Table
```

## sum memory of all processes

```
Get-Process  | measure-object -sum 'PrivateMemorySize', PM,NPM,WS  |  
select-object  @{Name='Sum(Gb)';Expression={"{0:N2}" -f ($_.sum / 1Gb  ) }  } ,count, Property
```

## list and grep process members

```
Get-Process | Get-Member | findstr Mem
```

## query process by WMI

```
Get-WMIObject Win32_Process
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://book.ferro.pro/dev/powershell.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
