This function will connect the management group and add OpsMgr snapin if you're not connected, create the specified folder if it doesn't exist and ask to re-use the folder if exist. You can execute the ExportMP function with no path, a new folder will be created in C:\Temp. Don't forget to change text in red
- Function ExportMP ([string]$RMS, [string]$PATH)
- {
- switch ($RMS.toupper()) {
- "PROD" {$RMS1="PRODRMS.Mydomain.com"}
- "DEV" {$RMS1="DEVRMS.Mydomain.com"}
- "PREPROD" {$RMS1="PREPRODRMS.Mydomain.com"}
- default {Write-Host "RMS - $RMS - not valid" -ForegroundColor red ;sleep 3;exit}
- }
- 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: $RMS1 -Credential: $creds
- Set-Location "OperationsManagerMonitoring::" | Out-Null;}
- If ($PATH -eq "")
- {
- $a = Get-Date -format d
- $a=$a.Replace('/', '-')
- $RMS = $RMS.toupper()
- $PATH = "C:\Temp\UnsealedMPs-"+$RMS+"-"+$a
- $TestPath = Test-Path $PATH
- if ( $TestPath -eq $False) {
- "Create a new backup folder: " + $PATH
- New-Item -ItemType directory -Path $PATH
- $Continue= "Yes"
- }
- else {
- Write-Host "Path - $PATH - already exist.
- " -ForegroundColor green
- $Question = Read-Host "Do you want to re-use it [Y/N] ?"
- Switch ($Question.toupper()){
- "Y" {$Continue= "Yes"}
- "N" {$Continue= "No"}
- default {$Continue= "No"}
- }
- }
- }
- Else { Write-Host "Folder doesn't exist - create the folder: $PATH" -ForegroundColor green
- New-Item -ItemType directory -Path $PATH
- $Continue= "Yes"}
- if ($Continue -eq "Yes") {
- $mps = get-managementpack | where-object {$_.Sealed -eq $false}
- foreach ($mp in $mps)
- {
- export-managementpack -managementpack $mp -path $PATH
- }
- }
- Else { Write-Host "No export Done" -BackgroundColor red -ForegroundColor yellow}
- }
This posting is provided "AS IS" with no warranties.
No comments:
Post a Comment