Pages

torsdag 30. mai 2013

DPM: Run Weekly ExpressFull with data integrity check

It is important that your backup is consistent with the source. When backing up SQL server databases, you should to a periodic data integrity check. I like to do this on a weekly schedule. I use a PowerShell script for this and schedule it with Task Scheduler. The script looks like this:
 Param(  
  [string]$DPMServer  
 )  
 # Import the DPM PowerShell module  
 $installPath = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft Data Protection Manager\Setup" "UIInstallPath").UIInstallPath  
 $dpmModuleFullPath = $installPath + "Modules\DataProtectionManager\DataProtectionManager.psd1"  
 Import-Module $dpmModuleFullPath  
 # Use local host if DPM Server is not specified  
 If(!$DPMServer) {$DPMServer = [System.Net.Dns]::GetHostByName(($env:computerName)).HostName}  
 # Failed to connect To DPM server  
 If (!(Connect-DPMServer $DPMServer)) {Exit 1}  
 $pglist = Get-DPMProtectionGroup -DPMServerName $DPMServer | Where-Object {$_.IsPGDisconnected -eq $False}  
 # No Protection group found  
 If(!$pglist) {Exit 2}  
 ForEach ($pg in $pglist) {  
  $pgname = $pg.FriendlyName  
  # Get all datasources with active protection and of type starting with SQL Server  
  $dslist = Get-DPMDatasource -ProtectionGroup $pg | Where-Object {$_.Protected -eq $True -and $_.Type.Name -like 'SQL Server*'}  
  If($dslist) {   
   ForEach ($ds in $dslist) {  
    $dstype = $ds.Type.Name  
    $dsname = $ds.Name  
    # Create Recovery Point Job ExpressFull with dataintegritycheck  
    New-DPMRecoveryPoint -Datasource $ds -Disk -BackupType ExpressFull -WithDataIntegrityCheck  
   }  
  }  
 }  
 Exit 0  

To schedule this, say to run at 02:00 every Saturday of every week, use this command on your DPM server:
schtasks.exe /Create /F /TN "DPM Start SQL RP With CC" /SC "WEEKLY" /RU "SYSTEM" /D SAT /ST 02:00 /TR "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noninteractive -nologo -file \"c:\scripts\StartSQLRPWithCC.ps1\""

mandag 20. mai 2013

OpsMgr: Show reports with hidden details

In Operations Manager we can schedule reports. But what if some sections of the report are hidden:


By clicking the plus sign we can expand the hidden details like this:


The problem starts when you want to schedule the report and, say, send it as a PDF file by e-mail. Obviously, we can not toggle the hidden part in a PDF file. So, can we make the hidden part visible by default? Yes we can... Here is how:

