Sturbi's Home

  • Gallery
  • Modellflug
  • Datenschutz
  • Impressum

Blog

  • Allgemein (15)
    • Sprüche (6)
  • Angeln (3)
  • Computer (25)
    • Linux (16)
      • Nagios (5)
      • Nginx (4)
      • Postfix (3)
      • Subversion (1)
    • VMware (3)
    • Windows (9)
      • Powershell (8)
  • Fotografie (26)
  • Reise (8)
    • Hawaii (4)
    • Irland (1)
    • USA (5)
Wenn du etwas so machst,
wie du es seit zehn Jahren gemacht hast,
dann sind die Chancen groß,
daß du es falsch machst.

Charles F. Kettering amerikanischer Ingenieur * 29.08.1876, † 25.11.1958

Pimp my Powershell Environment

19. Juli 2012 by Sturbi Kategorie: Powershell, Windows

Hier einmal meine Microsoft.PowerShell_profile.ps1

Wichtig ist mir vor allem, das die Powershell schnell startet. Also möglicht wenige Module laden.
Zum schnellen Nachladen der einzelnen Module habe ich die Aufrufe in Funktionen verpackt, welche sich über „load-XXX“ aufrufen lassen.(siehe Script loads.ps1)
Das Quest Active Directory  wird standardmäßig geladen. Bits benötigt kaum Zeit zum laden und ich benutze es gern um Downloads durchzuführen.

Meine lokalen Scripte lege ich im Ordner $lib ab.

Als Editor verwende ich überwiegend Notepad++, welcher über den alias e aufgerufen wird.

Um über die Command Line Dateien via scp zu kopieren benutze ich das Client Pack von VanDyke.
Meine SSH Verbindungen rufe ich über Funktionen im Script ssh.ps1 auf. An Stelle von SecureCRT kann man auch mit Putty arbeiten.

Mit den Funktionen „big“ und „small“ kann ich schnell die Konsole in ihrer Größe verändern, ohne die Maus zu bemühen.

Add-PSSnapin Quest.ActiveRoles.ADManagement
Import-Module BitsTransfer

$lib = "C:\data\PowerShell\lib\"

set-alias -Name vi -Value "C:\Program Files (x86)\Vim\vim73\vim.exe" -Force
set-alias -Name Edit-File -Value "C:\Program Files (x86)\Notepad++\notepad++.exe" -Force
set-alias -Name e -Value "C:\Program Files (x86)\Notepad++\notepad++.exe" -Force

Set-Alias -Name scp -Value "C:\Program Files\VanDyke Software\ClientPack\vcp" -Force
Set-Alias -Name ssh -Value "C:\Program Files\VanDyke Software\ClientPack\vsh" -Force

. "C:\data\PowerShell\lib\ssh.ps1"
. "C:\data\PowerShell\lib\loads.ps1"

$env:PSModulePath = "$env:PSModulePath;C:\data\powershell\Modules\"

function global:prompt {
    # our theme
    $cdelim = [ConsoleColor]::DarkCyan
    $chost = [ConsoleColor]::Green
    $cloc = [ConsoleColor]::Cyan

    write-host "$([char]0x0A7) " -n -f $cloc
    write-host ([net.dns]::GetHostName()) -n -f $chost
    write-host ' {' -n -f $cdelim
    # write-host (shorten-path (pwd).Path) -n -f $cloc
	write-host (pwd).Path -n -f $cloc
    write-host '}'  -f $cdelim
	Write-Host ":~#" -NoNewline -ForegroundColor $cdelim
    return ' '
}

function big(){

$pshost = get-host
$pswindow = $pshost.ui.rawui

$newsize = $pswindow.buffersize
$newsize.height = 3000
$newsize.width = 180
$pswindow.buffersize = $newsize

$newsize = $pswindow.windowsize
$newsize.height = 80
$newsize.width = 180
$pswindow.windowsize = $newsize
}

function small(){

$pshost = get-host
$pswindow = $pshost.ui.rawui

$newsize = $pswindow.windowsize
$newsize.height = 24
$newsize.width = 80
$pswindow.windowsize = $newsize

$newsize = $pswindow.buffersize
$newsize.height = 24
$newsize.width = 80
$pswindow.buffersize = $newsize
}

function load-PowerTabe()
{
	Import-Module "PowerTab" -ArgumentList "C:\data\powershell\Modules\PowerTab\PowerTabConfig.xml"
	$PowerTabConfig.DefaultHandler = "Intellisense"
	$PowerTabConfig.DoubleBorder = $False
}

function load-PSCX()
{
	Import-Module Pscx
}

function load-Exchange()
{
	. 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto
}

