1.Overview of Windows PowerShell

简介: PS C:/Documents and Settings/somebody> cd c:/ PS C:/> dirPS C:/> md c:/testPS C:/> cd c:/testPS C:/test> fsutil file createNew c:/test/myNewFile.

PS C:/Documents and Settings/somebody> cd c:/
PS C:/> dir
PS C:/> md c:/test
PS C:/> cd c:/test
PS C:/test> fsutil file createNew c:/test/myNewFile.txt 1000
File c:/test/myNewFile.txt is created
PS C:/test> dir
PS C:/test> del *.txt
PS C:/test> cd c:/
PS C:/> rd c:/test


PS C:/> ipconfig /all >ipconfig.txt
PS C:/> notepad ipconfig.txt

PS C:/> ipconfig /all >tshoot.txt; route print >>tshoot.txt; netdiag /q >>tshoot.txt; net statistics workstation >>tshoot.txt;

cmdlets arguments :-whatif,-confirm

PS C:/> get-process note*

Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName
-------  ------    -----      ----- -----   ------     -- -----------
     65       7     1648       6724    79     0.37   5124 notepad

PS C:/> notepad
PS C:/> get-process note*

Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName
-------  ------    -----      ----- -----   ------     -- -----------
     65       7     1648       6724    79     0.37   5124 notepad
     66       7     1656       6128    91     0.06   5428 notepad

PS C:/> stop-process -id 5428 -whatif
What if: Performing operation "Stop-Process" on Target "notepad (5428)".

PS C:/> stop-process -id 5428 -confirm

Confirm
Are you sure you want to perform this action?
Performing operation "Stop-Process" on Target "notepad (5428)".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): y

PS C:/> exit

PS C:/> Export-Console myconsole

PS C:/> PowerShell -version 1
Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.

PS C:/> PowerShell -version 2
Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.

PS C:/> PowerShell -version 3
Cannot start Windows PowerShell version 3 because it is not correctly installed.

PS C:/> PowerShell -nologo
PS C:/> PowerShell -psconsolefile myConsole.psc1
Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.


#
Parameter
 Meaning
 
-whatif
 Tells the cmdlet to not execute but to tell you what would happen if the cmdlet were to run
 
-confirm
 Tells the cmdlet to prompt before executing the command
 
-verbose
 Instructs the cmdlet to provide a higher level of detail than a cmdlet not using the verbose parameter
 
-debug
 Instructs the cmdlet to provide debugging information
 
-ErrorAction
 Instructs the cmdlet to perform a certain action when an error occurs. Allowed actions are: continue, stop, silentlyContinue, and inquire.
 
-ErrorVariable
 Instructs the cmdlet to use a specific variable to hold error information. This is in addition to the standard $error variable.
 
-Outvariable
 Instructs the cmdlet to use a specific variable to hold the output information
 
-OutBuffer
 Instructs the cmdlet to hold a certain number of objects before calling the next cmdlet in the pipeline
 
 Note  To get help on any cmdlet, use the Get-Help cmdletname cmdlet.
 
get-help get-help

PS C:/> get-help get*

PS C:/> get-help getdrive -example

1.Retrieve an alphabetic listing of all currently defined aliases, and inspect the list for one assigned to either the Get-Help cmdlet or the key stroke combination gh. The command to do this is as follows:
get-alias |sort
2.After you have determined that there is no alias for the Get-Help cmdlet, and that none is assigned to the gh key stroke combination, review the syntax for the Set-Alias cmdlet. Use the -full argument to the Get-Help cmdlet. This is shown here:
get-help set-alias -full
3.Use the Set-Alias cmdlet to assign the gh key stroke combination to the Get-Help cmdlet. To do this, use the following command:
set-alias gh get-help

1.Change to the C:/ root directory by typing cd C:/ inside the PowerShell prompt:

Cd c:/
2.Obtain a listing of all the files in the C:/ root directory by using the dir command:

