Do you want to get more out of your PowerShell? Then make sure you configure your PowerShell Profile to boost your PowerShell console.
The PowerShell Profile is a script that runs when you open PowerShell. It allows you to load PowerShell scripts or modules automatically, create aliases for cmdlets that you use often, and change the look of your console.
In this article, we are going to take a look at the different PowerShell Profile locations, explain how to create a profile, and give you some useful examples.
PowerShell Profile Location
What most people don’t know is that there are different profiles. You can create a profile for the PowerShell Console/Terminal and a separate one for PowerShell ISE. But it’s also possible to create one profile that is used on all locations.
To find your PowerShell Profile location we are going to use PowerShell.
- Open PowerShell
- Type $profile
The $profile variable returns the profile for the current user in the current program (host). But as mentioned, there are different profiles. If you also work a lot in PowerShell ISE, then makes more sense to use the Current User – All Hosts profile.
You can use the same method to create the profile of all hosts or all users using the command in the table above.
To use the profile you will need to make sure you have set the Execution Policy to Remote Signed. Otherwise, you won’t be able to run the script when PowerShell opens. Make sure you run PowerShell with elevated permissions (admin mode) to change the execution policy:
Edit the PowerShell Profile
The profile is now created, allowing you to open and edit the PowerShell Profile. Again we are using the PowerShell command to open the profile file:
This will open the profile in PowerShell ISE, showing a completely blank profile file. Keep in mind that the more you add to your profile, the longer it may take before PowerShell is started.
PowerShell Profile Examples
The profile is a PowerShell script, so we can right pretty much any PowerShell function in it. But basically, you want to do a couple of things in your profile:
- Style your PowerShell console
- Set default location
- Load different paths (folders) with scripts
- Set default variables
- Import modules
- Create aliases
Style your PowerShell Console
You can style your PowerShell console, settings the font and background color, and windows title for example. Personally, I use Windows Terminal and use a customized theme for it. You can read more about Windows Terminal in this article.
Set Default Location
By default, PowerShell starts in your home folder $home . But when I am working with PowerShell, most of the time I want to have easy access to my scripts folder. So we can set the default location to start PowerShell in:
Load scripts from different locations
To have quick access to your scripts, you can load the folders that contain the scripts into your environment path $env:path . This allows you to have access to all your script without the need to change directories every time:
Set default variables
Another useful tip is to set default variables in your profile. For example, I often need to connect to Office 365. By settings the SharePoint Admin URL, or my UserPrincipalName as a variable in the profile, I can quickly connect to the different endpoints.
This works the best in combination with the connection scripts that you can find here on my GitHub.
Import modules or Scripts
Most of my scripts are writing as a function. But to really use them as a function you will need to create a PowerShell Module from it. And those module files need to be placed in your modules folder: $HOME\Documents\PowerShell\Modules .
My modules folder isn’t connected to my GitHub repository, so changes made in the scripts need to be copied to the module folder, which I always forget.
An easier method, in my opinion, is to use an alias for your scripts. This way you can call your scripts as a function, without the need of making modules from them:
Create Aliases for commands
You can also create aliases for commands that you often use, like:
After you have made all the changes, save your profile file and restart your PowerShell console.
A good configured PowerShell Profile can really save you time when working with PowerShell. It gives you direct access to often-used scripts, variables, and functions.
If you have suggestions or tips for the profile, then please share them below. Also if you have questions, just drop a comment below.
I want to create an alias of a cmdlet that doesn’t expire after I close the current session of Powershell, let’s say I have this alias :
This perfectly creates the Goto alias, but I want to use it even after I close the current session, how can I achieve that.
The PowerShell Help system suggests that I can export the aliases I create, and import them next time I open a new session, actually that’s not really what I’m looking, for, is there a direct clear way to keep having a alias after I create it through different sessions
9 Answers 9
UPDATED – January 2021
It’s possible to store in a profile.ps1 file any PowerShell code to be executed each time PowerShell starts. There are at least 6 different paths where to store the code depending on which user has to execute it. We will consider only 2 of them: the “all users” and the “only your user” paths (follow the previous link for further options).
To answer your question, you only have to create a profile.ps1 file containing the code you want to be executed, that is:
and save it in the proper path:
- “$Home\Documents” (usually C:\Users\
\Documents ): only your user will execute the code. This is the recommended location You can quickly find your profile location by running echo $profile in PowerShell
- $PsHome ( C:\Windows\System32\WindowsPowerShell\v1.0 ): every user will execute this code
IMPORTANT: remember you need to restart your PowerShell instances to apply the changes.
If both paths contain a profile.ps1 file, the all-users one is executed first, then the user-specific one. This means the user-specific commands will overwrite variables in case of duplicates or conflicts.
Always put the code in the user-specific profile if there is no need to extend its execution to every user. This is safer because you don’t pollute other users’ space (usually, you don’t want to do that).
Another advantage is that you don’t need administrator rights to add the file to your user-space (you do for anything in C:\Windows\System32).
If you really need to execute the profile code for every user, mind that the $PsHome path is different for 32bit and 64bit instances of PowerShell. You should consider both environments if you want to always execute the profile code.
APPLIES TO: 2013 2016 2019 Subscription Edition SharePoint in Microsoft 365
The User Profile service is a shared service in SharePoint Server that provides a central location for configuring and managing user profiles.
This article contains required information and procedures for configuring a User Profile service application.
Before you begin
Before you begin this operation, review the following information about prerequisites:
A managed path exists.
An application pool for My Sites exists.
A site collection that uses the My Site Host template exists.
Create a User Profile service application
You can create a User Profile service application by using either the SharePoint Central Administration website or Microsoft PowerShell. Be sure you’re a member of the Farm Administrators group when you perform these procedures.
To create a User Profile Service application by using Central Administration
In Central Administration, in the Application Management section, click Manage service applications.
In the Create group of the ribbon, click New, and then click User Profile Service Application in the list of service applications to create.
In the Create New User Profile Service Application dialog, in the Name section, type a unique name for the User Profile service application.
In the Application Pool section, select Use existing application pool to choose an existing application pool from the list or select Create a new application pool to create a new application pool.
In the Application Pool section, for the Select a security account for this application pool option, select Predefined to choose an existing predefined security account from the list or select Configurable to choose an existing managed account.
In the Profile Database section, in the Database Server box, type the name of the database server where you want to create the profile database. In the Database Name box, type the name that you want to use for the profile database.
In the Profile Database section, for the Database authentication option, select Windows Authentication (recommended) to use Integrated Windows authentication to connect to the profile database or select SQL authentication to enter the credentials that will be used to connect to the profile database.
In the Failover Server section, in the Failover Database Server box, type the name of the database server to be used together with SQL Server database mirroring.
In the Synchronization Database section, in the Database Server box, type the name of the database server where you want to create the synchronization database. In the Database Name box, type the name of the synchronization database.
Only ASCII characters are allowed for the synchronization database name.
In the Failover Server section under Synchronization Database, in the Failover Database Server box, type the name of the database server to be used together with SQL Server database mirroring.
In the Social Tagging Database section, in the Database Server box, type the name of the database server where the social tagging database will be located. In the Database Name box, type the name of the database where social tags will be stored.
In the Social Tagging Database section, for the Database authentication option, select Windows Authentication (recommended) to use Integrated Windows authentication to connect to the social tagging database or select SQL authentication to type the credentials that will be used to connect to the social tagging database.
In the Failover Server section, in the Failover Database Server box, type the name of the database server that you want to use with SQL Server database mirroring.
In the My Site Host URL section, type the URL of the site collection where the My Site Host is provisioned.
In the My Site Managed Path section, type the managed path where you want to create individual My Sites.
Self-service site creation can be enabled for the web application that hosts My Sites. Users must have Create Personal Site permissions to create their own My Site. By default, this permission is enabled in SharePoint Server for all authenticated users. Ensure that you want the default setting to apply to the organization. Or, you can use one or more security groups to grant the Create Personal Site permission to a subset of users in an organization.
In the Site Naming Formatsection, select one of the following formats for naming new personal sites:
User name (do not resolve conflicts)
User name (resolve conflicts by using domain_user name)
Domain and user name (will not have conflicts)
In the Default Proxy Group section, select whether you want the proxy of this User Profile service application to be a part of the default proxy group on this farm.
In the Yammer Integration section, select whether you want to use Yammer for social collaboration.
In this PowerShell tutorial, we will discuss how to create a folder in PowerShell? Also, we will check how to create a folder if not exists in PowerShell. Or we will check how to create a directory if not exists in PowerShell.
We will see how to use the below PowerShell cmdlets.
- Test-Path: PowerShell Test-Path cmdlet, we can use to check if a folder exists or not.
- New-Item: We will use the PowerShell New-Item cmdlet to create a folder in PowerShell.
You can write the below PowerShell script by using visual studio code or PowerShell ISE.
I have also created a video tutorial on PowerShell create directory if not exists.
PowerShell create folder
Now, let us first check how to create a folder in PowerShell. We can use the New-Item PowerShell cmdlet to create a folder.
The below PowerShell command will create a folder with a folder name as of today’s date.
You can see it will create a folder with today’s date like below:
PowerShell create folder if not exists
Now we will check how to create a folder if not exists in PowerShell. The PowerShell command will check if a folder already exists or not. If the folder does not exist then it will create a folder.
PowerShell Provides Test-Path command to check if a folder already exists or not.
You can see the below fig since the folder already exists, it will just display the message as Folder already exists.
If the folder or directory does not exists, the PowerShell cmd will create directory if not exists.
Read some PowerShell tutorials:
I hope this article will be helpful to create a folder using PowerShell or PowerShell create directory if not exists. Also, we discussed
In this tutorial, we will discuss, what is a PowerShell ArrayList how to create and use ArrayList.
Also, we will see how to sort an ArrayList, remove items from an ArrayList, how to sort an ArrayList, and how to create an ArrayList from an array.
What is PowerShell Arraylist
We can use an ArrayList to store a list of items in PowerShell.
Unlike array, arraylist’s length is not fixed, it can changed.
One difference between array and ArrayList is, An array is strongly types, that means array can store only specific type elements. On the other hand, ArrayList can store all the datatype values.
Create ArrayList in PowerShell
Now, we will see how to create an arraylist in PowerShell.
ArrayList is part of the System.Collections namespace within .NET. And we can create a new object of type System.Collections.ArrayList to create an ArrayList.
Below are the two ways to create an arraylist.
This way, we can create arraylist of objects type.
You can see by calling the GetType() method.
How to create an empty ArrayList
We can also create an empty arraylist like below:
This will create an empty arraylist.
PowerShell ArrayList add
Now, we will see how to add item to arraylist.
We can use the Add() method to add an item to the arraylist.
You can retrieve the arraylist elements by using the arraylist name like below:
How to Get ArrayList Item count
We can count the items from the ArrayList by using the Count property.
You can see the output like below:
Sort ArrayList Items
We can easily sort arraylist using sort-object.
You can see now the Arraylist is displaying in sorted order like below:
This is how we can sort a ArrayList.
PowerShell arraylist foreach
Now, we will see how to iterate ArrayList by using foreach.
We can use ArrayList foreach like below:
It will looks like below:
How to create an ArrayList from an Array in PowerShell?
Now, we will see how to create an arraylist from an array.
Below are two ways we can create an arraylist from an array.
You can see the output like below:
Below is also another way, we can create an arraylist from an array by using the below script:
remove item from ArrayList PowerShell
Now, we will see how to remove item from arraylist.
We can use the RemoveAt() method to remove an item from the ArrayList.
Remove multiple item from arraylist
Now, we will see how to remove multiple items from PowerShell ArrayList by using the RemoveRange() method.
RemoveRange takes two parameter, first parameter is Index and second parameter is Count.
The above code remove 2 items starting from index 1. So it will remove 4,6 from the arraylist.
PowerShell uses aliases generically for alternatives to many commands. Even in its early version, 1.0, PowerShell came with 100 aliases by default. As an example, you can give PowerShell a UNIX flavor and use commands like cp, mv, man, and ls. PowerShell will parse and translate them to native PowerShell versions. The UNIX “man” command, for example, is an alias for PowerShell’s command get-help. If you’re not happy with the built-in aliases, you can add your own to replace them. Let’s have a look at the built-in aliases first.
Built-in aliases ^
The number of built-in PowerShell aliases has steadily increased from the original 100 in version 1.0 to around 450 in PowerShell 4. You can list all aliases with the command get-alias. Notice that get-alias even has its own alias, “gal.”
Here’s a sample listing:
Some commands have multiple built-in aliases. Get-childitem, for example, has several pseudonyms: dir, ls, and gci. Be warned, however, that alias behavior does not extend to parameters of the original native commands.
For example, trying to display a wide directory listing with dir /w will result in the following error:
You have to use PowerShell to format the display with dir |fw instead to get a wide display of files and folders.
PowerShell alias cmdlets ^
Aliases can be managed with five PowerShell cmdlets: Export-alias, Import-alias, Get-alias, Set-alias, and New-alias.
Export-alias and Import-alias simply save or load aliases to or from a text file, respectively, allowing you to back up and restore aliases. Note that PowerShell 3.0 and later does not overwrite existing aliases, by default, when you import from a file. To overwrite an existing alias, you need to use the -Force argument.
Get-alias, as already mentioned, displays existing aliases along with their meaning. You can use wildcards or exclude items to filter the display.
Finally, New-alias and Set-Alias are both very similar. The difference is subtle. New-alias will error if you try to create an alias that already exists, whereas Set-alias will happily create a brand new alias or overwrite an existing one.
Create an alias ^
You can create an alias for any cmdlet, script, function within a script, or even an external command. The choice is limited only by your creativity. To create your own alias, you need to use either the New-Alias or Set-Alias command. The simplest syntax is:
So, if you want to open Notepad by typing “ed,” you use:
That’s easy but not that useful. The secret to benefiting from aliases is to use them for complex PowerShell scripts or external commands that have horrible paths too hard to type or remember. For example, you would set the alias “cm” for the command that launches System Center’s Configuration Manager agent as follows:
A few aliasing issues ^
Aliasing has a few notable caveats to be aware of. One issue is that many of the built-in aliases are read-only.
What that means is those aliases are protected from accidental use—that is, you cannot delete them easily. You need to use –Force to delete; however, doing so is not recommended.
The second big issue is that aliases only exist for the lifetime of the shell window. This is very similar to the DOS Set command. If you create an environment variable in a DOS window and then close that window, you destroy the variable. PowerShell aliases behave in the same way. The solution is to add the alias to your PowerShell profile.
Before you add aliases to your profile, however, be selective. Choose only the commands that you use most often to be aliases. If you have too many, you will struggle to remember them all and thus defeat the whole purpose of an alias in the first place—its usability.
There is, however, one core catch to aliasing in PowerShell that even DOS betters. It’s only practical to alias single commands or cmdlets. That means you cannot alias long, multi-command strings or even add parameters. Doing so will cause the command to fail.
Creating complex aliases ^
The solution, ironically, is to use functions. So, to edit your profile with “edss,” you need to define a function first and then alias the function.
Now that your appetite is whetted, here are some creative alias/function pairs:
In order of appearance, these aliases display eventlog errors per day, last boot time of a machine, PowerShell version, and, finally, two deployment values: machine serial number and machine model from the BIOS, respectively.
You can, of course, split your aliases off into a separate file altogether if you want, using Export-Alias, and simply have “import-alias D:\youraliases.txt” in your profile. Note that the export will overwrite the file. To prevent that, you can use the wonderfully named –noclobber option:
Subscribe to 4sysops newsletter!
Don’t get carried away as you create aliases. It’s a bad idea to create aliases in scripts, and certainly never do so in production scripts. Alias commands, but don’t do so in scripts.
I was recently asked how to create a PowerShell command alias that accepts parameters.
The asker wanted to know how to run a command such as:
ffmpeg -i “take 1.avi” -vcodec h264 -acodec mp2 output.mp4
but have the input and output values as parameters to the alias.
You can’t do this with PowerShell…
In PowerShell, aliases are meant to be for hard-coded commands and aren’t able to be parameterized. Bummer.
…but you can accomplish the same thing by storing a function in your profile!
We’ll be able to get the desired outcome in just a few steps, by creating our own function and then loading that whenever PowerShell loads, via the Profile.ps1 file.
Step 1: Create a PowerShell function
We’ll create a function to do what we need to do, with the appropriate parameters.
For example, let’s say we call the function Encode-Video :
Step 2: Create a Profile.ps1 file
Powershell handily uses a variable for your profile file, $profile .
So, if you were to run:
You’ll either open the existing Profile.ps1 file, or be prompted to create a new one.
Step 3: Paste your function and save
Paste the function you created in step 1 into the Profile.ps1 file and save it.
And that’s it!
Now, whenever PowerShell loads, the definition for that function will also be loaded from your profile file, and you can use it as much as you’d like.
PowerShell alias can be created permanently by 2 methods below.
a) Import / Export Alias
To export all the aliases, you need to use Export-Alias cmdlet. When you use this command it will ask you the path for the file to import.
To export the newly created alias, you need to give alias name and the name for the export, so later you can import it with the same name.
In the below example, we have created alias name Edit for the Wordpad and we will export all the aliases with the name Alias1, so the newly created alias will also be stored and when you want to import your newly created aliases you need to write Import-Alias command.
Now, we will export all the aliases.
You can check the exported aliases and manipulate them as well with the proper format.
Next, whenever you run the new PowerShell console, you won’t find the new aliases so you need to import the exported aliases.
But when you run the above command, you will get an error that inbuilt aliases are already existed but we have remediation for it, we can use –Force parameter to forcefully overwrite those aliases.
Now you see the newly created aliases as well in the PowerShell console.
b) Startup Profile Script.
Another option but easier than Import/Export option is to create a profile script so every time PowerShell opens it loads a startup profile and all the commands and scripts are loaded which resides inside that profile folder.
Here, we will create a profile file Profile.ps1 using below command on the $PROFILE path of your PowerShell.
The above command will prompt to the user to create Profile1.ps1 on the $Profile path if it doesn’t exist and if it is already created then it will open the file to allow the user to manipulate.
Once a file is opened, edit the file to set your aliases. Here we will set two aliases in the file. Type the following two commands in notepad and save it.
Launch the PowerShell console again and when you type edit, it will open Notepad and when you type edit1, it will open Wordpad.
With this simple method, you can add as many aliases in the profile script and launch them through the PowerShell console.
Founder and CEO
Lowell is the founder and CEO of How-To Geek. He’s been running the show since creating the site back in 2006. Over the last decade, Lowell has personally written more than 1000 articles which have been viewed by over 250 million people. Prior to starting How-To Geek, Lowell spent 15 years working in IT doing consulting, cybersecurity, database management, and programming work. Read more.
For frequent PowerShell users, the standard settings might not be ideal. We can change the settings of our PowerShell window to how we like it by modifying the profile.
The first thing we need to check is whether or not a profile already exists. We can do this by opening a PowerShell window and typing:
Since our query returned “False” we are going to have to create a new profile. We’ll type the following in our PowerShell prompt:
You should get the following pop-up, and just click yes to proceed.
The profile script will now be created. It will be in the location following the “Directory:” output. When we browse to that location, the profile script will be there waiting for us to modify. Open the file named “Microsoft.Powershell_profile.ps1”
The profile will be empty, so we can fill it with any commands that we want to run. You can set the starting prompt location to the root directory by adding:
We can change the title of the PowerShell window to SysadminGeek by adding:
We can also change the window size and scrollback with the following:
$Shell = $Host.UI.RawUI
$size = $Shell.WindowSize
$Shell.WindowSize = $size
$size = $Shell.BufferSize
$Shell.BufferSize = $size
The background and text coloring can also be changed with these entries:
You can put any scripts or aliases that you commonly use as well. We’ve included our alias for Notepad.exe
new-item alias:np -value C:WindowsSystem32notepad.exe
The final entry is included to clear everything from the PowerShell window, giving you a clean workspace:
All together, it looks like this:
After you’ve saved your profile, the next time you open PowerShell you will see all the changes made to your profile.
It’s pretty easy to customize your profile, and the more you use PowerShell, the more you will find yourself returning to add in new aliases and scripts that you need to run at startup.
- › How to Use a Batch File to Make PowerShell Scripts Easier to Run
- › How to Configure Windows to Work with PowerShell Scripts More Easily
- › 11 Things to Check When Buying a Used iPhone
- › Emulate Classic Consoles With Portable Retro Handhelds
- › Buying a Used GPU? Here’s What to Look Out For
- › Stop Closing Apps on Your iPhone
- › 10 Things to Do With Your New iPhone
- › What Is Spam, and Why Do We Call It That?
Lowell is the founder and CEO of How-To Geek. He’s been running the show since creating the site back in 2006. Over the last decade, Lowell has personally written more than 1000 articles which have been viewed by over 250 million people. Prior to starting How-To Geek, Lowell spent 15 years working in IT doing consulting, cybersecurity, database management, and programming work.
Read Full Bio »
Q: I would like to personalize the way that PowerShell works. I have heard that I can use a thing called a profile to do this, but when I try to find information about profiles, I come up blank. There is no New-Profile cmdlet, so I do not see how to create such a thing. Can you help me, please?
A: Profiles are a powerful part of PowerShell and allow you to customize PowerShell for your environment. They are easy to create and support a range of deployment scenarios.
What is a Profile?
Before explaining the profile, let’s first examine the PowerShell host. A PowerShell host is a program that hosts PowerShell to allow you to use it. Common PowerShell hosts include the Windows PowerShell console, the Windows PowerShell ISE, the PowerShell 7 console, and VS Code. Each host supports the use of profile files.
A profile is a PowerShell script file that a PowerShell host loads and executes automatically every time you start that PowerShell host. The script is, in effect, dot-sourced, so any variables, functions, and the like that you define in a profile script remain available in the PowerShell session, which is incredibly handy. I use profiles to create PowerShell drives, various useful variables, and a few useful (for me!) functions.
Each PowerShell host has 4 separate profile files as follows:
- This host, this user
- This host, all users
- All hosts, this user
- All hosts, all users
Why so many, you might ask. Because having these four profiles allows you numerous deployment opportunities. You could, for example, have one profile that defines corporate aliases or standard PS drives for every PowerShell host and user on a machine. You could have ‘this host’ profiles that define host-specific customizations that could differ depending on the PowerShell host. For example, in my profile file for VS code, I use Set-PSReadLineOption to set token colours depending on which color theme I am using. Like so many things in PowerShell, the PowerShell team engineered profiles for every scenario you might come across in deploying PowerShell and PowerShell hosts.
In practice, the “this host, this user” profile is the one you most commonly use, but having all four allows considerable deployment flexibility. You have options!
Where do I find them?
Another frequently asked question is: where are these files and how are they named? It turns out, like many things PowerShell, you can find the answer to the question inside PowerShell itself. In this case, inside a PowerShell automatic variable, $PROFILE .
Automatic variables in PowerShell, are variables created by PowerShell itself and are available for use. These variables are created by PowerShell when you start the host. For more details on automatic variables see the automatic variable help text.
The $PROFILE variable
The $PROFILE variable is an automatic variable that PowerShell creates within each session during startup. This variable has both a ToString() method and four additional note properties that tell you where this host finds its profile files.
To determine the location and fill script name for the four PowerShell scripts, you can do something like this:
This example is from a Windows 10 client running PowerShell 7 inside VS Code. In the example, you can see that the $PROFILE variable contains four note properties that contain the location of each profile Also, you can see that the $PROFILE variable’s value is the name of the CurrentUserCurrentHost profile. For simplicity you can run Notepad $Profile to bring up the profile file inside Notepad (or use VS Code!)
What can you do in a profile script?
You can pretty much do anything you want in profile file to create the environment that works best for you. I find the profile useful for creating variables and short aliases, PS Drives, and more as you can see below. As an example of what you can do in a profile, and to get you started, I have published two sample profile files to GitHub:
- A profile for the PowerShell 7 console
- A profile for VSCode
These samples do a lot of useful things, including:
- Over-ride some default parameter values
- Update the Format enumeration limit
- Set the ‘home’ directory to a non-standard location
- Create personal aliases
- Create a PowerShell credential object
These are all things that make the environment customized to your liking. I use some personal aliases as alternatives to standard aliases – if only to save typing. Creating personal variables or updating automatic variables can be useful.
While creating a credential object can be useful, it is arguable whether it is a good thing. In this case, the credential is for a set of VMs I used in my most recent PowerShell book to illustrate using PowerShell in an Enterprise. As they are all local VMs and are only for testing, creating a much used credential object is useful.
It is easy to get carried away with profile files. At one point in the PowerShell 3.0 days, my profile file was over 700 lines long. I’d just chucked all these cool things I’d found on the Internet (and never used them again) As a result, starting PowerShell or the ISE took some time. It is so easy to see some cool bits of code and then add it to your profile. I suggest you look carefully at each profile on a regular basis and trim it when possible.
Profile are PowerShell scripts you can use to customize your PowerShell environment. There are 4 profile files for each host as you can see by examining the $Profile automatic variable.
Tip of the Hat
I based this article on one written for the earlier Scripting Guys blog How Can I Use Profiles With Windows PowerShell. It was written by Ed Wilson.
Summary: Use Windows PowerShell to create and manage registry keys.
Microsoft Scripting Guy, Ed Wilson, is here. Today I am happy to provide you with an excerpt from my book, Windows PowerShell 3.0 Step by Step, published by Microsoft Press.
Note The registry contains information that is vital to the operation and configuration of your computer. Serious problems could arise if you edit the registry incorrectly. Therefore, it is important to back up your system prior to attempting to make any changes. For information about backing up your registry, see article 322756 in the Microsoft Knowledge Base. For general information about working with the registry, see article 310516.
Creating a new registry key by using Windows PowerShell is the same as creating a new file or a new folder. All three processes use the New-Item cmdlet. In addition, you might use the Test-Path cmdlet to determine if the registry key already exists. You may also want to change your working location to one of the registry drives. If you do this, you might use the Push-Location, Set-Location, and Pop-Location cmdlets. This is, of course, the long way of doing things…
Just the steps
- Store the current working location by using the Push-Location cmdlet.
- Change the current working location to the appropriate registry drive by using the Set-Location cmdlet.
- Use the Test-Path cmdlet to determine if the registry key already exists.
- Use the New-Item cmdlet to create the new registry key.
- Use the Pop-Location cmdlet to return to the starting working location.
The following example creates a new registry key named hsg off the HKEY_CURRENT_USERS software registry hive. It illustrates each of the five steps previously detailed.
New-Item -Path .\Software -Name test
The commands and the associated output from the commands are shown in the following image:
The short way to create a new registry key
It is not always necessary to change the working location to a registry drive when you create a new registry key. In fact, it is not even necessary to use the Test-Path cmdlet to determine if the registry key exists. If the registry key already exists, an error generates. If you want to overwrite the registry key, use the Force parameter.
Note How you choose to deal with an already existing registry key is one of those design decisions that confront IT pros who venture very far into the world of scripting. Software developers are very familiar with these types of decisions, and they usually deal with them during the analyzing requirements portion of the development lifecycle. IT pros who open the Windows PowerShell ISE first, and think about the design requirements second, become easily stymied, or else write-in problems. For more information about this, see my Microsoft Press book, Windows PowerShell 2.0 Best Practices.
The following example creates a new registry key named test in the HKCU:\Software location. Because the command includes the full path, it does not need to execute from the HKCU drive. Because the command uses the Force switched parameter, the command overwrites the HKCU:\Software\test registry key if it already exists.
New-Item -Path HKCU:\Software -Name test –Force
Just the steps: The short way to create a new registry key
- Include the full path to the registry key to create.
- Use the Force parameter to overwrite any existing registry key of the same name.
In the following image, the first attempt to create a test registry key fails because it already exists. The second command uses the Force parameter, which causes the command to overwrite the existing registry key, and therefore it succeeds without creating an error.
Setting the default value for the key
The previous examples do not set the default value for the newly created registry key. If the registry key already exists (as it does in this specific case), use the Set-Item cmdlet to assign a default value to the registry key. The steps to accomplish this are shown here:
Just the steps: Assign a default value to an existing registry key
- Use the Set-Item cmdlet and supply the complete path to the existing registry key.
- Supply the default value in the Value parameter of the Set-Item cmdlet.
The following command assigns the value “test key” to the default property value of the hsg registry key contained in the HKCU:\Software location.
Set-Item -Path HKCU:\Software\test -Value “test key”
Join me tomorrow when I will talk about more cool Windows PowerShell stuff.
This guide demos 3 methods to create new outlook profile..
Options to Create New Outlook Profile
The 3 methods to create new Outlook profile discussed in this guide are:
- From Outlook Account Settings
- From Control Panel
- Accessing OLCFG.EXE in Program Files
To create an Outlook profile, you need to access Mail Setup (shown below). The difference between the 3 methods discussed in this guide is how Mail Setup is accessed.
Create New Outlook Profile From Outlook Account Settings
Here are the steps for this method:
- Open Outlook. Then click File and click Account Settings drop-down. Finally, select Manage Profiles.
- When Mail Setup opens, click Show Profiles..
- If you receive User Account Control confirmation, click Yes.
- At Mail profiles, you have 2 options: Use Add button to add a new profile. Or use Copy button to copy an exiting profile into a new profile. To copy and existing Outlook profile select the profile from the list then click Copy…
- On the Copy Profile pop up, rename the profile. Then click OK.
- To load this profile by default, on the When Starting Outlook, use this profile section, select Always use this profile. Then select the new profile from the drop-down.
Create New Outlook Profile From Control Panel
You can also access Mail settings for Outlook profiles from Control Pane.
Here are the steps..
- Press Windows logo + R to open Run Command.
- At Run command type Control Panel and click OK.
- If Control Panel View by is in Category, click the drop-down. Then select Small icons.
- On the Small icons Control Panel view, click Mail (Microsoft Outlook xxx(xx bits).
- When Mail Setup opens, click Show Profiles..
- At Mail profile settings, click Add..
- On the New Profile pop up, give the profile a name. Then click OK.
- On the Add Account page, enter your name and the email address you wish to add to the new profile. Then type and retype the password for the email and click Next.
- If you are prompted to reenter your password. Type it then click Sign in. This page may look different depending on your email provider.
- Depending on your email provider, you may also receive this message. Click Next.
- If Outlook is able to connect to your email, it will setup and add the profile to outlook. On the final page, click Finish. The new outlook profile will become available in your Mail Profile (See the second image below).
Create New Outlook Profile by Accessing OLCFG.EXE in Program Files
The last method discussed in this guide demos how to access Mail Setup from Program Files.
Here are the steps to create new Outlook profile with this method:
- Type %Programfiles(x86)% in search bar. Then click the folder in the search result.
- When your Program Files folder opens, navigate to Microsoft Office\root folder.
- Then, depending on your version of Office, open either Office Office 15 or Office 16 folder.
- Within Office 15 or Office 16 folder, locate and open OLCFG.EXE. Then respond Yes to the User Account Control confirmation.
- When the Mail Setup opens, click Show Profiles…
- To create new Outlook profile click Add…Alternatively, you could copy an existing profile using Copy…
You should be able to create new Outlook profile with one of the methods discussed in this guide.
However, if your current outlook profile is corrupt do not copy the existing profile as it may copy the issues across to the new profile. In such situation it is better to create a new profile.
Have a question, comment or feedback? Use the “Leave a Reply” form found at the end of this page.
For more emails and productivity guides visit our Emails & Productivity How-to page.
In the PowerShell command type:
to install the PowerShell Azure AD Module.
You can then check that the AzureAD Powershell Module has been installed successfully by typing the following command:
and most of all that the module can be actually used:
then go to the directory where the module was installed to be able to copy the path and the name of the dll we need later.
It should be:
3. Loading the Microsoft.Open.AzureAD16.Graph.Client.dll within PowerShell Application.
4. Creating the user in Azure AD
Then let’s create the password variable. You can use [email protected] that is compliant to the required rules for an Azure AD password: Then we have to connect to Azure AD in order to really create the user. Type: A dialog is opening for you to type your Azure Account Login
then your Azure Account password
You should have the following screen after the connection:
Then type the following line by replacing the tenant domain of the User Principal Name by your tenant domain (mine is charmoisdev.onmicrosoft.com): You sould have the following screen after user creation:
You can then check in the Azure Portal that your user has been created successfully:
I am writing a PowerShell script to create several directories if they do not exist.
The filesystem looks similar to this
- Each project folder has multiple revisions.
- Each revision folder needs a Reports folder.
- Some of the “revisions” folders already contain a Reports folder; however, most do not.
I need to write a script that runs daily to create these folders for each directory.
I am able to write the script to create a folder, but creating several folders is problematic.
12 Answers 12
Try the -Force parameter:
See the New-Item MSDN help article for more details.
Test-Path checks to see if the path exists. When it does not, it will create a new directory.
This internally checks for directory existence, and creates one, if there is no directory. Just one line and native .NET method working perfectly.
The following code snippet helps you to create a complete path.
The above function split the path you passed to the function and will check each folder whether it exists or not. If it does not exist it will create the respective folder until the target/final folder created.
To call the function, use below statement:
The first line creates a variable named $path and assigns it the string value of “C:\temp”
The second line is an If statement which relies on the Test-Path cmdlet to check if the variable $path does not exist. The not exists is qualified using the ! symbol.
Third line: If the path stored in the string above is not found, the code between the curly brackets will be run.
md is the short version of typing out: New-Item -ItemType Directory -Path $path
Note: I have not tested using the -Force parameter with the below to see if there is undesirable behavior if the path already exists.
If you have Outlook configured as your main mail client in Windows 10, this is how to re-create your Outlook profile.
You might ask why do you ever want to do this? Well, for one this is a quick way to troubleshoot any unknown issues when there is no obvious path to resolve a malfunction. Especially if your Outlook’s exchange account is tied to your Window’s login (with single-sign-on). In the case below Outlook refuses to establish the connection against Exchange server, while at the same time you are able to access exchange’s webmail. We’ve ruled out network connectivity issues, but Outlook still unable to connect. It’s possible that you have a corrupted Outlook profile, to test out this theory you need to reset your Outlook Profile. Follow the steps below to perform this operation.
To perform and reset your Outlook profile, you need to go to Control Panel > (search for) mail and find the “Mail (32-bit)” option.
Go follow the link under Profiles > Show Profiles…
Here you want to select your existing profile and Remove it, then Add a new one.
Now, ensure Outlook is fully restarted (have quit the process) and try again. With any luck your Outlook will function again.
I have a PowerShell sample to delete folders from Outlook and user asked how to use PowerShell to create folders. The PowerShell samples on this page create subfolders in the Inbox, or, by changing one line, add the folders to the root of the mailbox, at the same level as the Inbox.
The first PowerShell has the folder name in the Folders.Add line. If you need more than one folder, repeat the line. However, it is generally much easier to create a text file with one folder name per line than to copy and edit each line. The second set of PowerShell scripts use a text file for the folder names.
To add the folder at the same level as the Inbox, change this line:
This PowerShell script reads the folder names from a text file. Use this is you need to frequently create new folders as the text file is generally easier to update.
To add the folders at the same level as the Inbox, change this line:
Don’t forget to change the path to the text file!
Enter your folder names in a text file, one name per line.
Like the script above, this PowerShell script reads the folder names from a text file. It just uses a different method to read the text file.
The scripts above work with the default data file; to add the folders to a secondary data file in your profile, you need add another line to identify the data file. You’ll also need ot refer to the parent folder by name.
If you need to delete the folders you added, this PowerShell will read the text file and delete the folders. This script moves the folders to the deleted items folder. To delete them from the Deleted Items folder, change 6 to a 3 in this line:
$Folder = $namespace.GetDefaultFolder(6)
To open the PowerShell IDE, type powershell on the start menu and click on Windows PowerShell ISE when the PowerShell app is found. Paste the script in the editing window.
Note: This PowerShell script will not work with the Windows Store version of Office. You’ll need to use the macro version if you have the Windows store version of Office installed.
Saving PowerShell Scripts
If you want to save the script as a .ps1 file, paste it into Notepad and save it with the extension .ps1. To open it in the PowerShell IDE, type powershell on the start menu and click on Windows PowerShell ISE when the PowerShell app is found. Paste the script in the editing window.
To use it, you need to allow local scripts by running this command:
To run your saved .ps1 file, right-click on the script and choose Run with PowerShell.
A VBA macro that creates folders from a CSV list of filenames is here: Create Outlook Folders from a List of Folder Names
About Diane Poremsky
A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.
Windows classifies the networks into three different types: public, private and domain, with this allows different firewall configurations to be applied according to the established profile. If you want to force a network to be of a different profile, my recommendation is that you use PowerShell. This time we will use the cmdlet Set-NetConnectionProfile.
To established network profile with PowerShell, use the Set-NetConnectionProfile cmdlet with the following syntax:
The Get-NetConnectionProfile cmdlet gets a connection profile associated with the physical network adapters. A connection profile represents a network connection.
Run PowerShell console as administrator, and then type:
This command set the network category, using the -InterfaceIndex parameter.
It is important to know that you can not set the DomainAuthenticated type by using this cmdlet. The computer automatically sets the Domain value when the network is authenticated to a domain controller.
This post covers the steps to create a work profile for personal devices in Intune. Microsoft Intune allows you to create work profiles on our personal Android and IOS devices. This is done through an Integrated profile without modifying our applications and personal configurations.
Intune helps you deploy apps and settings to Android Enterprise work profile devices to make sure work and personal information are separate.
Let’s see how we can perform this procedure from the Microsoft Intune console. To know more about managing Android work profiles with Intune, read this post.
Create a Work Profile for Personal Devices in Intune
Launch the Intune portal. Go to Android Enrollment and click Personal devices with work profile.
Most of all use work profiles to manage corporate data and applications on Android devices owned by users. By default, enrollment of personally owned work profile devices is enabled, hence no further action is necessary.
To configure platform restrictions and assign them to specific user groups, go to Registration Restrictions. Block enrollment of Android device administrators in enrollment restrictions if you only want users to sign up with Android Enterprise work profiles.
Now open Google Play and download Intune Company portal to register our personal device.
We will follow the instructions marked to be able to access our Work-Profile and be able to manage it from Intune.
At the end of the wizard we can see in our team the added profile and in which the applications previously intended for the group that hosts the device.
You can also see the applications.
Going back to Intune portal, we can see the device with the applications.
Clicking the device shows more details about it.
Finally if you click Managed Apps, we can see all apps installed on the Android device. With this configuration we can work and enjoy our devices without having to format them and lose our personal information.