Posts Tagged ‘Module’

I do not know about everyone else. I am a rather busy admin and quite fond of powershell and scripting. However, I also have a separate admin account for doing my administrative tasks. Now when you are working with multiple systems, all of which have PowerShell consoles, it can become a little bit of a pain opening a console for Exchange 2010, Operations Manager 2010, Virtual Machine Manager and Service Manager to name a few. There are tons of products that now have powershell interfaces. Would it not be great to have ONE SHELL to control them all, with all the PSSnapins and Modules? The answer is of course, YES. This is what I got right thanks to Uncle GOOGLE and a lot a research and a wonderful thing called the Powershell Profile. So using another link I found as a base, I started my mission. I though of all the modules and pssnapins I used and created the shell below.

image

It adds all the Modules and PSSnapins I use on a daily basis, I also copied the same profile.ps1 to my “admin” profile so that the same would happen when using this as my “admin” account. See code snippet below. The first line of code caters for those people like me using PowerGui and the Script-Explorer addon, that took some time for figure out, hope you enjoy Smile (2 different views included to make it easier to use if you so wish)

 
================================================================

import-module Add-on.ScriptExplorer

# Sets APPDATA environment variable if it doesn’t exist
if (! (Test-Path [string]$env:APPDATA) ) {$env:APPDATA = $env:USERPROFILE + "\Application Data"}
 
# Create Powershell Drives
#New-PSDrive -name SCRIPT -psprovider FileSystem -root "\\fileshare\data\IT Department\Team\Scripts"
#New-PSDrive -name VMSCRIPT -psprovider FileSystem -root "\\fileshare2\common\IT Department\Projects\VMWare\Scripts"
#Set-Location VMSCRIPT:
"You are now PowerShell : " + $env:Username
 
# Exchange 2010
if (((Get-PSSnapin -Name "Microsoft.Exchange.Management.PowerShell.E2010" -ErrorAction SilentlyContinue) -eq $null ) -and ((Get-PSSnapin –registered -Name "Microsoft.Exchange.Management.PowerShell.E2010") -ne $null))
{
   Write-Host "Adding Exchange 2010" -ForegroundColor Green
   Add-PSSnapin -name Microsoft.Exchange.Management.PowerShell.E2010
   ."C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1"; "Connect-ExchangeServer -auto"
}
# Virtual Machine Manager
if (((Get-PSSnapin -Name "Microsoft.SystemCenter.VirtualMachineManager" -ErrorAction SilentlyContinue) -eq $null ) -and ((Get-PSSnapin –registered -Name "Microsoft.SystemCenter.VirtualMachineManager") -ne $null))
{
   Write-Host "Adding Virtual Machine Manager" -ForegroundColor Green
   Add-PSSnapin -name Microsoft.SystemCenter.VirtualMachineManager
   #C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files\Microsoft System Center Virtual Machine Manager 2008 R2\bin\cli.psc1" -NoExit
}

# Quest Active Directory
if (((Get-PSSnapin -Name "Quest.ActiveRoles.ADManagement" -ErrorAction SilentlyContinue) -eq $null ) -and ((Get-PSSnapin –registered -Name "Quest.ActiveRoles.ADManagement") -ne $null))
{
   Write-Host "Adding Quest Active Directory" -ForegroundColor Green
   Add-PSSnapin -name Quest.ActiveRoles.ADManagement
}
#SMCmdletSnapIn
if (((Get-PSSnapin -Name "SMCmdletSnapIn" -ErrorAction SilentlyContinue) -eq $null ) -and ((Get-PSSnapin –registered -Name "SMCmdletSnapIn") -ne $null))
{
   Write-Host "System Centre 2010 Snapin" -ForegroundColor Green
   Add-PSSnapin -name SMCmdletSnapIn
}
# Operations Manager 2007
if (((Get-PSSnapin -Name "Microsoft.EnterpriseManagement.OperationsManager.Client" -ErrorAction SilentlyContinue) -eq $null ) -and ((Get-PSSnapin –registered -Name "Microsoft.EnterpriseManagement.OperationsManager.Client") -ne $null))
{
   Write-Host "Operations Manager 2007 Snapin" -ForegroundColor Green
   Add-PSSnapin -name Microsoft.EnterpriseManagement.OperationsManager.Client
}
# time to import smlets
$exist = $false
foreach ($modulePath in ${env:PSModulePath}.Split(";"))
{
   if ((Test-Path ($modulePath + "Smlets\smlets.Module.dll")) -and !$exist)
   {
   Write-Host "Adding SMLets for SCSM 2010" -ForegroundColor Green
   $exist = $true
   Import-Module smlets
   }

}
#time to import ActiveDirectoryModule
$exist = $false
foreach ($modulePath in ${env:PSModulePath}.Split(";"))
{
   if ((Test-Path ($modulePath + "ActiveDirectory\ActiveDirectoryPowerShellResources.dll")) -and !$exist)
   {
   Write-Host "Adding ActiveDirectory Module" -ForegroundColor Green
   $exist = $true
   Import-Module ActiveDirectory
   }
}
#time to import FailoverClusters Module
$exist = $false
foreach ($modulePath in ${env:PSModulePath}.Split(";"))
{
   if ((Test-Path ($modulePath + "FailoverClusters\Microsoft.FailoverClusters.PowerShell.dll")) -and !$exist)
   {
   Write-Host "Adding Failover Clusters Module" -ForegroundColor Green
   $exist = $true
   Import-Module FailoverClusters
   }
}
#time to import Group Policy Module
$exist = $false
foreach ($modulePath in ${env:PSModulePath}.Split(";"))
{
   if ((Test-Path ($modulePath + "GroupPolicy\GroupPolicy.psd1")) -and !$exist)
   {
   Write-Host "Adding Group Policy Module" -ForegroundColor Green
   $exist = $true
   Import-Module GroupPolicy
   }
}

function prompt
{
    $cwd = (get-location).Path
    $host.UI.RawUI.WindowTitle = "Fletcher’s Shell " + $global:connectedFqdn
    $host.UI.Write("Yellow", $host.UI.RawUI.BackGroundColor, "[PS]")
    " $cwd>"
}

function get-fletchbanner
{
    write-host "`n         Welcome to the Fletch’s Management Shell!`n"   
}

get-fletchbanner
cd\

=============================================================

 

Talking about “admin” accounts, the one BIG thing about Windows 7 is the lack of “Running as another account and elevated”. I also found a solution to this as well.

I really hope this helps everyone, like this has helped me.

 

Follow me

clip_image001 clip_image002 clip_image003