dir
3.Create a directory off the C:/ root directory by using the md command:

Md mytest
4.Obtain a listing of all files and folders off the root that begin with the letter m:

Dir m*
5.Change the working directory to the PowerShell working directory. You can do this by using the Set-Location command as follows:

Set-location $pshome
6.Obtain a listing of memory counters related to the available bytes by using the typeperf command. This command is shown here:

typeperf "/memory/available bytes"
7.After a few counters have been displayed in the PowerShell window, use the ctrl-c command to break the listing.

8.Display the current boot configuration by using the bootcfg command:

Bootcfg
9.Change the working directory back to the C:/Mytest directory you created earlier:

set-location c:/mytest
10.Create a file named Mytestfile.txt in the C:/Mytest directory. Use the fsutil utility, and make the file 1,000 bytes in size. To do this, use the following command:

fsutil file createnew mytestfile.txt 1000
11.Obtain a “directory listing” of all the files in the C:/Mytest directory by using the Get-ChildItem cmdlet. This is shown here:

get-childitem
12.Print out the current date by using the Get-Date cmdlet. This is shown here:

get-date
13.Clear the screen by using the cls command. This is shown here:

cls
14.Print out a listing of all the cmdlets built into Windows PowerShell. To do this, use the Get-Command cmdlet. This is shown here:

get-command
15.Use the Get-Command cmdlet to get the Get-Alias cmdlet. To do this, use the -name argument while supplying Get-Alias as the value for the argument. This is shown here:

get-command -name get-alias
16.This concludes the step-by-step exercise. Exit the Windows PowerShell by typing exit and pressing Enter.


get-help get-help -detailed
get-help get-help -full
get-help get-help -examples

目录
打赏
0
0
0
0
20
分享
相关文章
|
6月前
|
Powershell 重新排列去重 Windows环境变量
【9月更文挑战第13天】本文介绍如何使用PowerShell对Windows环境变量进行重新排列和去重。首先通过`$env:`访问环境变量,接着使用`-split`命令分割路径,再利用`Select-Object -Unique`去除重复项。之后可根据需要对路径进行排序,最后将处理后的路径组合并更新环境变量。注意修改环境变量前应备份重要数据并了解潜在影响。
198 10
PowerShell 脚本编写 :自动化Windows 开发工作流程
PowerShell 脚本编写 :自动化Windows 开发工作流程
210 0
内网渗透测试基础——Windows PowerShell篇
内网渗透测试基础——Windows PowerShell篇
174 0
|
10月前
|
【vscode】 VsCode终端崩溃C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe已终止,退出代码:2
【vscode】 VsCode终端崩溃C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe已终止,退出代码:2
1384 1
|
10月前
|
windows可以安装Ubuntu,ubuntu上也可以安装Powershell
powerhsell除了可以在windows上使用外,还可以在Ubuntu上部署开发环境。下面介绍Ubuntu上安装powershell的方法。
271 0
windows中cmd和PowerShell批处理命令
之前在 Git 批量删除本地分支,有用到 Linux 或 MacOS 下的批处理命令,这个命令中的 grep、xargs 本身是 Shell script,在 windows 中的 cmd 和 PowerShell 中是不能用的
150 0
使用PowerShell获取Windows当前锁屏壁纸
使用PowerShell获取Windows当前锁屏壁纸 如果原始图片丢了,用这段代码就可以提取当前锁屏壁纸了!
219 0
前端开发工具 vscode 使用技巧篇:控制台由powershell切换为cmd方法,windows下新旧版控制台cmd与powershell互切方法
前端开发工具 vscode 使用技巧篇:控制台由powershell切换为cmd方法,windows下新旧版控制台cmd与powershell互切方法
506 0
前端开发工具 vscode 使用技巧篇:控制台由powershell切换为cmd方法,windows下新旧版控制台cmd与powershell互切方法

相关课程

更多
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等