PowerShell: Using Snapins, Startup Files, and Preferences
来源:互联网 发布:蒙古骑兵为什么知乎 编辑:程序博客网 时间:2024/05/17 06:45
PowerShell允许配置几个方面来定义如何launch PowerShell和启动后进行那些动作。你也可以添加其它的provider和cmdlet。当PowerShell启动时会加载core snapins,你可以从core snapins加载自定义的snapins. Snapins 是包含provider 和/或 cmdlet 的.net 组件。可以创建profile文件定制每个PowerShell的行为表现,也可按用户定制。也可用alias改变PowerShell的行为表现。
启动
可从命令行用如下命令启动PowerShell
PowerShell 或 PowerShell –PSConsoleFile consoleFileName。如果指定console文件则console文件被加载,如果没有指定或指定的文件不存在则缺省的console 文件被加载。Console文件后缀是psc1. 可以用export-console 命令导出当前的console文件
Snapins
一旦缺省console文件或者指定的console文件被装载,PowerShell snapins也被装载。Snapins是一组PowerShell provider或cmdlet,代表性的,比如共享一些功能。用get-pssnapin可获知被装载的PowerShell console, 在1.0中可见至少以下snapins被装载
· Core-包含用于影响PowerShell引擎的命令,例如get-help, get-command和get-history.也包括FileSystem, Registry, Alias,Environment, Function, 和Variable providers。命名空间是Microsoft.PowerShell.Core
· Host-包含被PowerShell host使用的命令。包括Start-transcript 和stop-transcript. 命名空间是 Microsoft.PowerShell.Host.
· Management-包含管理PowerShell安全的命令。例如get-authenticode Signature 和get-acl. 命名空间是 Microsoft.PowerShell.Security。
· Utility-包含操纵数据的功用命令,例如get-member, write-host,和 format-list. 命名空间是 Microsoft.PowerShell.Utility.
可用get-command和where-object命令获知有哪些命令属于特定的snapin. 例如:get-command –commandtype cmdlet|where-object {$_.pssnapin –match “core”}
如果想获知那个snapin包含哪些provider,可用如下命令 get-psprovider|format name,pssnapin.
Profile
Profile 文件时PowerShell启动时自动运行的PS脚本。它可以包含添加alias,定义function和用其它方法配置console。Profile文件可以放在下面的目录中,如果有,按如下所列先后顺序运行。如有冲突更精准的优先。
· %windir%/system32/WindowsPowerShell/v1.0/profile.ps1 — 对所有用户的所有PS console设置这个文件
· ❑ %windir%/system32/WindowsPowerShell/v1.0/ Microsoft.PowerShell_profile.ps1 —对所有用户但仅装载缺省PS console的用户的一个设置文件
· ❑ %UserProfile%/My Documents/WindowsPowerShell/profile.ps1 — 设置一个用户特定的profile给所有的被特定用户load的PS console
· ❑ %UserProfile%/My Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1 —设置一个用户特定的profile但仅装载缺省PS console的用户
可用启动带-noprofile 跳过profile运行 例如:PowerShell –noprofile
可用命令test-path $profile检测user profile是否存在,用$profile显示user profile的位置,用notepad $profile打开user profile。
%windir%/system32/WindowsPowerShell/v1.0/sample下有一个示例profile文件。
Prompt,
PowerShell 允许用户用Prompt 函数自定义命令行提示。 可将Prompt函数定义放在profile文件中。Prompt函数返回一个字符串,此字符串显示在每一个命令行前。
Preference Variables
Preference Variables 的值表示在一个特定的情况下PowerShell采取怎样的行动。,比如$ErrorActionPreference 的值指定当错误出现时PowerShell采取什么样的行动。 可用get-variable *preference*, get-variable Maximum*, get-variable report*, 命令获知系统中的Preference Variables.
- PowerShell: Using Snapins, Startup Files, and Preferences
- Professional Windows PowerShell Programming: Snapins, Cmdlets, Hosts and Providers
- 2.Using Windows PowerShell Cmdlets and 3.Leveraging PowerShell Providers
- Checking Signing and Versioning using Powershell
- 5.Using PowerShell Scripts and 5.Using WMI
- Uploading Files Using CGI and Perl
- Using Unicode in INI files and WritePrivateProfileStringW
- Using SSIS to zip files and email the zipped files
- Using Shared Preferences
- OpenCV--File Input and Output using XML and YAML files
- System startup files
- Asp.Net Globalization and Localization using Local Resource files and Global Resource files
- Upload Files Using ASP.NET Impersonation and UNC Share
- using LINQ to detect and remove duplicate files
- Using tar and ssh to efficiently copy files preserving permissions
- Parsing XML Files with PowerShell
- Calling Executable Files in PowerShell
- Applications using Launch Screen Files and targetting iOS 7.1 and earlier
- 使用 Visual C++ 2008 功能包加强 Windows 应用程序
- 国内十大仪表行业网站提名
- Web设计需要遵循一些准则
- 有关C#开发抓取、分析网络数据包的代码段
- 程序人生----JavaScript引发的思考
- PowerShell: Using Snapins, Startup Files, and Preferences
- 普通视图和物化视图区别
- linux2.6.29 CFS调度详细分析(二)
- oracle中的数据类型
- HP ProLiant DL380 G5 前面板指示灯说明
- 新生项目必备工具--Linux项目生成器
- Oracle数据类型简介
- SQL Server的安全模型
- Oracle PLSQL的集合类型