2017年8月28日 星期一

Programmatically remove a management pack with Dependencies

Programmatically remove a management pack with Dependencies

When a management pack is deleted from the administration pane UI, it can become very time consuming to recursively track down and delete all dependent management packs before deleting the originally intended management pack. You can use the following script to cascade delete a management pack and all its dependencies.
To run the script, follow these steps:
  1. Open the Operations Manager Command Shell prompt in Administrator mode.
  2. Run the attached script from the directory where you have saved it in the disk. For example:
    • .\RecursiveRemove.ps1 <ID or System Name of the MP>
    • .\RecursiveRemove.ps1 Microsoft.SQLServer.2014.Discovery
    Note You can see the ID or System Name of the MP that you want to uninstall by selecting it in Installed Management Packs view. Then click Properties in the Actions Pane. Then copy the content in ID: text box in General tab.
# The sample scripts are not supported under any Microsoft standard support 
# program or service. The sample scripts are provided AS IS without warranty 
# of any kind. Microsoft further disclaims all implied warranties including, 
# without limitation, any implied warranties of merchantability or of fitness
# for a particular purpose. The entire risk arising out of the use or 
# performance of the sample scripts and documentation remains with you. In no
# event shall Microsoft, its authors, or anyone else involved in the creation,
# production, or delivery of the scripts be liable for any damages whatsoever
# (including, without limitation, damages for loss of business profits,
# business interruption, loss of business information, or other pecuniary
# loss) arising out of the use of or inability to use the sample scripts or
# documentation, even if Microsoft has been advised of the possibility of 
# such damages.
#
#
# PowerShell script to automagically remove an MP and its dependencies.
#
# Original Author :      Christopher Crammond
# Modified By   :      Chandra Bose
# Date Created   : April 24th, 2012
# Date Modified  :  Januray 18th, 2016
#
# Version  :       0.0.2
#

# Needed for SCOM SDK
$ipProperties = [System.Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties()
$rootMS = "{0}.{1}" -f $ipProperties.HostName, $ipProperties.DomainName


#######################################################################
#
# Helper method that will remove the list of given Management Packs.
#
function RemoveMPsHelper 
{param($mpList)
  foreach ($mp in $mpList)
  {
 $recursiveListOfManagementPacksToRemove = Get-SCOMManagementPack -Name $mp.Name -Recurse
 if ($recursiveListOfManagementPacksToRemove.Count -gt 1)
 {
  Echo "`r`n"
  Echo "Following dependent management packs has to be deleted before deleting $($mp.Name)..."

  $recursiveListOfManagementPacksToRemove | format-table name
  RemoveMPsHelper $recursiveListOfManagementPacksToRemove
 }
 else
 {
  $mpPresent = Get-ManagementPack -Name $mp.Name
        $Error.Clear()
        if ($mpPresent -eq $null)
        {
            # If the MP wasn’t found, we skip the uninstallation of it.
            Echo "    $mp has already been uninstalled"
        }
  else
  {
   Echo "    * Uninstalling $mp "
   Uninstall-ManagementPack -managementpack $mp
  }
 }
  }
}

#######################################################################
#
# Remove 'all' of the JEE MPs as well as MPs that are dependent on them.
# The remove is done by finding the base MP (Microsoft.JEE.Library) and finding
# all MPs that depend on it.  This list will be presented to the user prompting
# if the user wants to continue and removing the list of presented MPs
#
function RemoveMPs
{param($mp)

  $listOfManagementPacksToRemove = Get-SCOMManagementPack -Name $mp -Recurse
  $listOfManagementPacksToRemove | format-table name

  $title = "Uninstall Management Packs"
  $message = "Do you want to uninstall the above $($listOfManagementPacksToRemove.Count) management packs and its dependent management packs"

  $yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", "Uninstall selected Management Packs."
  $no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", "Do not remove Management Packs."
  $options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)

  $result = $host.ui.PromptForChoice($title, $message, $options, 0) 

  switch ($result)
  {
        0 {RemoveMPsHelper $listOfManagementPacksToRemove}
        1 {"Exiting without removing any management packs"}
  }
}

