PowerShell Profile Locations

PowerShell uses different profile files depending on which Host, or application you’re using.

Below are the defaults for PowerShell 5.1

All Users, All Hosts (PowerShell console, ISE) – $PSHOME\Profile.ps1

All Users, Current Host (PowerShell console) – $PSHOME\Microsoft.PowerShell_profile.ps1

    All User, Current Host (VS Code) – $PSHOME\Microsoft.VSCode_profile.ps1

    Current User, All Hosts (PowerShell console, ISE) – $HOME\Documents\WindowsPowerShell\Profile.ps1

    Current user, Current Host (PowerShell console) – $HOME\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

    Current user, Current Host (VS Code) – $HOME\Documents\WindowsPowerShell\Microsoft.VSCode_profile.ps1

    To edit or create each of the profile files, you can use the following commands with the $Profile variable:

    Current User, Current Host – notepad $PROFILE

    Current User, Current Host – notepad $PROFILE.CurrentUserCurrentHost

    Current User, All Hosts – notepad $PROFILE.CurrentUserAllHosts

    All Users, Current Host – notepad $PROFILE.AllUsersCurrentHost

    All Users, All Hosts – notepad $PROFILE.AllUsersAllHosts


    PowerShell tip: $PSDefaultParameters

    If you’re an avid user of PowerShell you’ve probably, at some point gotten sick of providing values for the same parameters over and over. The solution, use $PSDefaultParameters. Using this preference variable you can set default values like the DC used with the AD cmdlets, the SQL server you connect to, or the error preference for all cmdlets or a subset. This means you can essentially pre-enter the desired value once, and the cmdlet will automatically use it. Pretty cool, huh?

    Examples:
    $PSDefaultParameterValues["*-AD*:Server"] = "dc01.corp.viamonstra.com"

    Add/Remove single entries:
    $PSDefaultParameterValues.Add('Get-ADComputer:Server', 'dc01')
    $PSDefaultParameterValues.Remove('*-GPO:Name')

    The $PSDefaultParameterValues variable is only available in the session you set it in. The easiest way to take advantage of $PSDefaultParameterValues is to add them to you PowerShell profile. That way each time you start a PowerShell session, the default values are already set for you.

    PowerShell profile example:
    $PSDefaultParameterValues['Get-ChildItem:Force'] = $true
    $PSDefaultParameterValues[':ErrorAction'] = 'Stop' $PSDefaultParameterValues['Get-:Recurse'] = $true

    Here is a link to Microsoft’s documentation of $PSDefaultParameters.

    Copy GPO with PowerShell

    If you need to make a copy of a group policy, using the Group Policy Management Console can be a slow process. Using PowerShell is a much faster process.

    All you need is the name of the source GPO copied to the clipboard.

    Copy-GPO -SourceName "Edge Browser Settings - Test" -TargetName "Edge Browser Settings - Prod"
    

    You can also copy by using the GUID of the source and/or destination GPO. In addition, you can copy GPOs between domains.

    copy-gpo -SourceName "Edge Browser Settings - Test" -SourceDomain "corp.viamonstra.com" -TargetName "Edge Browser Settings - Prod" -TargetDomain "lab.viamonstra.com"
    

    I don’t have an image of copying between domains because my lab only contains a single domain.