26 Nov 2014 @ 12:46 PM 

Also mainly because when I create screenshots for a blog article or document, I want those screenshots to provide me with some marketing.
So, I customize my PowerShell prompt:

PSWindow

But I want to be able to, looking at my prompt, identify if I’m running an elevated prompt or not.
Looking at Linux, you can see that by the fact that there’s a # in the prompt:

PSWindow_Elevated

So, here’s the code I use, which I’ve also put in my PowerShell profile :-)

if ((
        [Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()
    ).IsInRole(
        [Security.Principal.WindowsBuiltInRole] "Administrator"
    )){
    function prompt {
        'JeffWouters.nl #> '
    }
} else {
    function prompt {
        'JeffWouters.nl > '
    }    
}
Posted By: Jeff Wouters
Last Edit: 26 Nov 2014 @ 12:46 PM

EmailPermalinkComments (0)
Tags
Categories: DuPSUG, PowerShell

 25 Nov 2014 @ 7:45 AM 

By default, PowerShell has a few locations it knows there are modules located.
However, it is possible to load a module that’s residing in some custom path.
Note that IntelliSense and/or tab-completion won’t work in that case until you’ve loaded the module.
This is because it’s not located in a path known to the $Env:PSModulePath variable.
When a module resides in a path known in the $Env:PSModulePath variable, tab-completion for the cmdlets and even IntelliSense for those cmdlets will work.
So you can either edit the variable, move the module to a location known in the $Env:PSModulePath variable, or use my solution.

In PowerShell the is a beautiful thing called a profile. There even is a variable for it called $Profile.
This variable refers to a *.ps1 file.
Anything placed in this file is executed when you start a PowerShell prompt, or ISE.
But… by default there it refers to a file that doesn’t exist! So you’ll have to create it:

new-item $Profile -ItemType File -Force

Please note that the -Force parameter will overwrite any profile that may be there already!

Now that the file is created, you can put some code in there to load the module:

Add-Content -Path $Profile -Value 'Import-Module "C:\Program Files (x86)\SomeProduct\PowerShell\ProductModule.psd1"' -Force
Posted By: Jeff Wouters
Last Edit: 26 Nov 2014 @ 08:04 AM

EmailPermalinkComments (0)
Tags
Categories: AWS, Cloud, DuPSUG, PowerShell





 Last 50 Posts
 Back
Change Theme...
  • Users » 1
  • Posts/Pages » 339
  • Comments » 486
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight

About



    No Child Pages.

Contact



    No Child Pages.

Speaking



    No Child Pages.

Health Check



    No Child Pages.