[关闭]
@cyysu 2017-10-23T12:25:03.000000Z 字数 3121 阅读 856

powershell-安装篇

  • 时间:2017年10月23日
  • 作者:Kali
  • 邮箱:cyysu.github.io@gmail.com/2869905223@qq.com/微信lwyx1413
  • 版本:4.0
  • 描述:我们这里的安装平台采用Linux,如果是windows平台可能都需要你来安装。

powershell系列教程


ubuntu16.04安装

  1. # 第一种方法 加入APT源,然后apt安装
  2. curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
  3. curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/microsoft.list
  4. sudo apt-get update
  5. sudo apt-get install -y powershell
  6. # 第二种方法 下载powershell deb包进行安装,这里推荐采用这个方式
  7. 大家到下面那这个网址自己去下载,然后按照deb包安装方式进行安装。

https://github.com/PowerShell/PowerShell/tree/master

常见的几个命令

  1. # 这里建议大家执行的时候在英文路径下,目前这个对中文支持还不是很好。
  2. mj@DZ:~/powershell$ powershell
  3. PowerShell v6.0.0-beta.8
  4. Copyright (C) Microsoft Corporation. All rights reserved.
  5. PS /home/mj/powershell>
  6. PS /home/mj/powershell> dir
  7. PS /home/mj/powershell> touch 123.txt
  8. PS /home/mj/powershell> dir
  9. Directory: /home/mj/powershell
  10. Mode LastWriteTime Length Name
  11. ---- ------------- ------ ----
  12. ------ 17/10/23 下午8:02 0 123.txt
  13. PS /home/mj/powershell>
  14. # 清除命令
  15. 可以使用Linux下的clear或者windows下的cls
  16. # 获取时间命令
  17. PS /home/mj/powershell> Get-Date
  18. 20171023日星期一 下午8:03:47
  19. # 获取系统开机时间
  20. PS /home/mj/powershell> Get-Uptime
  21. Days : 1
  22. Hours : 16
  23. Minutes : 55
  24. Seconds : 9
  25. Milliseconds : 0
  26. Ticks : 1473090000000
  27. TotalDays : 1.70496527777778
  28. TotalHours : 40.9191666666667
  29. TotalMinutes : 2455.15
  30. TotalSeconds : 147309
  31. TotalMilliseconds : 147309000
  32. # 获取当前目录的两种方式
  33. PS /home/mj/powershell> pwd
  34. Path
  35. ----
  36. /home/mj/powershell
  37. PS /home/mj/powershell> Get-Location
  38. Path
  39. ----
  40. /home/mj/powershell
  41. # 常见的创建删除命令啥的我推荐用Linux上的,毕竟我们很熟悉Linux上命令了。
  42. rm rmdir mkdir touch cat ls cp 等等
  43. # 如果想查看某个命令的使用信息如:
  44. cpio --help
  45. # 显示系统中所有的进程。
  46. PS /home/mj/powershell> Get-Process
  47. NPM(K) PM(M) WS(M) CPU(s) Id SI ProcessName
  48. ------ ----- ----- ------ -- -- -----------
  49. 0 0.00 2.04 0.00 2138 126 (sd-pam)
  50. 0 0.00 2.05 0.00 2745 743 (sd-pam)
  51. 0 0.00 7.66 2.73 1068 068 accounts-daemon
  52. 0 0.00 0.00 0.00 98 0 acpi_thermal_pm
  53. # 如果我们想查看某一进程的详细信息
  54. PS /home/mj/powershell> Get-Process systemd
  55. NPM(K) PM(M) WS(M) CPU(s) Id SI ProcessName
  56. ------ ----- ----- ------ -- -- -----------
  57. 0 0.00 5.77 6.26 1 1 systemd
  58. 0 0.00 4.74 0.06 2126 126 systemd
  59. 0 0.00 4.83 0.05 2743 743 systemd
  60. # 显示命令的帮助
  61. PS /home/mj/powershell> Get-Help clear
  62. NAME
  63. Clear-Host
  64. SYNOPSIS
  65. Clears the display in the host program.
  66. SYNTAX
  67. Clear-Host [<CommonParameters>]
  68. DESCRIPTION
  69. The Clear-Host function removes all text from the current display, including commands and output that might have accumula
  70. ted. When complete, it displays the command prompt. You can use the function name or its alias, CLS.
  71. Clear-Host affects only the current display. It does not delete saved results or remove any items from the session. Sessi
  72. on-specific items, such as variables and functions, are not affected by this function.
  73. Because the behavior of the Clear-Host function is determined by the host program, Clear-Host might work differently in d
  74. ifferent host programs.
  75. # 查看所有命令
  76. PS /home/mj/powershell> Get-Command
  77. CommandType Name Version Source
  78. ----------- ---- ------- ------
  79. Function Add-NodeKeys 0.0 PSDesiredStateConfiguration
  80. Function AddDscResourceProperty 0.0 PSDesiredStateConfiguration
  81. Function AddDscResourcePropertyFromMetadata 0.0 PSDesiredStateConfiguration
  82. # 显示命令设置的别名
  83. PS /home/mj/powershell> Get-Alias
  84. CommandType Name Version Source
  85. ----------- ---- ------- ------
  86. Alias ? -> Where-Object
  87. Alias % -> ForEach-Object
  88. # 给命令设置别名
  89. PS /home/mj/powershell> Set-Alias
  90. cmdlet Set-Alias at command pipeline position 1
  91. Supply values for the following parameters:
  92. Name:

打赏

                    支付宝                                                         微信

微信与支付宝支付

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注