PowerShell The Basics ( for me anyway )

PowerShell The Basics ( Profiles )

If you use one of the search engines now available you’ll find tons of information containing videos and blogs on what PowerShell is and explanations showing how to use it.  Simply put it could be any one of these things

  • What is PowerShell?
  • PowerShell Cmdlets
  • PowerShell Snapins
  • PowerShell Modules
  • PowerShell Remoting
  • Navigating in PowerShell
  • PowerShell Profiles

These are a  few things that I like to do when setting up PowerShell on my machine and machines in the environments where I typically work.  Providing that you have access to machines in your domain and the role you have can limit some processes within PowerShell. For example you might not have AD (Active Directory) access to review users or computer roles. But, if access is granted PowerShell can be of value.

Most people and especially system admins  have tools and scripts they like or have developed for researching files and folders, reading event logs and countless other uses.  Scripting tools like PowerShell can assist with and automate day to day processing and as an added bonus you don’t have to install executable programs in data centers or on production machines.

PowerShell comes to the aid allowing you to place common and often used scripts into modules that can be distributed to others and if placed into your profile, will be available each time you start a PowerShell session.

PowerShell Profile.

PowerShell essentially runs a script as the new session is started.  If the script is empty you get default PowerShell window. If you have a custom profile with custom modules and scripts those will run.*.ps1 Profiles can contain many useful functions.

PowerShell profile locations.

Show all profile names available

$PROFILE | Get-Member -MemberType noteproperty | select name
Name
—-
AllUsersAllHosts
AllUsersCurrentHost
CurrentUserAllHosts
CurrentUserCurrentHost

Show all profiles along with path

$PROFILE | Select-Object -Property *
AllUsersAllHosts :
C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1
AllUsersCurrentHost :
C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1
CurrentUserAllHosts :
C:\YourLocation\Documents\WindowsPowerShell\profile.ps1
CurrentUserCurrentHost :
C:\YourLocation\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
Length :
70

$Profile Standard default C:\YourLocation\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

Editing a profile is as simple as entering NOTEPAD $profile or which profile to edit could be NOTEPAD $Profile.AllUsersAllHosts.  etc..  As mentioned if no profile exists a nice popup allows you to create/save profile that you’re editing.noprofile

As you see profiles are nothing more then PowerShell scripts running for the duration of your session.

A profile can be as simple or complex as you’d like

function Edit-ProfileFile
{
Notepad $profile
}

Set-Alias -Name ep -value Edit-ProfileFile -Scope Global

Remember to set the windows PowerShell script execution policy to one of the following values: Restricted, AllSigned, RemoteSigned or Unrestricted.

I will be posting all profile code that I use on github as time permits.

Joseph

.



Categories: #PowerShell, PowerShell Posts, Technology

Tags: , , ,

Contribute Your Thoughts . . . . . . . . .

Discover more from Perspective - Joseph Kravis

Subscribe now to keep reading and get access to the full archive.

Continue reading