In a Browser, open the Reports folder (e.g. http://localhost/Reports), you should see something like this:


Switch to Details View and locate the report you would like to edit. The ODR - Instance Space report is in the ODR folder, and its name is Microsoft.SystemCenter.DataWarehouse.Report.Instance.Space.

Point at the name and then click the arrow to the right of the name and select Download:


After the file has been downloaded, open it in a text editor like Notepad. We want to find the Visibility sections and in particular, those with a ToggleItem section. Search for ToggleItem. In this particular report we will find this in two places:
 <Visibility><Hidden>=Parameters!Interactive.Value</Hidden><ToggleItem>textbox10</ToggleItem></Visibility>  
 <Visibility><Hidden>true</Hidden><ToggleItem>reportDescriptionTitle</ToggleItem></Visibility>  

Look at the value of Hidden. For textbox10, it is =Parameters!Interactive.Value. And for reportDescriptionTitle, it is true. We can change this to false if we would like it to be expanded by default. In this report I change the value of the first Hidden, =Parameters!Interactive.Value, to false (and I leave the other unchanged). Save the file with a new name, like ODR Instance Space.rdl (to avoid confusion with the original report).

Create a folder in the root (e.g. Modified Reports), then open the folder and select Upload File, Browse to the .rdl file and select OK:


PS! You should use a folder in the root. Many reports use relative paths to images (e.g. ../gradient_portrait.gif). If the report is not in a folder at the root, it will not find the image.

After the upload we need to verify the datasource, so we click the arrow to the right of the report name and select Manage.

Then we go to Data Sources and use Browse next to Select a shared data source. (PS! you can look at the original report to find the datasource name it uses). The Instance Space report use the Data Warehouse database, so choose the Data Warehouse Main data source in the root of Reporting Services, then press OK and Apply.

The report will now be available in Operations Manager Console under Authored Reports. When you Open and Run it you will notice that the details are expanded.

OpsMgr: Script Monitor: Verify that new file exist

Monitoring details


Using: Operations Manager 2012.
Agent: running Windows Server 2008 R2.
Objective: Monitor that file(s) not older than x hours, exist in specified folder or subfolders.
Method: VBScript using two state Script Monitor.
State: Trigger Critical state if no file newer than x hours exist.
Schedule: Run every 60 minutes.
Action to take: If Critical state, notify application owner, by e-mail.

Monitor characteristics

  • Monitor is disabled by default, use override to run on specified computer or group of Computers.
  • Monitor is in Critical state if script returns a status message of BAD
  • Monitor is in Healthy state if script returns a status message of GOOD
  • Arguments (2):
    • [string]FolderPath: Path to the folder we want to monitor
    • [string]Hours: Check for files newer than specified hours.
  • Properties (1):
    • [string]Result: GOOD or BAD

Script

 '======================================================================  
 ' NAME : fscheckthatnewfileexist.vbs
 ' AUTHOR : Reidar Johansen
 ' DATE : 5/20/2013
 ' COMMENT: Monitor that file(s) not older than x hours, exist in folder.
 ' Include subfolders. Trigger Critical state if no file newer than x hours exist.
 ' Used in a two-state monitor.
 '======================================================================
 Option Explicit  
 Dim oArgs, oAPI, sMonitorStatus, oBag  
 Dim oFso, sFolderPath, iHours  
 Set oArgs = Wscript.Arguments  
 Set oAPI = CreateObject("MOM.ScriptAPI")  
 If oArgs.Count < 2 Then  
  ' If called without argument, create event and quit  
  Call oAPI.LogScriptEvent(WScript.ScriptName,1001,2,"The script was called without correct arguments and was not executed.")  
  Wscript.Quit -1  
 End If  
 Set oFso = CreateObject("Scripting.FileSystemObject")  
 ' Capture path from arguments  
 sFolderPath = oArgs(0)  
 iHours = cInt(oArgs(1))  
 ' See if folder exists  
 If (oFso.FolderExists(sFolderPath)) Then  
  If TestFiles(sFolderPath) Then  
   sMonitorStatus = "GOOD"  
  Else  
   sMonitorStatus = "BAD"  
  End If  
 Else  
  ' If folder do not exist, create event and quit  
  Call oAPI.LogScriptEvent(WScript.ScriptName,1001,2,"The path " + sFolderPath + " was not found. Verify that it exists and check permissions.")  
  Wscript.Quit -1  
 End If  
 ' Create and submit the propertybag  
 Set oBag = oAPI.CreatePropertyBag()  
 Call oBag.AddValue("Result",sMonitorStatus)  
 Call oAPI.Return(oBag)  
 Function TestFiles (ByVal sFolder)  
  Dim oParentFld, oSubFld, cFiles, oFile  
  Set oParentFld = oFso.GetFolder (sFolder)  
  Set cFiles = oParentFld.Files  
  TestFiles = False  
  For Each oFile In cFiles  
   If DateDiff("h", oFile.DateCreated, Now, vbMonday, vbFirstFourDays) <= iHours Then  
    TestFiles = True  
    Exit Function  
   End If  
  Next  
  For Each oSubFld In oParentFld.SubFolders  
   ' Test all files in each subfolder  
   If TestFiles(oSubFld.Path) Then  
    TestFiles = True  
    Exit Function  
   End If  
  Next  
 End Function  

To create a Script Monitor in Operations Manager, take a look at my other blogg: OpsMgr: Script Monitor: Check that no files exist in subfolders.

DPM: Set location of WindowsImageBackup

DPM use Windows Server Backup (WSB) when you select to backup System State. WSB will create a folder called WindowsImageBackup on the root of the drive with the most free space (determined at the time of DPM agent installation). During backup all data will be in this folder and upon completion it will be transferred to the DPM server storage pool. To change the location of this folder:
  1. Open the file PSDataSourceConfig.xml (default location C:\Program Files\Microsoft Data Protection Manager\DPM\Datasources) on the computer you are backing up.
  2. Find the section for <FilesToProtect> (or search for WindowsImageBackup) and change drive letter to the drive you want WSB to use.
  3. Save the file, and do a Consistency Check against the System State data source.

tirsdag 14. mai 2013

Scripting: Delete user profile

If you ever need to delete a user profile on Windows Vista/7/2008, or above, using script, you can use wmic like this (replace red text with variables or whatever works for you):
 wmic /node:"computer.fqdn.name" path win32_UserProfile where LocalPath="c:\\users\\username" Delete

mandag 13. mai 2013

OpsMgr: Backup Unsealed management packs using PowerShell

To backup unsealed management packs use this command:
 Get-SCOMManagementPack | Where {$_.Sealed -eq $false} | Export-SCOMManagementPack -Path:"C:\Backup\MPs"

If using OpsMgr 2007 R2, use this:
 Get-ManagementPack | Where {$_.Sealed -eq $false} | Export-ManagementPack -Path:"C:\Backup\MPs"

søndag 5. mai 2013

OpsMgr: Turn Agent Proxy on by default

Many people working with Operations Manager like to turn on Agent Proxy for all agents. This can be a security risk if you import a management pack that exploit Agent Proxy. However, this is rare and many management packs require Agent Proxy anyway. Therefore, you should always take great care when importing management packs. Always research the developer to find out if he/she can be trusted. Also make shure to design-check every management pack before you use it in a production environment. If you do this, you should be safe.

To turn Agent Proxy on by default open up PowerShell (not Operations Manager Shell), then type in as follows (substitute SRVSCOMMS01 with the name of your management server):
 Add-PSSnapin "Microsoft.EnterpriseManagement.OperationsManager.Client"  
 New-ManagementGroupConnection -ConnectionString:SRVSCOMMS01
 Set-Location "OperationsManagerMonitoring::"  
 Set-DefaultSetting -Name HealthService\ProxyingEnabled -Value True  
You can also turn on Agent Proxy for installed agents by using Operations Manager Shell:
 Get-SCOMAgent | where {$_.ProxyingEnabled.Value -eq $False} | Enable-SCOMAgentProxy