PowerShell-学习笔记

来源:互联网 发布:魔兽世界哪些插件软件 编辑:程序博客网 时间:2024/04/29 06:26
Windows PowerShell Cmdlet 

cmdlet  (读作“command-let”)是 Windows PowerShell 中用于操作对象的单功能命令。 可以通过其名称格式识别 cmdlet --  由短划线 (-) 分隔的动词名词,如 Get-Help、Get-P rocess 和 Start-Service。 (命令不区分大小写)


1:获取 cmdlet 帮助文件命令: 

.get-help <cmdlet 名称> -detailed (要获取 Get-Command cmdlet 的详细帮助)

.get-help <cmdlet 名称> -full(若要显示 cmdlet 的所有可用帮助)

.get-help <cmdlet 名称> -examples(若要仅查看示例)

.get-help <cmdlet 名称> -parameter *(若要仅查看详细的参数说明)

.get-help <cmdlet 名称> -about_*(若要显示 Windows PowerShell 中所有概念性帮助主题的列表-概念的帮助以“about_”开头)

2:处理对象:

.get-service | get-member (Get-Member 显示有关.NET对象的信息,其中包括对象的类型名称及其属性和方法的列表。)

.get-service schedule | format-list -property *(要查找系统上 Schedule 服务的所有属性)

.(get-service alerter).canpauseandcontinue(要列出特定服务的属性值)

.get-service alerter | format-list -property name, CanPauseAndContinue(要显示 Alerter 服务的 CanPauseAndContinue 属性的名称和值列表)

.get-service alerter | format-list -property *(若要显示 Alerter 服务的所有属性值的列表)

.get-service | format-table -property name, CanPauseAndContinue(若要显示所有服务的 CanPauseAndContinue 属性的名称和值表)

.(get-service schedule).stop()(若要调用服务对象的方法(务必包括圆括号)。)

3:对象管道:

.ipconfig | findstr "Address"(将 IpConfig 命令的结果传递到 Findstr 命令)

4:显示有关执行策略的信息:

.get-help about_signing 

5:列出了在 Windows PowerShell 中可用的可执行文件:

.get-command *.exe

6:查看和更改远程计算机的组件:

.get-wmiobject win32_bios -computername server01(令获取有关 Server01 远程计算机上 BIOS 的信息)

7:使用别名:

.Windows PowerShell 中的别名由 Windows PowerShell Alias 提供程序支持,该提供程序是一个 .NET 程序集,通过它可以查看驱动器(与 Windows 中的文件系统驱动器非常类似)中的别名。用于别名的驱动器是 Alias:。

.get-alias | where-object {$_.definition -eq "set-location"}(若要查找 cmdlet 的别名)

.set-alias gh get-help(为 Get-Help cmdlet 创建“gh”别名)

.set-alias np c:\windows\notepad.exe(若要为启动 Notepad 创建别名)

.remove-item alias:ls(,若要删除“ls”别名)

.function bootini {notepad c:\boot.ini}(使用记事本打开 Boot.ini 文件,只能使用创建函数不能用别名)

8:使用windows程序:

.$env:path(若要查看 Path 环境变量中的路径)

.$env:path += ";newdirectory"(若要将目录添加到 Path 环境变量)

. $env:path += ";C:\Program Files\Windows NT\Accessories"(若要将 WordPad.exe 文件的目录添加到 Path 变量)

9:导航&驱动器:

.get-psdrive(要查看 Windows PowerShell 驱动器的列表)

.示主目录的内置变量 $home 和表示 Windows PowerShell 安装目录的内置变量 $pshome。

.get-help about_psprovider(有关 Windows PowerShell 提供程序的信息)

.get-psprovider(若要查看 Windows PowerShell 提供程序的列表)

.get-help -category provider(有关提供程序帮助文件的列表)

.get-help registry(有关特定提供程序的信息)

10:检查执行策略:

.get-help about_signing(如果要运行脚本或加载配置文件,则可以更改系统上的执行策略,有关信息说明)

.get-executionpolicy(若要查找系统上的执行策略)

.set-executionpolicy remotesigned(若要更改系统上的执行策略)

11:powershell配置文件:

.配置文件按加载顺序列出。较特 定的配置文件优先于较不特定的配置文件(如果它们适用)。 
. %windir%\system32\WindowsPowerShell\v1.0\profile.ps1 (此配置文件适用于所有用户和所有外壳程序。 )
.%windir%\system32\WindowsPowerShell\v1.0\ Microsoft.PowerShell_profile.ps1 ( 此配置文件适用于所有用户,但仅适用于 Microsoft.PowerShell 外壳程序。). %UserProfile%\My Documents\WindowsPowerShell\profile.ps1 ( 此配置文件仅适用于当前用户,但影响所有外壳程序.)

.%UserProfile%\\My Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 ( 此配置文件仅适用于当前用户和 Microsoft.PowerShell 外壳程序。 )

.test-path $profile(若要确定是否已创建用户配置文件)

.new-item -path $profile -itemtype file -force (若要创建用户配置文件,若要在记事本中打开配置文件,notepad $profile)

.new-item -path C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1 -itemtype  file -force(若要创建其他配置文件之一,如适用于所有用户和所有外壳程序的配置文件)

.new-item -path C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1 -itemtype  file -force (对于 Windows PowerShell 中的环境变量,不能使用 “%”表示法。若要标识 Windows 环 境变量,请使用以下格式:$env:<变量>,如 $env:windir:)

.如果在记事本中创建配置文件,然后保存它,请务必将文件名括在引号中。例如: "profile.ps1" 如果没有引号,则记事本会将 .txt 文件扩展名追加到文件,而 WindowsPowerShell 将无 法识别它。

.function pro { notepad $profile }(创建一个名为 pro 的函数,该函数用于 在记事本中打开用户配置文件。)

12:查看powershell版本号:

.get-host

.$host.version

.get-host | select-object version

13:常用符号解析

.$(表示变量,本质上命名为对象,而非文本)

.$_(引用管道中的当前对象)

14:WMI

.Windows Management Instrumentation (WMI) 是 Windows 系统管理的核心技术,因为它可以按统一的方式公开各种类型的信息。

.get-wmiobject -list(获取本地计算机中可用的 WMI 类列表)








0 0
原创粉丝点击