windows/*: add page (#8783)

* Add some PowerShell related commands

* Include new pages for start-service, stop-service, set-service, show-markdown, resolve-path

* Include new pages for measure-command.md, tee-object.md, get-acl.md, and set-acl.md

* Include new pages for get-date, set-date, measure-object, sort-object, test-json, wait-process

* Remove i18n identifier from all added pages

* get-acl: Better wording and fix missing placeholder
sls: Use kebab-case for tldr view original command

* get-date: Better wording and change date string to ISO

* test-json: Better wording, generic json, and add one more example

* Add token {{}} to some missing places

* Apply suggestions from code review

Co-authored-by: Axel Navarro <navarroaxel@gmail.com>

* Fix typo on pages/windows/resolve-path.md

Co-authored-by: K.B.Dharun Krishna <kbdharunkrishna@gmail.com>

* Update pages/windows/measure-object.md

Co-authored-by: Axel Navarro <navarroaxel@gmail.com>
Co-authored-by: K.B.Dharun Krishna <kbdharunkrishna@gmail.com>
pull/1/head
Fernando Crespo 2022-12-21 01:26:27 -03:00 committed by GitHub
parent 7ff1585c3b
commit aed340476f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 319 additions and 0 deletions

13
pages/windows/get-acl.md Normal file
View File

@ -0,0 +1,13 @@
# Get-Acl
> Gets the security descriptor for a resource, such as a file or registry key.
> This command can only be used through PowerShell.
> More information: <https://learn.microsoft.com/powershell/module/microsoft.powershell.security/get-acl>.
- Display the ACL for a specific directory:
`Get-Acl {{path/to/directory}}`
- Get an ACL for a registry key:
`Get-Acl -Path {{HKLM:\System\CurrentControlSet\Control}} | Format-List`

21
pages/windows/get-date.md Normal file
View File

@ -0,0 +1,21 @@
# Get-Date
> Gets the current date and time.
> This command can only be used through PowerShell.
> More information: <https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/get-date>.
- Display the current date and time:
`Get-Date`
- Display the current date and time with a .NET format specifier:
`Get-Date -Format "{{yyyy-MM-dd HH:mm:ss}}"`
- Display the current date and time in UTC and ISO 8601 format:
`(Get-Date).ToUniversalTime()`
- Convert a Unix timestamp:
`Get-Date -UnixTimeSeconds {{1577836800}}`

View File

@ -0,0 +1,13 @@
# Measure-Command
> Measures the time it takes to run script blocks and cmdlets.
> This command can only be used through PowerShell.
> More information: <https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/measure-command>.
- Measure the time it takes to run a command:
`Measure-Command { {{command}} }`
- Pipe input to Measure-Command (objects that are piped to `Measure-Command` are available to the script block that is passed to the Expression parameter):
`10, 20, 50 | Measure-Command -Expression { for ($i=0; $i -lt $_; $i++) {$i} }`

View File

@ -0,0 +1,13 @@
# Measure-Object
> Calculates the numeric properties of objects, and the characters, words, and lines in string objects, such as files of text.
> This command can only be used through PowerShell.
> More information: <https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/measure-object>.
- Count the files and folders in a directory:
`Get-ChildItem | Measure-Object`
- Pipe input to Measure-Command (objects that are piped to `Measure-Command` are available to the script block that is passed to the Expression parameter):
`"One", "Two", "Three", "Four" | Set-Content -Path "{{path/to/file}}"; Get-Content "{{path/to/file}}"; | Measure-Object -Character -Line -Word`

View File

@ -0,0 +1,17 @@
# Out-String
> Outputs input objects as a string.
> This command can only be used through PowerShell.
> More information: <https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/out-string>.
- Print host information as string:
`Get-Alias | Out-String`
- Convert each object to a string rather than concatenating all the objects into a single string:
`Get-Alias | Out-String -Stream`
- Use the `Width` parameter to prevent truncation:
`@{TestKey = ('x' * 200)} | Out-String -Width {{250}}`

View File

@ -0,0 +1,8 @@
# where
> This command is an alias of `Where-Object`.
> More information: <https://learn.microsoft.com/powershell/module/microsoft.powershell.core/where-object>.
- View documentation for the original command:
`tldr Where-Object`

View File

@ -0,0 +1,17 @@
# Resolve-Path
> Resolves the wildcard characters in a path, and displays the path contents.
> This command can only be used through PowerShell.
> More information: <https://learn.microsoft.com/powershell/module/microsoft.powershell.management/resolve-path>.
- Resolve the home folder path:
`Resolve-Path {{~}}`
- Resolve a UNC path:
`Resolve-Path -Path "\\{{hostname}}\{{path/to/file}}"`
- Get relative paths:
`Resolve-Path -Path {{path/to/file_or_directory}} -Relative`

View File

@ -0,0 +1,26 @@
# Select-String
> Finds text in strings and files in PowerShell.
> This command can only be used through PowerShell.
> You can use `Select-String` similar to grep in UNIX or findstr.exe in Windows.
> More information: <https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/select-string>.
- Search for a pattern within a file:
`Select-String -Path "{{path/to/file}}" -Pattern '{{search_pattern}}'`
- Search for an exact string (disables regular expressions):
`Select-String -SimpleMatch "{{exact_string}}" {{path/to/file}}`
- Search for pattern in all `.ext` files in current dir:
`Select-String -Path "{{*.ext}}" -Pattern '{{search_pattern}}'`
- Capture the specified number of lines before and after the line that matches the pattern:
`Select-String --Context {{2,3}} "{{search_pattern}}" {{path/to/file}}`
- Search stdin for lines that do not match a pattern:
`Get-Content {{path/to/file}} | Select-String --NotMatch "{{search_pattern}}"`

13
pages/windows/set-acl.md Normal file
View File

@ -0,0 +1,13 @@
# Set-Acl
> Changes the security descriptor of a specified item, such as a file or a registry key.
> This command can only be used through PowerShell.
> More information: <https://learn.microsoft.com/powershell/module/microsoft.powershell.security/set-acl>.
- Copy a security descriptor from one file to another:
`$OriginAcl = Get-Acl -Path {{path/to/file}}; Set-Acl -Path {{path/to/file}} -AclObject $OriginAcl`
- Use the pipeline operator to pass a descriptor:
`Get-Acl -Path {{path/to/file}} | Set-Acl -Path {{path/to/file}}`

17
pages/windows/set-date.md Normal file
View File

@ -0,0 +1,17 @@
# Set-Date
> Changes the system time on the computer to a time that you specify.
> This command can only be used through PowerShell.
> More information: <https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/set-date>.
- Add three days to the system date:
`Set-Date -Date (Get-Date).AddDays({{3}})`
- Set the system clock back 10 minutes:
`Set-Date -Adjust -0:10:0 -DisplayHint Time`
- Add 90 minutes to the system clock:
`$90mins = New-TimeSpan -Minutes {{90}}; Set-Date -Adjust $90mins`

View File

@ -0,0 +1,17 @@
# Set-Service
> Starts, stops, and suspends a service, and changes its properties.
> This command can only be used through PowerShell.
> More information: <https://learn.microsoft.com/powershell/module/microsoft.powershell.management/set-service>.
- Change a display name:
`Set-Service -Name {{hostname}} -DisplayName "{{name}}"`
- Change the startup type of services:
`Set-Service -Name {{service_name}} -StartupType {{Automatic}}`
- Change the description of a service:
`Set-Service -Name {{service_name}} -Description "{{description}}"`

View File

@ -0,0 +1,17 @@
# Show-Markdown
> Shows a Markdown file or string in the console in a friendly way using VT100 escape sequences or in a browser using HTML.
> This command can only be used through PowerShell.
> More information: <https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/show-markdown>.
- Render markdown to console from a file:
`Show-Markdown -Path {{path/to/file}}`
- Render markdown to console from string:
`{{"# Markdown content"}} | Show-Markdown`
- Open Markdown file in a browser:
`Show-Markdown -Path {{path/to/file}} -UseBrowser`

8
pages/windows/sls.md Normal file
View File

@ -0,0 +1,8 @@
# sls
> This command is an alias of `Select-String`.
> More information: <https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/select-string>.
- View documentation for the original command:
`tldr where-object`

View File

@ -0,0 +1,25 @@
# Sort-Object
> Sorts objects by property values.
> This command can only be used through PowerShell.
> More information: <https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/sort-object>.
- Sort the current directory by name:
`Get-ChildItem | Sort-Object`
- Sort the current directory by name descending:
`Get-ChildItem | Sort-Object -Descending`
- Sort items removing duplicates:
`"a", "b", "a" | Sort-Object -Unique`
- Sort the current directory by file length:
`Get-ChildItem | Sort-Object -Property Length`
- Sort processes with the highest memory usage based on their working set (WS) size:
`Get-Process | Sort-Object -Property WS`

View File

@ -0,0 +1,17 @@
# Start-Service
> Starts one or more stopped services.
> This command can only be used through PowerShell.
> More information: <https://learn.microsoft.com/powershell/module/microsoft.powershell.management/start-service>.
- Start a service by using its name:
`Start-Service -Name {{service_name}}`
- Display information without starting a service:
`Start-Service -DisplayName *{{name}}* -WhatIf`
- Start a disabled service:
`Set-Service {{service_name}} -StartupType {{manual}}; Start-Service {{service_name}}`

View File

@ -0,0 +1,17 @@
# Stop-Service
> Stops one or more running services.
> This command can only be used through PowerShell.
> More information: <https://learn.microsoft.com/powershell/module/microsoft.powershell.management/stop-service>.
- Stop a service on the local computer:
`Stop-Service -Name {{service_name}}`
- Stop a service by using the display name:
`Stop-Service -DisplayName "{{name}}"`
- Stop a service that has dependent services:
`Stop-Service -Name {{service_name}} -Force -Confirm`

View File

@ -0,0 +1,13 @@
# Tee-Object
> Saves command output in a file or variable and also sends it down the pipeline.
> This command can only be used through PowerShell.
> More information: <https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/tee-object>.
- Output processes to a file and to the console:
`Get-Process | Tee-Object -FilePath {{path/to/file}}`
- Output processes to a variable and `Select-Object`:
`Get-Process notepad | Tee-Object -Variable {{proc}} | Select-Object processname,handles`

View File

@ -0,0 +1,17 @@
# Test-Json
> Tests whether a string is a valid JSON document.
> This command can only be used through PowerShell.
> More information: <https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/test-json>.
- Test if a string from stdin is in JSON format:
`'{{string}}' | Test-Json`
- Test if a string JSON format:
`Test-Json -Json '{{json_to_test}}'`
- Test if a string from stdin matches a specific schema file:
`'{{string}}' | Test-Json -SchemaFile {{path/to/schema.json}}`

View File

@ -0,0 +1,13 @@
# Wait-Process
> Waits for the processes to be stopped before accepting more input.
> This command can only be used through PowerShell.
> More information: <https://learn.microsoft.com/powershell/module/microsoft.powershell.management/wait-process>.
- Stop a process and wait:
`Stop-Process -Id {{process_id}}; Wait-Process -Id {{process_id}}`
- Wait for processes for a specified time:
`Wait-Process -Name {{process_name}} -Timeout {{30}}`

View File

@ -0,0 +1,17 @@
# Where-Object
> Selects objects from a collection based on their property values.
> This command can only be used through PowerShell.
> More information: <https://learn.microsoft.com/powershell/module/microsoft.powershell.core/where-object>.
- Filter aliases by its name:
`Get-Alias | Where-Object -{{Property}} {{Name}} -{{eq}} {{name}}`
- Get a list of all services that are currently stopped. The `$_` automatic variable represents each object that is passed to the `Where-Object` cmdlet:
`Get-Service | Where-Object {$_.Status -eq "Stopped"}`
- Use multiple conditions:
`Get-Module -ListAvailable | Where-Object { $_.Name -NotLike "Microsoft*" -And $_.Name -NotLike "PS*" }`