Showing posts with label Export. Show all posts
Showing posts with label Export. Show all posts

Thursday, April 4, 2013

[MMS 2013] Retrieving MMS 2013 Content Sessions using PowerShell



Stefan Stranger has created a PowerShell script which retrieves all sessions of the MMS 2013 and makes it possible to export the result to a csv file using the Export-CSV cmdlet.

If you want you can do many more fun things with the results, let him know what you created.



Remarks:

Retrieving the website and getting the HTML Tag name elements can take some time to finish, be patient!
You need PowerShell v3 to run this script.


This posting is provided "AS IS" with no warranties.

[OpsMgr 2007 R2] Powershell script to export all product knowledge for rule and monitor for a specific MP

I've been asked to provide knowledge article to application owner in order to help them to determine what instruction to give to support level one for alert raised by SCOM management pack.

With no access to SCOM console, I didn't find an easy way to do it and I also decided to proceed with a powershell script.



Here are the command line I've written to export all product knowledge for rules and monitors for a specific MP. Create a PS1 file named ExportKnowledgeArticleFromAMP.ps1 and copy paste the command line from this post and go down and click download to get the PS1 file.

Usage a this script needs 2 parameters : MP name and Path to create files.
Example:
.\ExportKnowledgeArticleFromAMP.ps1 "Microsoft.Windows.Server.PrintServer.2012" "C:\Temp"

  1. param([string]$MPName, [string]$Path)
  2. # Script to export all product knowledge for rule and monitor for a specified MP 
  3. # usage : .\ExportKnowledgeArticleFromAMP.ps1 "Microsoft.Windows.Server.PrintServer.2012" "C:\Temp"
  4. function MamlToHTML($MAMLText)
  5. {
  6.  $HTMLText = "";
  7.  $HTMLText = $MAMLText -replace('xmlns:maml="http://schemas.microsoft.com/maml/2004/10"');
  8.  $HTMLText = $HTMLText -replace("maml:para","p");
  9.  $HTMLText = $HTMLText -replace("maml:");
  10.  $HTMLText = $HTMLText -replace("</section>");
  11.  $HTMLText = $HTMLText -replace("<section>");
  12.  $HTMLText = $HTMLText -replace("<section >");
  13.  $HTMLText = $HTMLText -replace("<title>","<h2>");
  14.  $HTMLText = $HTMLText -replace("</title>","</h2>");
  15.  $HTMLText = $HTMLText -replace("<listitem>","<li>");
  16.  $HTMLText = $HTMLText -replace("</listitem>","</li>");
  17.  $HTMLText = "<html><body>" + $HTMLText + "</body></html>";
  18.  $HTMLText;
  19. }
  20. # Mainline
  21. # Clear the screen.
  22. cls;
  23. # Get US Culture information.
  24. $ciUS = [System.Globalization.CultureInfo]'en-US';
  25. # Retrieve the Management Pack.
  26. $mps = get-managementpack
  27. $mp = $mps | ? { $_.Name -eq $MPName}
  28. $FolderName = $MPName + " - " + $mp.version
  29. # Create Folder
  30. New-Item -ItemType directory -Path $Path\$FolderName
  31. # Retrieve the Management Pack rules and monitors.
  32. $rules = $mp.getrules()
  33. $monitors = $mp.getmonitors()
  34. cls
  35. # Retrieve the knowledge Article for rules.
  36.  $i = 1
  37.  $j = 1
  38. foreach ($rule in $rules) {
  39.  $article = $rule.GetKnowledgeArticle($ciUS);
  40.  if ($article -ne $Null)
  41.  {
  42.   if ($article.MamlContent -ne $Null)
  43.   {
  44.     $article_text = $article.MamlContent;
  45.     $article_text = MamlToHTML($article_text);
  46.   }
  47.   write-host "Outputing HTML...";
  48.   if ($rule.DisplayName -ne "")
  49.     {
  50.     $RuleName = "Rule - " + [string]$i + " - " + [string]$rule.DisplayName
  51.     }
  52.   else
  53.     {
  54.     $RuleName = "Rule - " + [string]$i + " - " + [string]$rule.Name
  55.     }
  56.   # < > : " / \ | ? * removal
  57.    $RuleName
  58.   $RuleName = $RuleName.replace('<','lower than')
  59.   $RuleName = $RuleName.replace('>','Greater than')
  60.   $RuleName = $RuleName.replace('/','')
  61.   $RuleName = $RuleName.replace('|','')
  62.   $RuleName = $RuleName.replace('\','')
  63.   $RuleName = $RuleName.replace('!','')
  64.   $RuleName = $RuleName.replace('?','')
  65.   $RuleName = $RuleName.replace('*','')
  66.   $RuleName = $RuleName.replace(':','')
  67.   $RuleName = $RuleName.replace(';','')
  68.   $ExportFile = $Path + "\" + $FolderName + "\" + $RuleName + ".htm";
  69.   $article_text.tostring() | out-file $ExportFile
  70.   $i = $i + 1
  71.  }
  72. }
  73. # Retrieve the knowledge Article for monitors.
  74. foreach ($monitor in $monitors) {
  75.  $article = $monitor.GetKnowledgeArticle($ciUS);
  76.  if ($article -ne $Null)
  77.  {
  78.   if ($article.MamlContent -ne $Null)
  79.   {
  80.     $article_text = $article.MamlContent;
  81.     $article_text = MamlToHTML($article_text);
  82.   }
  83.   write-host "Outputing HTML...";
  84.    if ($monitor.DisplayName -ne "")
  85.     {
  86.     $MonitorName = "Monitor - " + [string]$j + " - " + [string]$monitor.DisplayName
  87.     }
  88.    else
  89.      {
  90.     $MonitorName = "Monitor - " + [string]$j + " - " + [string]$monitor.Name
  91.     }
  92.   # < > : " / \ | ? * removal
  93.    $MonitorName
  94.   $MonitorName = $MonitorName.replace('<','lower than')
  95.   $MonitorName = $MonitorName.replace('>','Greater than')
  96.   $MonitorName = $MonitorName.replace('/','')
  97.   $MonitorName = $MonitorName.replace('|','')
  98.   $MonitorName = $MonitorName.replace('\','')
  99.   $MonitorName = $MonitorName.replace('!','')
  100.   $MonitorName = $MonitorName.replace('?','')
  101.   $MonitorName = $MonitorName.replace('*','')
  102.   $MonitorName = $MonitorName.replace(':','')
  103.   $MonitorName = $MonitorName.replace(';','')
  104.   $ExportFile = $Path + "\" + $FolderName + "\" + $MonitorName + ".htm";
  105.   $ExportFile
  106.   $article_text.tostring() | out-file $ExportFile
  107.    $j = $j + 1
  108.  }
Executing the script will create a folder Microsoft.Windows.Server.PrintServer.2012 - 6.0.7004.0 that contains an HTML file for each monitor/rules.




Note :
  • The script sometimes return errors on some monitors or rules - I guess the conversion to HTML is failing - but in that case, the impact is that the HTML file is not created for that rule/monitor.
  • The script can be easily adapted of courses to run on OpsMgr 2012.


Here is a link where you can download my script : ExportKnowledgeArticleFromAMP.ps1



I'll publish a page on my blog >>>> HERE <<<< with all the product knowledge for all the provided MP I've in my environment.


This posting is provided "AS IS" with no warranties.

Friday, March 8, 2013

[OpsMgr 2007 R2][OpsMgr 2012] Powershell script to list all references stored in all unsealed Management Pack

I'm actually doing some clean up in our 2007 R2 environment to be sure that all management pack are OK before importing them in our new SCOM 2012  environment.



As you know, best practices is to create one override MP by MP you want to tune. One of the tasks we wanted to do is to ensure that all overrides stored in unsealed MPs are corresponding to the sealed assocaited MP.

Listing all references of unsealed MPs is a good help to identify what unsealed MP has a reference on a MP (and also override) that should not be referenced !

Download the file :

Or create a file : ListReferenceUnsealedMPs.ps1

  1. param([string]$Path)
  2. $Exportfile = [string]$Path + "\ListAllReferencesForNonSealedMPs.csv"
  3. $Exportfile
  4. # SCOM 2007R2
  5. $mps = get-managementpack | where-object {$_.Sealed -eq $false}
  6. # SCOM 2012
  7. # $mps = Get-SCOMManagementPack | where-object {$_.Sealed -eq $false}
  8. "Management Pack Name;Reference Name;Reference Key Token;Reference Version;Reference ID;Reference Version ID" >> $Exportfile
  9. Foreach ($mp in $mps)
  10.  {
  11.  $References = $mp.References
  12.  foreach ($Ref in $References)
  13.   {
  14.   $mp.Name + ";" + $Ref.name + ";" + $Ref.KeyToken + ";" + $Ref.Version  + ";" + $Ref.Id + ";" + $Ref.VersionId >> $Exportfile
  15.   }
  16.  }
 Then you can use the ListReferenceUnsealedMPs.ps1 "C:\temp" command line in a powershell connected to your SCOM (don't forget to comment line 5 + un-comment line 7 for using in 2012).

This will create a c:\Temp\ListAllReferencesForNonSealedMPs.csv that contains all References by unsealed MP.

Openning the .csv file with excel will give you :


 Enjoy !

This posting is provided "AS IS" with no warranties.

Thursday, January 31, 2013

[OpsMgr 2012][Powershell] Get Alerts for all specified SCOM MP using powershell in Operations Manager 2012


Here is a short powershell script I've just updated to be usable in operations Manager 2012 since cmdlet have been renamed. This script will help you to retrieve alerts from a specified SCOM MP using powershell.
 

Note that previous version dedicated to Operations Manager 2007 R2 is here
  
Here is the new script :

  1. $mp = Get-SCOMManagementPack -name 'MPName'
  2. # Criteria       : All alerts, raw and processed descriptions.
  3. # Output to      : File (c:\temp\output\Alerts-all.csv)
  4. # Fields Selected: Lots.
  5. # Output Format  : CSV
  6. # Notes          : Need more work on this.
  7. $alerts_csv = "C:\MPName.csv";
  8. write-host "Exporting all alerts to csv: ",$alerts_csv;
  9. Get-SCOMAlert | select-object @{Name = '%'; expression ={$_.MonitoringObjectDisplayName}},Severity, Name, ResolutionState, RepeatCount,@{Name = 'Instances'; expression ={$_.RepeatCount+1}},@{Name = 'Created'; expression =
  10. {$_.TimeRaised.ToLocalTime()}},@{Name = 'Description (Processed)';Expression = {$_.Description  -replace "`n"," " -replace " "," "}},MonitoringObjectFullName, IsMonitorAlert,Id,MonitoringRuleId,MonitoringClassId,Description | sort Name | export-csv $alerts_csv -noTypeInformation;
 Replace MPName in red by the your MP Name. Il will export all alerts in a CSV file.

This posting is provided "AS IS" with no warranties.

Wednesday, November 28, 2012

[Powershell] Creating your own Windows Powershell Profile - Part 3

---------- Go to Part 1, Part 2 ----------


  • Function to Export Unsealed Management Pack from a specified management group in a specified folder

  • 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

    1. Function ExportMP ([string]$RMS, [string]$PATH)
    2. {
    3. switch ($RMS.toupper()) {
    4.  "PROD" {$RMS1="PRODRMS.Mydomain.com"}
    5.  "DEV" {$RMS1="DEVRMS.Mydomain.com"}
    6.  "PREPROD" {$RMS1="PREPRODRMS.Mydomain.com"}
    7.  default {Write-Host "RMS  - $RMS - not valid" -ForegroundColor red ;sleep 3;exit}
    8.  }
    9. if ( (Get-pssnapin | where {$_.Name -eq "Microsoft.EnterpriseManagement.OperationsManager.Client" }).Name -ne "Microsoft.EnterpriseManagement.OperationsManager.Client" )
    10.   {
    11.   add-pssnapin "Microsoft.EnterpriseManagement.OperationsManager.Client" -ErrorVariable errSnapin;
    12.   $creds = Get-Credential("MyDomain\MyAccount");
    13.   $connection = New-ManagementGroupConnection -ConnectionString: $RMS1 -Credential: $creds
    14.   Set-Location "OperationsManagerMonitoring::" | Out-Null;}
    15. If ($PATH -eq "")
    16.  {
    17.  $a = Get-Date -format d
    18.  $a=$a.Replace('/', '-')
    19.  $RMS = $RMS.toupper()
    20.  $PATH = "C:\Temp\UnsealedMPs-"+$RMS+"-"+$a
    21.  $TestPath = Test-Path $PATH
    22.  if ( $TestPath -eq $False) {
    23.   "Create a new backup folder: " + $PATH
    24.   New-Item -ItemType directory -Path $PATH
    25.   $Continue= "Yes"
    26.   }
    27.  else {
    28.  Write-Host "Path  - $PATH - already exist.
    29.   
    30.  " -ForegroundColor green
    31. $Question = Read-Host "Do you want to re-use it [Y/N] ?"
    32.  Switch ($Question.toupper()){
    33.   "Y" {$Continue= "Yes"}
    34.   "N" {$Continue= "No"}
    35.   default {$Continue= "No"}
    36.   }
    37.  }
    38.  }
    39. Else { Write-Host "Folder doesn't exist - create the folder: $PATH" -ForegroundColor green
    40.   New-Item -ItemType directory -Path $PATH
    41.   $Continue= "Yes"}
    42. if ($Continue -eq "Yes") { 
    43.  $mps = get-managementpack | where-object {$_.Sealed -eq $false}
    44.  foreach ($mp in $mps)
    45.   {
    46.   export-managementpack -managementpack $mp -path $PATH
    47.   }
    48.  }
    49. Else { Write-Host "No export Done" -BackgroundColor red -ForegroundColor yellow}
    50. }

    This posting is provided "AS IS" with no warranties.

    Tuesday, November 27, 2012

    [OpsMgr 2012] Exporting Sealed and Non Sealed Management Packs using powershell script



    As per in OpsMgr 2007, exporting sealed MPs in XML format in Operations Manager 2012 is very easy. You just add to run the the following command in the Operations Manager Shell :


    Get-SCManagementPack | Export-SCManagementPack -Path “D:\Temps\ExportSealedMP”


    For the non-sealed MPs, here is a short script you should save in a ExportNonSealedMP.PS1 file (this one is working with OpsMgr 2007 and 2012):

    1. param ($MGTServerName)
    2. add-pssnapin “Microsoft.EnterpriseManagement.OperationsManager.Client”;
    3. set-location “OperationsManagerMonitoring::”;
    4. new-managementGroupConnection -ConnectionString:$MGTServerName;
    5. set-location $MGTServerName;
    6. $mps = get-managementpack | where-object {$_.Sealed -eq $false}
    7. foreach ($mp in $mps)
    8. {
    9. export-managementpack -managementpack $mp -path “D:\Temp\Backup”
    10. }
     Then you can execute the following command line :

     ExportNonSealedMP.PS1 -MGTServerName YourServerName

    This posting is provided "AS IS" with no warranties.

    Thursday, June 14, 2012

    [Orchestrator 2012] Tools to use for manipulating export file (ois_export files)

    Ryan Andorfer has published a new tool  for manipulating export of Orchestrator Runbooks (ois_export file).

    SanitizeExport.exe features : 
      • Turn off / on Generic logging on all exported runbooks
      • Turn off / on Object Specific logging on all exported runbooks
      • Remove all non-referenced Global Variables, Configs, Computer Groups, Schedules and Counters
    To download this tool, follow the link Download SanitizeExport

    This posting is provided "AS IS" with no warranties.

    Thursday, May 24, 2012

    [OpsMgr 2007R2] Get member of all SCOM groups and export result in CSV files - Powershell script

    Here is a script that will help you to create a CSV file per SCOM group. Each CSV file will have the name of the SCOM group and will contain this information
    • Name
    • Path
    • DisplayName
    • FullName
    • IsManaged
    • LastModified
    • HealthState
    • StateLastModified
    • IsAvailable
    • AvailabilityLastModified
    • InMaintenanceMode
    • MaintenanceModeLastModified
    • MonitoringClassIds
    • LeastDerivedNonAbstractMonitoringClassId
    • Id
    • ManagementGroup
    • ManagementGroupId
    Empty group does not create a CSV file.

    1. function GetDisplayName($object){
    2.      $displayName = [System.String]::Empty
    3.      if(($object.DisplayName -eq $null) -or ($object.DisplayName.Length -eq 0)){
    4.            $displayName = $object.Name;
    5.      }
    6.      else {
    7.            $displayName = $object.DisplayName;
    8.      }
    9.      $displayName;
    10. }
    11. $mg = (Get-ManagementGroupConnection).ManagementGroup
    12. $groups = $mg.GetRootPartialMonitoringObjectGroups() | sort DisplayName
    13. foreach($group in $groups) {
    14.      Write-Host
    15.      Write-Host $group.DisplayName
    16.      $groupMembers = $group.GetRelatedPartialMonitoringObjects([Microsoft.EnterpriseManagement.Common.TraversalDepth]::OneLevel);
    17.      if($groupMembers.Count -eq 0) {
    18.            Write-Host "The group is empty"
    19.      }
    20.      else {
    21.             $groupMembers | Select-Object DisplayName,Path,@{name="Type";expression={foreach-object {GetDisplayName $_.GetLeastDerivedNonAbstractMonitoringClass()}}} | sort DisplayName | ft
    22.             $FileName = $group.DisplayName
    23.             $FileName += ".csv"
    24.             $OutPath = $FileName
    25.             $groupMembers | Export-Csv -Path $OutPath -NoTypeInformation
    26.      }
    27. Write-Host
    28. }

    How to use it :
    - First connect to you management group
    1. add-pssnapin "Microsoft.EnterpriseManagement.OperationsManager.Client";
    2. set-location "OperationsManagerMonitoring::";
    3. new-managementGroupConnection -ConnectionString:MyRMS.MyDomain -Credential (get-credential "Domain\Account");
     - secondly, set your location where you want to store the created CVS files :
    1. set-location c:\temp
    - Then execute the script :



    Result will be :
     And you will retrieve your files in the location you have set - in my case :



    This posting is provided "AS IS" with no warranties.

    Friday, February 24, 2012

    [OpsMgr 2007] Export all performances rules by using a PowerShell Script

    Here is a new PowerShell script usefull to list in a CSV file all performance rules in your management group - The script use a get-rules with a criteria "Category='PerformanceCollection'". Be carefull also when you developp some MPs to well categorize the rules.

    $perf_collection_rules = get-rule -criteria:"Category='PerformanceCollection'"

    4 functions are needed for filtering the result :

    function GetPerfCounterName ([String] $configuration) {
              $config = [xml] ("<config>" + $configuration + "</config>")
              return ($config.Config.ObjectName + "\" + $config.Config.CounterName)
    }


    function GetFrequency ([String] $configuration) {
              $config = [xml] ("<config>" + $configuration + "</config>")
              $frequency = $config.Config.Frequency;
              if($frequency -eq $null) {
                        $frequency = $config.Config.IntervalSeconds;
              }
              return ($frequency)
    }


    function GetDisplayName($performanceRule) {
              if($performanceRule.DisplayName -eq $null) {
                          return ($performanceRule.Name);
               }
              else {
                          return ($performanceRule.DisplayName);
               }
    }


    function GetWriteActionNames($performanceRule) {
              $writeActions = "";
              foreach($writeAction in $performanceRule.WriteActionCollection) {
                         $writeActions += " " + $writeAction.Name;
               }
               return ($writeActions);
    }

    You are now able to export the $perf_collection_rules in a CSV file by getting the type, the rule display name, the counter name, the frequency and the write actions.

    $perf_collection_rules | select-object @{name="Type";expression={foreach-object {(Get-MonitoringClass -id:$_.Target.Id).DisplayName}}},@{name="RuleDisplayName";expression={foreach-object {GetDisplayName $_}}} ,@{name="CounterName";expression={foreach-object {GetPerfCounterName $_.DataSourceCollection[0].Configuration}}},@{name="Frequency";expression={foreach-object {GetFrequency $_.DataSourceCollection[0].Configuration}}},@{name="WriteActions";expression={foreach-object {GetWriteActionNames $_}}}  | sort Type,RuleDisplayName,CounterName | export-csv "C:\perf_collection_rules.csv" -noTypeInformation


     I don't remember having developped this script by myself - perhaps it was not mine. By the way, this is very usefull.

    >>>>>>>>>> Get the PS1 file Here <<<<<<<<<<

    This posting is provided "AS IS" with no warranties.

    Friday, January 13, 2012

    [OpsMgr 2007 R2][Powershell] Get Alerts for all specified SCOM MP using powershell in Operation Manager 2007 R2

    Here is a short powershell script you can use to retrieve alerts froml a specified SCOM MP using powershell.

    1. $mp = Get-ManagementPack -name 'MPName'
    2. # Criteria       : All alerts, raw and processed descriptions.
    3. # Output to      : File (c:\temp\output\Alerts-all.csv)
    4. # Fields Selected: Lots.
    5. # Output Format  : CSV
    6. # Notes          : Need more work on this.
    7. $alerts_csv = "C:\MPName.csv";
    8. write-host "Exporting all alerts to csv: ",$alerts_csv;
    9. Get-Alert | select-object @{Name = '%'; expression ={$_.MonitoringObjectDisplayName}},Severity, Name, ResolutionState, RepeatCount,@{Name = 'Instances'; expression ={$_.RepeatCount+1}},@{Name = 'Created'; expression =
    10. {$_.TimeRaised.ToLocalTime()}},@{Name = 'Description (Processed)';Expression = {$_.Description  -replace "`n"," " -replace " "," "}},MonitoringObjectFullName, IsMonitorAlert,Id,MonitoringRuleId,MonitoringClassId,Description | sort Name | export-csv $alerts_csv -noTypeInformation;
     Replace MPName in red by the your MP Name. Il will export all alerts in a CSV file.



    An updated version for Operations Manager 2012 has been published >>>>>>>>>> here <<<<<<<<<<

    This posting is provided "AS IS" with no warranties.

    [Powershell] Get Rules information or Monitors information for all MP in SCOM

    Here is a short powershell command to list in a .CSV file Rules information for all SCOM MP using a powershell script :

    Get Rules Informations :
    1. get-rule | select-object @{Name="MP";Expression={ foreach-object {$_.GetManagementPack().DisplayName }}}, @{Name="MP Version";Expression={ foreach-object {$_.GetManagementPack().Version }}}, Name, DisplayName, XmlTag, Enabled, Category |
      sort-object -property MP | export-csv "C:\Allrules-MyMgtGroupName.csv"
    Get Monitors Informations :
    1. get-monitor | select-object @{Name="MP";Expression={ foreach-object {$_.GetManagementPack().DisplayName }}}, @{Name="MP Version";Expression={ foreach-object {$_.GetManagementPack().Version }}}, Name, DisplayName, XmlTag, Enabled, Category, Configuration  | Sort-object -property MP | export-csv "C:\AllMonitors-MyMgtGroupName.csv"
     With the same way, you can imagine listing all classes for all MP : see http://tetris38.blogspot.com/2012/01/powershell-get-classes-information-for.html

    This posting is provided "AS IS" with no warranties.

    [Powershell] Get classes information for all MP in SCOM

    Here is a short powershell command to list in a .CSV file all classes information for all SCOM MP using a powershell script :

    1. get-monitoringclass | select-object @{Name="MP";Expression={ foreach-object {$_.GetManagementPack().DisplayName }}}, @{Name="MP Version";Expression={ foreach-object {$_.GetManagementPack().Version }}}, Name, DisplayName, Id, Abstract, Accessibility, Base, Comment, Description, Hosted, LanguageCode, LastModified, ManagementGroup, ManagementGroupId, PropertyCollection, Singleton, Status, TimeAdded, XmlTag  |  sort-object -property MP | export-csv "C:\AllClasses-MyMgtGroupName.csv"

    In my case this is usefull to determine what are the Name + ID for all classes for a specific MP to configure monitoring instructions in a tool.

    With the same way you can export Rules and Monitors information for all your MP : http://tetris38.blogspot.com/2012/01/powershell-get-rules-information-or.html

    This posting is provided "AS IS" with no warranties.