function load-Sharepoint()
{
	$ver = $host | select version
	if ($ver.Version.Major -gt 1)  {$Host.Runspace.ThreadOptions = "ReuseThread"}
	Add-PsSnapin Microsoft.SharePoint.PowerShell
	Set-location $home
}

function load-SQL()
{
	$ErrorActionPreference = "Stop"

	$sqlpsreg="HKLM:\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.SqlServer.Management.PowerShell.sqlps"

	if (Get-ChildItem $sqlpsreg -ErrorAction "SilentlyContinue")
	{
		throw "SQL Server Provider for Windows PowerShell is not installed."
	}
	else
	{
		$item = Get-ItemProperty $sqlpsreg
		$sqlpsPath = [System.IO.Path]::GetDirectoryName($item.Path)
	}

	#
	# Set mandatory variables for the SQL Server provider
	#
	Set-Variable -scope Global -name SqlServerMaximumChildItems -Value 0
	Set-Variable -scope Global -name SqlServerConnectionTimeout -Value 30
	Set-Variable -scope Global -name SqlServerIncludeSystemObjects -Value $false
	Set-Variable -scope Global -name SqlServerMaximumTabCompletion -Value 1000

	#
	# Load the snapins, type data, format data
	#
	Push-Location
	cd $sqlpsPath
	Add-PSSnapin SqlServerCmdletSnapin100
	Add-PSSnapin SqlServerProviderSnapin100
	Update-TypeData -PrependPath SQLProvider.Types.ps1xml 
	# update-FormatData -prependpath SQLProvider.Format.ps1xml 
	Pop-Location

	#
	# Loads the SQL Server Management Objects (SMO)
	#

	$ErrorActionPreference = "Stop"

	$sqlpsreg="HKLM:\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.SqlServer.Management.PowerShell.sqlps"

	if (Get-ChildItem $sqlpsreg -ErrorAction "SilentlyContinue")
	{
		throw "SQL Server Provider for Windows PowerShell is not installed."
	}
	else
	{
		$item = Get-ItemProperty $sqlpsreg
		$sqlpsPath = [System.IO.Path]::GetDirectoryName($item.Path)
	}

	$assemblylist = 
	"Microsoft.SqlServer.Management.Common",
	"Microsoft.SqlServer.Smo",
	"Microsoft.SqlServer.Dmf ",
	"Microsoft.SqlServer.Instapi ",
	"Microsoft.SqlServer.SqlWmiManagement ",
	"Microsoft.SqlServer.ConnectionInfo ",
	"Microsoft.SqlServer.SmoExtended ",
	"Microsoft.SqlServer.SqlTDiagM ",
	"Microsoft.SqlServer.SString ",
	"Microsoft.SqlServer.Management.RegisteredServers ",
	"Microsoft.SqlServer.Management.Sdk.Sfc ",
	"Microsoft.SqlServer.SqlEnum ",
	"Microsoft.SqlServer.RegSvrEnum ",
	"Microsoft.SqlServer.WmiEnum ",
	"Microsoft.SqlServer.ServiceBrokerEnum ",
	"Microsoft.SqlServer.ConnectionInfoExtended ",
	"Microsoft.SqlServer.Management.Collector ",
	"Microsoft.SqlServer.Management.CollectorEnum",
	"Microsoft.SqlServer.Management.Dac",
	"Microsoft.SqlServer.Management.DacEnum",
	"Microsoft.SqlServer.Management.Utility"

	foreach ($asm in $assemblylist)
	{
		$asm = [Reflection.Assembly]::LoadWithPartialName($asm)
	}

	Push-Location
	cd $sqlpsPath
	update-FormatData -prependpath SQLProvider.Format.ps1xml 
	Pop-Location

}

function load-VMWare()
{
	# Adds the base cmdlets
	Add-PSSnapin VMware.VimAutomation.Core
	# Add the following if you want to do things with Update Manager
	Add-PSSnapin VMware.VumAutomation
	# This script adds some helper functions and sets the appearance. You can pick and choose parts of this file for a fully custom appearance.
	# . "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-VIToolkitEnvironment.ps1"

	. "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1"
	Connect-VIServer -Server vcenter
}

function load-EQL()
{
	Import-Module -name "C:\Program Files\EqualLogic\bin\EqlPSTools.dll"
}

function telnet-switch-iscsi-1{
	& "C:\Program Files\VanDyke Software\Clients\SecureCRT.exe" /T /TELNET 192.168.9.221
}

function ssh-hermes{
	& "C:\Program Files\VanDyke Software\Clients\SecureCRT.exe" /T /SSH2 wutz@10.0.10.5
}

function ssh-hermine{
	& "C:\Program Files\VanDyke Software\Clients\SecureCRT.exe" /T /SSH2 wutz@hermine
}

 

 

 

 

© 2026 · Sturbi's Home