---------- Go to Part 1 ----------
What goes in my profile ?
This part will be SCOM oriented by you must keep in mind that all cmdlets, scripts, functions and any command in powershell could be added to your profile.
- Function to connect OpsMgr Environment
This command will open a windows that ask you to enter the password for your crédentials
Here is the few powershell line to copy in your profile file : (Replace the red words by your RMS name + your credential). Note that you can set the password in parameters of the Get-Credentials( ) but this is not really secure.
- function Connect ([string]$RMS)
- {
- switch ($RMS.toupper()) {
- "PROD" {$RMS="RMSName1"}
- "DEV" {$RMS="RMSName2"}
- "PP" {$RMS="RMSName3"}
- "PREPROD" {$RMS="RMSName3"}
- default {"RMS - $RMS - not valid"; exit }
- }
- # Load Operation Manager environment
- if ( (Get-pssnapin | where {$_.Name -eq "Microsoft.EnterpriseManagement.OperationsManager.Client" }).Name -ne "Microsoft.EnterpriseManagement.OperationsManager.Client" ) {
- add-pssnapin "Microsoft.EnterpriseManagement.OperationsManager.Client" -ErrorVariable errSnapin; }
- $creds = Get-Credential("MyDomain\MyAccount");
- $connection = New-ManagementGroupConnection -ConnectionString: $RMS -Credential: $creds #-ErrorAction:SilentlyContinue;
- # Move off of a drive to avoid deadlock.
- Set-Location "OperationsManagerMonitoring::" | Out-Null;
- }
- Function to list process information
Here is the code to copy in your profile file :
- function p-list([string]$name="*")
- {
- $WMIQuery = get-wmiobject win32_service | sort ProcessId | group-object ProcessId
- $Processes = @(get-process $name | sort Id)
- $i=0
- $j=0
- while($i -lt $Processes.count -and $j -lt $WMIQuery.count)
- {
- if($Processes[$i].Id -lt $WMIQuery[$j].Name)
- {
- $i++;
- continue;
- }
- if($Processes[$i].id -gt $WMIQuery[$j].Name)
- {
- $j++;
- continue;
- }
- if($Processes[$i].id -eq $WMIQuery[$j].Name)
- {
- $Processes[$i]| add-member NoteProperty service $WMIQuery[$j].group;
- $i++;
- $j++;
- }
- }
- $Processes;
- }
- Function to list active SDK connection information
http://tetris38.blogspot.fr/2012/03/opsmgr-2007-powershell-script-to-list.html
- function List-SDK()
- {
- # Get the connected users
- $SDKUsers = Get-ManagementGroupConnection | foreach-object {$_.ManagementGroup.getConnectedUserNames()} | sort
- $SDKNumberConnections = $SDKUsers | measure-object
- # number of active connections
- $SDKNumberConnections.count
- # count active connections per users
- $hash =@{}
- $SDKUsers | % {$hash[$_] = $hash[$_] + 1 }
- $Result = $hash.getenumerator() | ? { $_.value -gt 0 }
- $Result | sort value -DESC
- }
- Shell Windows tuning
- # Change Title - to "Windows PowerShell - your account"
- $Host.UI.RawUI.WindowTitle = "Windows PowerShell - " + $env:Username
- # Change background color
- $Host.UI.RawUI.BackgroundColor = "DarkBlue"
- # Change Text color
- $Host.UI.RawUI.ForegroundColor = "White"
You can download all the example I've provided in the file below
This posting is provided "AS IS" with no warranties.
No comments:
Post a Comment