IT tutorials
 
Windows
 

Windows Server 2008 : Creating and Running a PowerShell Script - Creating and Modifying the Global PowerShell Profile

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
11/29/2013 7:59:34 PM

The steps in the following table show how to create and modify the global profile.

Tip

You can use most of these steps to modify the local profile too.


StepsComments
1. Launch PowerShell with administrative permissions.Some of the steps will not work correctly if PowerShell is not started using Run As Administrator.
2. Create the global profile:
PS C:\> notepad c:\windows\system32\
windowspowershell\v1.0\profile.ps1

If the file doesn’t exist, Notepad prompts you to create the file. Click Yes.
3. Change the PowerShell starting folder:
set-location c:\scripts

Because cd is an alias, you can also enter cd c:\scripts.

Note

The path must exist for this to work. In other words, if c:\scripts isn’t a valid folder, PowerShell gives an error when it launches.

4. Add an alias to the profile in Notepad:
set-alias gh get-help

Creates an alias called gh that executes get-help. After this alias is created, you can use the following line to get help on the set-alias command: PS C:\> gh get-alias
5. Add a function to the profile:
function get-topprocesses
{
get-process | sort-object
-property ws -descending |
select-object -first 10 |
out-gridview
}

After this is added to the profile, you can enter the following line at the PowerShell prompt: PS C:\> get-topprocesses to run the function.

Tip

You can name the function anything you like. For example, you can name it something shorter such as gtp, which is short for get top processes. Additionally, you can have multiple lines of code in the function.

6. Press Ctrl+S to save the file.Saves the profile.
7. Close and restart PowerShell.You see the default path is changed to c:\scripts.
8. Run the alias from the profile:
PS C:\> gh

Runs the get-help command.
9. Run the function from the profile:
PS C:\> get-topprocesses

Runs the get-topprocesses function command. Your display looks similar to Figure 1.
10. Run other scripts from the profile:
. path-script.ps1
. c:\scripts\setenvironment.ps1

You can run other scripts from within the PowerShell profile by typing a dot, a space, and the path to the script.

Tip

If there is not a space after the dot, the command fails and you see an error message when PowerShell is launched.


Figure 1. Top running processes shown in grid view

Note

The profile is loaded only when Windows PowerShell is first launched. In other words, if you modify the profile, the modifications won’t take effect until you close and restart PowerShell.

 
Others
 
- Windows Server 2008 : Creating and Running a PowerShell Script - Creating a PowerShell Profile
- Windows Server 2008 : Creating and Running a PowerShell Script - Setting the Security Context
- Windows 8 : Cloud Connections - Office 2013
- Windows 8 : Cloud Connections - SkyDrive (part 3) - To access SkyDrive from a browser
- Windows 8 : Cloud Connections - SkyDrive (part 2) - To open SkyDrive inside Windows Explorer
- Windows 8 : Cloud Connections - SkyDrive (part 1) - To add a file to the tile-based SkyDrive app
- Windows 8 : Cloud Connections - Windows Essentials (part 2) - To install Windows Essentials
- Windows 8 : Cloud Connections - Windows Essentials (part 1)
- Windows 8 : Cloud Connections - Windows Live
- Windows 8 : Cloud Connections - Microsoft Account (part 2) - To enable a roaming profile
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us