• Configuring Powershell

    Home » Forums » AskWoody support » Windows » Windows 10 » Questions: Win10 » Configuring Powershell

    Author
    Topic
    #2636467

    I cannot seem to figure out how to configure PS so that it does not matter whether I start it from a Start menu pinned shortcut, a desktop shortcut or the Programs Files shortcut.

    For that matter, whether I am setting the Windows Properties or the default Programs listing shortcut.

    Is there a way to open PS, set the defaults and such just like you want them and then have it be that way no matter where or how you open Powershell?

    Geez!

    Viewing 2 reply threads
    Author
    Replies
    • #2636470

      Not really. PS is fussy about what you can run from where – too many VBS viruses got through.

      I use the right click menu, set a shortcut or run direct from the PS window.

      cheers, Paul

      1 user thanked author for this post.
    • #2636480

      I cannot seem to figure out how to configure PS so that it does not matter whether I start it from a Start menu pinned shortcut, a desktop shortcut or the Programs Files shortcut.

      Make the desktop shortcut open PS as you would like.  Assign a keyboard shortcut to this shortcut.  Now anywhere you are on this system and you want PS, enter the keyboard shortcut and it will open the PS you have configured for that shortcut.

      If you want an Admin PS, you can use Task Scheduler to get a single click opening without the UAC security window.

      If you like your Desktop clean, you can make that shortcut invisible.

      I have a shortcut for an Admin Command window that can’t be seen on the Desktop, but Ctrl + Alt + C open that Admin Command no matter where I am on my system.

      HTH, Dana:))

    • #2636563

      C.W.,

      Have you setup your Profiles for Powershell?

      There are 2 profiles for Windows Powershell (version 5 or less):
      Microsoft.PowerShell_profile.ps1 — For the CLI version
      Microsoft.PowerShellISE_profile.ps1 — for the ISE version.

      Here’s a sample:

      <#
       +--------------------------------------------------------+
       | Computer Mentors System PowerShell CMD Profile         |
       |   11/28/2014 - Include StrictMode setting              |
       |   07/02/2016 - Changed to Set-Location vs 2 cmds.      | 
       |   01/29/2018 - Added PSReadLine Options                |
       |                Adj. path to include Win 10 SDK path.   |  
       |   07/25/2020 - Added $PSModuleAutoLoadPreference.      |
        +--------------------------------------------------------+
      #>
        
      Function Prompt {"PS>" }
      	
      Function Get-AdminStatus {
      
          If (-NOT ([Security.Principal.WindowsPrincipal] `
                [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
                [Security.Principal.WindowsBuiltInRole] "Administrator"))
          {
            "User:"
          }
          Else
          {
            "Administrator:"
          }
      } #End Get-AdminStatus
      
      $Bitness = & {If([Environment]::Is64BitProcess) {"64-Bit"} Else {"32-Bit"}}
      
      Set-Location -LiteralPath 'G:\BEKDocs\Scripts\Production'
      
      $Env:Path = $Env:Path + ";C:\Program Files (x86)\Windows Kits\10\bin\x64"
      
          $Shell=$Host.UI.RawUI
          $Shell.BackgroundColor="White"
          $Shell.ForegroundColor="Black"
          $Shell.CursorSize=10
          $Shell.WindowTitle="PowerShell $Bitness - $(Get-AdminStatus) $pwd"
      
      
      Import-Module G:\BEKDocs\WindowsPowershell\Modules\PSReadline
      Set-PSReadlineOption -TokenKind Keyword   -ForegroundColor DarkBlue 
      Set-PSReadlineOption -TokenKind Variable  -ForegroundColor Red 
      Set-PSReadlineOption -TokenKind Operator  -ForegroundColor DarkGray
      Set-PSReadlineOption -TokenKind Type      -ForegroundColor Cyan
      Set-PSReadlineOption -TokenKind Command   -ForegroundColor Blue
      Set-PSReadlineOption -TokenKind Parameter -ForegroundColor DarkCyan
      Set-PSReadlineOption -TokenKind Comment   -ForegroundColor DarkGreen
      Set-PSReadlineOption -TokenKind String    -ForegroundColor DarkRed
      Set-PSReadlineOption -TokenKind Number    -ForegroundColor DarkBlue
      Set-PSReadlineOption -TokenKind Member    -ForegroundColor Black
      
      
      Set-StrictMode -Version Latest
      $PSDefaultParameterValues = @{'Install-Module:Scope'='AllUsers'}
      
      <#+-----------------------------------------------------------+
        | Valid Values for $PSModuleAutoLoadingPreference:          | 
        | "All" - which will import the module of a command on      |
        |         first use.                                        |
        | "ModduleQualified" - which will import a module when you  |
        |                      specify module name\command name.    |
        | "None" - which disables module autoloading.               |
        +-----------------------------------------------------------+#>
      $PsModuleAutoLoadingPreference = "ALL"
      
      Clear-Host
      "`$PSModuleAutoLoadingPreference set to: $PsModuleAutoLoadingPreference"
      
      

      These profiles belong in your Documents->WindowsPowerShell folder.

      If you are using Version 6+ universal PowerShell the Microsoft.PowerShell_profile (there is no ISE) is located in the Documents->PowerShell directory.

      These profiles are run every time you start the given version of PowerShell, unless of course you start it with the -noprofile parameter!

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    Viewing 2 reply threads
    Reply To: Configuring Powershell

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: