如何个性化PowerShell环境 ?
Windows PowerShell最强的一个特质在于其扩展性powershell 。这个脚本引擎能以许多方式进行自定义,并扩展到使用默认下不可用的功能。一旦你明白基本术语和cmdlet,接下来就个性化PowerShell。
掌控PowerShell环境
使用脚本环境并不是万能之策powershell 。
但是用户可以开始使用下面信息控制Windows PowerShell行为powershell 。
Profile
Profile是在PowerShell启动时运行的脚本powershell 。(我喜欢将它看成PowerShell的autoexec。bat,这可能很守旧,但仍然适用。
有两种类型的profilepowershell ,能存储于两个地点:
1powershell 。System profiles——适用于所有PowerShell会话
2powershell 。Host-specific profiles——只适用于某个主机(i。e。 PS+)
Global
位于系统System32的$PShome里,(C:windowssystem32WindowsPowerShellv1powershell 。
0),这个profile适用于在主机上发起的所有PowerShell会话powershell 。
User
具体用户文档在最后载入的profilepowershell 。位于$Env:UserProfileDocumentsWindowsPowerShellprofile。ps1。
PowerShell也允许你使用主机本身的文档创建自定义主机,不过这已经超出本文的讨论范围,深入到开发领域了powershell 。
扩展PowerShell的功能
尽管多数脚本环境包含扩展过程,但是这些方法通常很复杂,适合更有经验的用户powershell 。不过Windows PowerShell提供了几种级别的扩展性,新手可以很快学会。
Function
Function是最容易添加的,只需要在功能框里包含一个命令,如function {command},让用户创建他们自己的cmdlet,通过profile载入并能按需访问powershell 。
Snap-in
Snap-ins是在版本1powershell 。
0中添加二进制cmdlet到PowerShell会话的主要方法powershell 。通过如思杰、VMware或Exchange这样的应用供应商交付的编译代码,snap-ins由两个cmdlet控制:Get-PSSnapin和Add-PSSnapin。
Module
出现在Powershell 2powershell 。
0版本里,module提供了function(管理中心)和snap-in(开发中心)之间的桥梁powershell 。Module能按需载入,并能包含二进制cmdlet、function和script,通过下面信息进行管理:
1powershell 。Get-Module——获取目前载入的module
2powershell 。
Import-Module——导入powershell 。
爱资源吧版权声明:以上文中内容来自网络,如有侵权请联系删除,谢谢。