====== Powershell Umgebung einrichten ======
Datei $profile erstellen und anpassen
# Wo liegt das Profil
$profile
C:\Users\gpipperr\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
# testen ob das Profil schon exisitert
test-path $Profile.CurrentUserAllHosts
false
# Falls false anlegen
new-item -path $profile -type file -force
#Anpassen
notepad C:\Users\gpipperr\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
#signieren falls Ausführungsrechte auf AllSigned gesetzt und zertifikate angelegt wurden
Set-AuthenticodeSignature .\Microsoft.PowerShell_profile.ps1 @(Get-ChildItem cert:\CurrentUser\My -codesigning)[0]
Beispiel: Microsoft.PowerShell_profile.ps1
# prüfen ob eine administrative Session gestartet wurde
# Quelle http://www.interact-sw.co.uk/iangblog/2007/02/09/pshdetectelevation
& {
$wid=[System.Security.Principal.WindowsIdentity]::GetCurrent()
$prp=new-object System.Security.Principal.WindowsPrincipal($wid)
$adm=[System.Security.Principal.WindowsBuiltInRole]::Administrator
$IsAdmin=$prp.IsInRole($adm)
# Hintergrund Farben setzen
if ($IsAdmin)
{
(get-host).UI.RawUI.Backgroundcolor="DarkRed"
}
else {
(get-host).UI.RawUI.BackgroundColor = "blue"
}
(get-host).UI.RawUI.ForegroundColor = "white"
clear-host
}
# Begrüßungs Screen
$d = get-Date -f dd.M.yyy
"Welcome the the Power Shell started :: " + $d
Profile in Abhängigkeit von Anwender/User
* $Profile.AllUsersAllHosts
* $Profile.AllUsersCurrentHost
* $Profile.CurrentUserAllHosts
* $Profile.CurrentUserCurrentHost
\\
Werden, falls vorhanden, in der Reihenfolge vom größten zum geringsten Gültigkeitsbereich ausgeführt.