• Windows PowerShell Profiles (zz)


    Windows PowerShell Profiles (zz)
    //z 2012-3-2 20:25:52 PM IS2120@CSDN
    Published: May 20, 2009

    Updated: February 29, 2012

    Applies To: Windows PowerShell 2.0, Windows PowerShell 3.0

    [This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

    When you add aliases, functions, and variables, you are actually adding them only to the current Windows PowerShell session. If you exit the session or close Windows PowerShell, the changes are lost.

    To retain these changes, you can create a Windows PowerShell profile and add the aliases, functions, and variables to the profiles. The profile is loaded every time that Windows PowerShell starts.

    To load a profile, your Windows PowerShell execution policy must permit you to load configuration files. If it does not, the attempt to load the profile fails and Windows PowerShell displays an error message.

    Understanding the Profiles//z 2012-3-2 20:25:52 PM IS2120@CSDN

    You can have four different profiles in Windows PowerShell. The profiles are listed in load order. The most specific profiles have precedence over less specific profiles where they apply.

    • %windir%\system32\WindowsPowerShell\v1.0\profile.ps1

      This profile applies to all users and all shells.

    • %windir%\system32\WindowsPowerShell\v1.0\ Microsoft.PowerShell_profile.ps1

      This profile applies to all users, but only to the Microsoft.PowerShell shell.

    • %UserProfile%\My Documents\WindowsPowerShell\profile.ps1

      This profile applies only to the current user, but affects all shells.

    • %UserProfile%\My Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

      This profile applies only to the current user and the Microsoft.PowerShell shell.

    Creating a Profile

    When you create or import variables, aliases, or functions, or add a Windows PowerShell snap-in, these elements are added only to the current session. If you exit the session or close the window, they are gone.

    To save the variables, aliases, functions, and commands that you use routinely, and make them available in every Windows PowerShell session, add them to your Windows PowerShell profile.

    You can also create, share, and distribute profiles to enforce a consistent view of Windows PowerShell in a larger enterprise.

    Windows PowerShell profiles are not created automatically. To create a profile, create a text file with the specified name in the specified location. Typically, you will use the user-specific, shell-specific profile, known as the Windows PowerShelluser profile. The location of this profile is stored in the $profile variable.

    To display the path to the Windows PowerShell profile, type:

    $profile
    

    To determine whether a Windows PowerShell profile has been created on the system, type:

    test-path $profile
    

    If the profile exists, the response is True; otherwise, it isFalse.

    To create a Windows PowerShell profile file, type:

    new-item -path $profile -itemtype file -force
    

    To open the profile in Notepad, type:

    notepad $profile
    

    To create one of the other profiles, such as the profile that applies to all users and all shells, type:

    new-item -path $env:windir\System32\WindowsPowerShell\v1.0\profile.ps1 -itemtype file -force
    

    The profile is effective only when the file is located exactly in the path and with the file name that is stored in the $profile variable. Therefore, if you create a profile in Notepad and then save it, or if you copy a profile to your system, be sure to save the file in the path and with the file name specified in the $profile variable.

    If you create a profile in Notepad, enclose the file name in quotation marks to preserve the PS1 file name extension. For example:

    "Microsoft.PowerShell_profile.ps1"
    

    Without the quotation marks, Notepad appends the .txt file name extension to the file, and Windows PowerShell will not recognize it.

    Use the profile to store the aliases, functions, and variables that you use routinely. One very helpful opens your user profile in your favorite text editor. For example, the following command creates a function calledpro that opens the user profile in Notepad.

    function pro { notepad $profile }
    

    A well-designed profile can make it even easier to use Windows PowerShell and to administer your system.

    //z 2012-3-2 20:25:52 PM IS2120@CSDN


  • 相关阅读:
    fgets()函数读取键盘,去掉换行符或丢弃多余的字符
    c语言gets()函数与它的替代者fgets()函数
    基于京东手机销售数据用回归决策树预测价格
    「我去,这也能行!」令人惊叹的8个深度学习应用
    常见数据结构的 Python 实现(建议收藏)
    60 分钟极速入门 PyTorch
    大牛推荐的15本学习数据分析挖掘的好书
    排名前20的网页爬虫工具
    如何11 周打造全能Python工程师!
    初学者的编程自学指南
  • 原文地址:https://www.cnblogs.com/IS2120/p/6745934.html
Copyright © 2020-2023  润新知