Some examples of the use of basic powershell

Check the beginning of the command get,

View Help,

View a process,

View a specific command help,

List processes related commands,

Command list,

Memory-related performance counter list,

Kill process,

Call wmi view memory,

Powershell for entering a way,

As a calculator,

CMD operation following text;

Windows PowerShell
Copyright (C) Microsoft Corporation. all rights reserved.

PS C:\Users\Administrator> 3+9
12
PS C:\Users\Administrator> 99/23
4.30434782608696
PS C:\Users\Administrator> 3+9*5.6
53.4
PS C:\Users\Administrator> get-help

Theme
Windows PowerShell Help System

Short description
Displays help about Windows PowerShell cmdlet and the concept of.

Detailed description
    "Windows PowerShell Help," describes the Windows PowerShell cmdlet,
    function, script and modules, and explains the
    concept of language and other elements of Windows PowerShell.
    ......;


PS C:\Users\Administrator> get-command

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           Add-AppPackage                                     2.0.1.0    Appx
Alias           Add-AppPackageVolume                               2.0.1.0    Appx
Alias           Add-AppProvisionedPackage                          3.0        Dism
Alias           Add-ProvisionedAppPackage                          3.0        Dism
Alias           Add-ProvisionedAppxPackage                         3.0        Dism
Alias           Add-ProvisioningPackage                            3.0        Provisioning
Alias           Add-TrustedProvisioningCertificate                 3.0        Provisioning
Alias           Apply-WindowsUnattend                              3.0        Dism
Alias           Begin-WebCommitDelay                               1.0.0.0    WebAdministration
Alias           Disable-PhysicalDiskIndication                     2.0.0.0    Storage
Alias           Disable-StorageDiagnosticLog                       2.0.0.0    Storage
......
Function        A:
Function        Add-BCDataCacheExtension                           1.0.0.0    BranchCache
Function        Add-BitLockerKeyProtector                          1.0.0.0    BitLocker
Function        Add-DnsClientNrptRule                              1.0.0.0    DnsClient
Function        Add-DtcClusterTMMapping                            1.0.0.0    MsDtc
......
Cmdlet          Add-AppvClientConnectionGroup                      1.0.0.0    AppvClient
Cmdlet          Add-AppvClientPackage                              1.0.0.0    AppvClient
Cmdlet          Add-AppvPublishingServer                           1.0.0.0    AppvClient
......

PS C:\Users\Administrator> get-help get-*

Name                              Category  Module                    Synopsis
----                              --------  ------                    --------
Get-Verb                          Function
Get-FileHash                      Function  Microsoft.PowerShell.U... ...
Get-Command                       Cmdlet    Microsoft.PowerShell.Core ...
Get-Help                          Cmdlet    Microsoft.PowerShell.Core ...
Get-History                       Cmdlet    Microsoft.PowerShell.Core ...
Get-Job                           Cmdlet    Microsoft.PowerShell.Core ...
......

PS C:\Users\Administrator> get-help get-process

Name
    Get-Process

语法
    Get-Process [[-Name] <string[]>]  [<CommonParameters>]

......


PS C:\Users\Administrator> $ops=Get-WmiObject -Class Win32_OperatingSystem
PS C:\Users\Administrator> "机器名: {0}" -f $ops.csname
机器名: DESKTOP-1A10T3K
PS C:\Users\Administrator> "可用内存(MB): {0}" -f ([math]::round($ops.FreePhysicalMemory / 1kb, 2))
可用内存(MB): 8830.09
PS C:\Users\Administrator> (Get-Counter -ListSet memory).Counter
\Memory\Page Faults/sec
\Memory\Available Bytes
\Memory\Committed Bytes
\Memory\Commit Limit
\Memory\Write Copies/sec
\Memory\Transition Faults/sec
\Memory\Cache Faults/sec
\Memory\Demand Zero Faults/sec
\Memory\Pages/sec
......

PS C:\Users\Administrator> get-command *process

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Function        Get-AppvVirtualProcess                             1.0.0.0    AppvClient
Function        Start-AppvVirtualProcess                           1.0.0.0    AppvClient
Cmdlet          Debug-Process                                      3.1.0.0    Microsoft.PowerShell.Management
Cmdlet          Enter-PSHostProcess                                3.0.0.0    Microsoft.PowerShell.Core
Cmdlet          Exit-PSHostProcess                                 3.0.0.0    Microsoft.PowerShell.Core
Cmdlet          Get-Process                                        3.1.0.0    Microsoft.PowerShell.Management
Cmdlet          Start-Process                                      3.1.0.0    Microsoft.PowerShell.Management
Cmdlet          Stop-Process                                       3.1.0.0    Microsoft.PowerShell.Management
Cmdlet          Wait-Process                                       3.1.0.0    Microsoft.PowerShell.Management


C PS: \ the Users \ Administrator> GET-Process -name "mssqlserver"
GET-Process: Can not find "mssqlserver" process. Verify that the process name, and then call the cmdlet again.
Location Line: Character 1: 1
+ GET-Process -name "the MSSQLServer"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo: ObjectNotFound: (MSSQLServer: String) [the Get-Process], ProcessCommandException
    + FullyQualifiedErrorId: NoProcessFoundForGivenName, Microsoft.PowerShell.Commands.GetProcessCommand

PS C:\Users\Administrator> get-process -name "notepad"

Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
-------  ------    -----      -----     ------     --  -- -----------
    399      30     8812      28868       3.27    812   1 notepad
    702     191    43412      56372      55.31   1916   1 notepad


C PS: \ the Users \ Administrator> GET-Process -name "kminisite.exe"
GET-Process: Can not find "kminisite.exe" process. Verify that the process name, and then call the cmdlet again.
Location Line: Character 1: 1
+ GET-Process -name "kminisite.exe"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
    + CategoryInfo: ObjectNotFound: (kminisite.exe: String) [the Get-Process], ProcessCommandException
    + FullyQualifiedErrorId: NoProcessFoundForGivenName, Microsoft.PowerShell.Commands.GetProcessCommand

PS C:\Users\Administrator> get-process -name "kminisite"

Handles NPM (K), PM (K) WS (K), the CPU (s) Id ProcessName SI
------- ------ ------ ----- ----- - - - -----------
    682 61 47228 87264 9.53 22016 1 kminisite


C PS: \ the Users \ Administrator> STOP-Process -id 22016
STOP-Process: due to the following error could not stop the process "kminisite (22016)": Access is denied.
Location by: Character 1: 1
+ STOP-22016 Process -id
+ ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo: CloseError: (the System.Diagnostics.Process ( kminisite): Process) [the Stop-Process], ProcessComma
    ndException
    + FullyQualifiedErrorId: CouldNotStopProcess, Microsoft.PowerShell.Commands.StopProcessCommand

PS C:\Users\Administrator>

Published 475 original articles · won praise 545 · Views 3.04 million +

Guess you like

Origin blog.csdn.net/bcbobo21cn/article/details/104467118