#######################################################################
# Begin Script functionality
#
if ($args.Count -ne 1)
{
  Echo "Improper command line arguments"
  Echo ""
  Echo "Specify a command line argument to either import or export MPs"
  exit 1
}
else
{
  $firstArg = $args[0]

  add-pssnapin "Microsoft.EnterpriseManagement.OperationsManager.Client";
  $cwd = get-location
  set-location "OperationsManagerMonitoring::";
  $mgConnection = new-managementGroupConnection -ConnectionString:$rootMS;

  RemoveMPs $firstArg

  set-location $cwd
  remove-pssnapin "Microsoft.EnterpriseManagement.OperationsManager.Client";  
}

System_CAPS_noteNote
If any other imported management packs depend on the management pack you are trying to remove, the Dependent Management Packs error message displays. You must remove the dependent management packs before you can continue.

For
https://technet.microsoft.com/en-us/library/hh230746(v=sc.12).aspx

2017年8月3日 星期四

SCOM 2016,Unable to resolve the user xxx associated with the user role. Error code 1332

Problem
===========
Unable to resolve the user xxx associated with the user role. Error code 1332

Cause
=========
Normally – when you have a trust with a remote account domain, and you want to add users from the rote domain to SCOM, things go perfectly.
However, if the user account in the remote domain uses a different UPN name than the SAM account name – the SCOM UI block’s it.
  
Solution
===========
Use SCOM PowerShell to add these users to the role:

$Role = Get-SCOMUserRole -Name "MSFT TEST"
$Role | Set-SCOMUserRole -User ($Role.Users + "MSFT\jimmytest")


2017年7月26日 星期三

After applying update KB4025336 to our WSUS servers clients are no longer able to communicate with WSUS.

Cause
========
the virtual directories were throwing internal server error 500's for the WSUS


Analysis
=========

2017-07-26    13:41:01:572 1048   20d8   PT        WARNING: GetCookie_WithRecovery failed : 0x80244008
2017-07-26    13:41:01:572 1048   20d8   PT        WARNING: RefreshCookie failed: 0x80244008
2017-07-26    13:41:01:572 1048   20d8   PT        WARNING: RefreshPTState failed: 0x80244008
2017-07-26    13:41:01:572 1048   20d8   PT        WARNING: PTError: 0x80244008
2017-07-26    13:41:01:572 1048   20d8   Report           WARNING: Reporter failed to upload events with hr = 80244008.

Action Plan
=============

1. Open the elevated command prompt, and cd to the directory: C:\Program Files\Update Services\Tools;
2. Run the command: wsusutil.exe usecustomwebsite true,  to change the 80 port usage to 8530;
3. Run the command: wsusutil.exe usecustomwebsite false,  to change the 8530 port usage to 80 again.

2017年5月24日 星期三

Windows 10 Shows Windows Vista on Windows Server 2008R2 WSUS

請在WSUSDB裡面執行以下的語法,會將所有的Windows 10 Client MachineOS Description 修改成Windows 10
UPDATE [SUSDB].[dbo].[tbComputerTargetDetail]
SET [OSDescription] = 'Windows 10'
WHERE [OSMajorVersion] = '10'
AND [OSMinorVersion] = '0'
AND [OldProductType] = '1'

AND ([OSDescription] <> 'Windows 10' or [OSDescription] IS NULL) 

2017年5月11日 星期四

Error 2912 (0x80070534) happened when a host was added to VMM.

Cause
=========
The error occurred after the AD service account was renamed, and then the account mismatches with that in VMM registry.

Resolution
==============
1. Login to VMM server machine, and check the below registry:

     HKLM\Software\Microsoft\Microsoft System Center Virtual Machine manager Server\Setup\VMMerviceAccount

Please make note of the value.


2. Compare it with the account in AD side, and make sure they are matching.