Exchange the PowerShell configuration file

Source: Internet
Author: User
Tags aliases

You can use PowerShell config file to personalize your Shell environment, when you start Exchange Management Shell session, automatically import functions, modules, aliases and variables to Exchange Management Shell the session. In this section, we will learn how to create a configuration file.

The configuration file is not created by default, but you can check to see if a configuration file was created with the following command syntax:

Test-path $profile

650) this.width=650; "title=" 01.png "style=" Float:none; "src=" http://s3.51cto.com/wyfs02/M02/59/46/ Wkiom1tojxwbkwptaaapt6dhaue398.jpg "alt=" Wkiom1tojxwbkwptaaapt6dhaue398.jpg "/>

If the value returned is $True, indicates that the current user has created a configuration file, and if not, it is displayed as $False . We can open a configuration file that can exist through notepadexe in a Shell session:

Notepad $profile

Of course as I show here for $False , which indicates that a configuration file has not been created yet, we can create a profile for the current user with the following command:

New-item-type File–path $profile –force

How configuration Files work

a PowerShell configuration file, is just a . PS1 the script file, just it every time you start Shell when you start together. You can think of a configuration file as a login running PowerShell script or Exchange Management Shell. In the configuration file, you can add custom aliases, custom variables, load other modules, and add custom functions. In front, we used the new-item command to create a new configuration script for the current user, and the created configuration file will be stored in the $env: userprofile\document\ Windowspowershell\directory

In

because PowerShell loading Our configuration file is actually running some simple . PS1 Script , so we have to configure the policy so that our system can execute these scripts . If you do not configure these execution policies , You will receive an error message when loading the script .

There are four types of configuration files that can be used PowerShell:

$Profile. Allusersallhosts: This configuration file is applied to all users and all Shells in , This configuration file is located in the following path : $env: Windir\system32\windowspowershell\v1.0\profile.ps1

$Profile. Alluserscurrenthost: This configuration file applies to all users and Powershell.exe Host , The configuration file is located in the following path : $env: Windir\system32\windowspowershell\v1.0\microsoft.powershell_profile.ps1

$Profile. Currentuserallhosts: This configuration file applies to the current user and all Shells, is located in the following path : $env: Userprofile\documents\windowspowershell\profile.ps1

$Profile. Currentusercurrenthost: This configuration applies only to the current user and the current Powershell.exe Host , is located in the following path : $env: Userprofile\documents\windowspowershell\microsoft.powershell_profile.ps1

Use$Profilevariable to create a configuration file,By default it isCurrentusercurrenthostlocation,This is also one of the most used configuration file types. Powershellcan be run by a third-party application load,so"All Hosts"configuration types can be applied to thisPowerShellExample. " Current Host "configuration types can be used toPowershell.exeand theExchange Management Shell.

In addition to customizing aliases and functions in the configuration file , you may also want to load other modules . For example , you may want to load Active Directory Module , This makes it easier for us to start PowerShell automatically loaded and can be used when .

when you make a change to the configuration file , we need to save and close the configuration file . to have the configuration file take effect , we can reboot . Shell, or Dot-source Script Reload configuration file , The command is as follows :

. $profile

We can create multiple . PS1 Script , can include aliases , Functions and Variables , then use Dot-source These scripts into the configuration file , after each boot PowerShell is automatically loaded in .

You can refer to the Help system using the following command : Get-help about_profiles

technology all profile types and paths to related scripts can be a bit difficult . actually , Here's the trick . , can use $profile variable to see all the profile types and file Paths , You can use the following command :

$profile. psextended | Format-list

650) this.width=650; "title=" 02.png "style=" height:88px;width:720px; "border=" 0 "hspace=" 0 "src=" http://s3.51cto.com /wyfs02/m00/59/43/wkiol1tojluqci00aahjpbplhfk239.jpg "width=" 720 "height=" "alt=" Wkiol1tojluqci00aahjpbplhfk239.jpg "/>

This article from "Robin's Home" blog, declined reprint!

Exchange the PowerShell profile

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.