Wednesday, February 5, 2014

Backup Lync 2010 Remotely from Orchestrator

Backup Lync 2010 Remotely from Orchestrator


Prerequisites: Lync 2010 Cmdlets installed on Orchestrator Server.
Files needed: DBImpExp.exe


So I needed a way to backup Lync 2010 configuration. Since I have snap shots of the VM I can have a restored Lync environment up in a few hours. But all of my configuration changes will be missing.

This is where Orchestrator Runbook comes into play.

Simple layout
Monitor Date Time
Check Schedule
Export DBImpExp
Sleep (Note Runbook is faster than my script so I need to slow it down)
Script-Export


Now for the Code:

Export DBImpExp:
cd \
cd "C:\Program Files\Common Files\Microsoft Lync Server 2010\Support"
start-process dbimpexp.bat


dbimpexp.bat


@ECHO OFF
REM CD "C:\Program Files\Common Files\Microsoft Lync Server 2010\Support"
dbimpexp.exe /hrxmlfile:"E:\masterbackup\Lync-Backups\BackupFiles\DBImpExp.xml" /sqlserver:nlkvsqldba04\lync_prod
 

Sleep:
PING 127.0.0.1 -n 50 (I do a simple ping, always works!)

Export DBImpExp: once you get all of this data I like to package it into a zip file.


############# NEW-ZIP ############################
function New-Zip
{
  param(
 [Parameter(Mandatory=$true,
  Position=0,
  ValueFromPipeline=$true)]
 [String]
 $Path,
 
 [Switch]
 $PassThru,
 
 [Switch]
 $Force
 )
 process {

   if (Test-Path $path)
   {
    if (-not $Force) { 
     return
    }
   }
   Set-Content $path ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
   $item = Get-Item $path
   $item.IsReadOnly = $false 
   if ($passThru) { $item } 
  
 }
}

Here is the Function to Copy to Zip file

########## Copy-ToZip ###########################
function Copy-ToZip
{
param(
  [Parameter(Mandatory=$true,
    Position=0,
    ValueFromPipelineByPropertyName=$true)]
  [Alias('FullName')]
  [String]$File,

  [Parameter(Mandatory=$true,Position=1)]
  [String]$ZipFile,
  
  [Switch]$HideProgress,

  [Switch]$Force
  )
  begin {

      $ShellApplication = New-Object -ComObject Shell.Application
      if (-not (Test-Path $ZipFile)) {
        New-Zip $ZipFile
      }
      $Path = Resolve-Path $ZipFile
      $ZipPackage =$ShellApplication.Namespace("$Path")
    
  }
  process {

      $RealFile = Get-Item $File
      if (-not $RealFile) { return }    
      if (-not $hideProgress) {
        $perc +=5 
        if ($perc -gt 100) { $perc = 0 } 
        Write-Progress "Copying to $ZipFile" $RealFile.FullName -PercentComplete $perc
      }
      $Flags = 0
      if ($force) {
        $flags = 16 -bor 1024 -bor 64 -bor 512
      } 
      Write-Verbose $realFile.Fullname
      $ZipPackage.CopyHere($realFile.Fullname, $flags)
      Start-Sleep -Milliseconds 500
    
  }
}
Here is where I move the XML Files into the Zip file
I also call 4 other Lync Cmdlets
export-csconfiguration
export-cslisconfiguration
Get-CSVoicePolicy
Get-CSDialPlan

############ Loads funcion to Zip up XML files #############################

# Loads funcion to Zip up XML files
##		This script will purge old files, right now it is set for 10 days

$Now = Get-Date
$Days = "10"
$TargetFolder = "E:\masterbackup\Lync-Backups\BackupFiles\"
$Extension = "*.zip"
$LastWrite = $Now.AddDays(-$Days)
$Files = Get-Childitem $TargetFolder -Include $Extension -Recurse | Where {$_.LastWriteTime -le "$LastWrite"}
foreach ($File in $Files)
	    {
	    if ($File -ne $NULL)
	        {
	        Remove-Item $File.FullName | out-null
	        }
	    else
	        {
	        }
	    }
##		Create two Zip Files for backups
$filename = "E:\masterbackup\Lync-Backups\BackupFiles\{0:yyyy.MM.dd-HH.mm}-CSconfig.zip" -f (Get-Date)
$filename1 = "E:\masterbackup\Lync-Backups\BackupFiles\{0:yyyy.MM.dd-HH.mm}-LISconfig.zip" -f (Get-Date)
$filename2 = "E:\masterbackup\Lync-Backups\BackupFiles\{0:yyyy.MM.dd-HH.mm}-Rgsconfig.zip" -f (Get-Date)
$filename3 = "E:\masterbackup\Lync-Backups\BackupFiles\{0:yyyy.MM.dd-HH.mm}-CS.zip" -f (Get-Date)
##		Commands Run the Export Features
export-csconfiguration -Filename $filename -Force:$True
export-cslisconfiguration -Filename $filename1
#Export-CsRgsConfiguration  -Filename $filename2
Get-CSVoicePolicy | export-clixml –path E:\masterbackup\Lync-Backups\BackupFiles\VoicePolicy.xml
Get-CSDialPlan | export-clixml –path E:\masterbackup\Lync-Backups\BackupFiles\Dialplan.xml



##		Change Directories
Cd \
Cd \
cd E:
cd E:\masterbackup\Lync-Backups\BackupFiles
##		Create Zip file to move XML's
new-zip $filename3
PING 127.0.0.1 -n 10
dir .\DBImpExp.xml | copy-toZip -zipfile $filename3
PING 127.0.0.1 -n 10
dir .\VoicePolicy.xml | copy-toZip -zipfile $filename3
PING 127.0.0.1 -n 5
dir .\Dialplan.xml | copy-toZip -zipfile $filename3
PING 127.0.0.1 -n 5
Del *.xml




When the Runbook has completed you should have several Zip files you Configurations files.








Monday, January 13, 2014

Nagios & Ntop

Old Project:
Nagios Monitoring:


Below is a listing of Switch\Routers\AP's.
SNMP Traps Send status of devices



Diagram of how each device is connected to core Data Center.


Using MRTG you can chart usage.



 NTOP

network traffic probe, this was monitoring traffic on the MPLS between sites


With the monitoring you can filter bases on Port Traffic




Wednesday, January 8, 2014

DNS Failover Project

DNS Failover Project
Scope: One internet circuit fails dns records failover to back up circuit.
Technology IP anycast
Company DNS Made Easy

Summary;

Moved name servers for Contoso to DNS Made Easy. Configured DNS entries for failover between to IP Addresses.

Screenshot of DNS Failover Configuration. (Note company info has been changed.)

Test:
When Location 1 fails the following email is sent:
Notification: System is DOWN
IP: 8.8.8.8
System Desc: Test
Port: 80
Protocol: HTTP
2013-12-28 04:39:15.177 UTC
Previously failed: 7 times.
ID: 12124184
When the Location is has been restored the following email is sent:

Notification: System is UP
IP: 8.8.8.8
System Desc: Test
Port: 80
Protocol: HTTP
2013-12-28 04:39:15.177 UTC
Previously failed: 7 times.
ID: 12124184




Conclusion:
This Solution seems to be working fine for us, only issue we have seen is when the internet circuit flaps. To mitigate this we log into Easy DNS and disable the failover and disable the circuit on the firewall.

This scenario has only effected our production environment once since go live.






Friday, December 20, 2013

Set ACL on a folder

"Set ACL"
One of my Runbooks I create a home drive based on the location of the user and their name. I also set the ACL so they are the only ones with rights.

Screen shot of Runbook:




The DriveMap-Var build the drive mapping based on the location of the user. The VAR is taken from in Initialize Data. In my case
$locNLK ="\\nlkvflesvr04\NLK-Home"
$locBDU ="\\nlkvflesvr02\BDU-Home"
If ($location -eq "NLK"){
$loc = $locNLK
}


Once that is defined, I build the share name:

$homeDrive = "\`d.T.~Ed/{30B8BA77-3261-41F6-8EC5-F84511D45983}.loc\`d.T.~Ed/"
$username = "\`d.T.~Ed/{70D59E59-DB18-4D99-B7FE-FF591376E64C}.{F857D2AB-8976-40C1-B25A-6965985B8541}\`d.T.~Ed/"
$ShareName = "$homeDrive\$username"

I use the built in Create Folder in Orchestrator to create the users folder based on the $sharename.

Next I Set-ACL and the user is all set with a Home Drive.

Script: Set-ACL
$acl = get-acl "\`d.T.~Ed/{0FFE6E93-2182-4081-B0B3-7C9DD2B1F871}.Folder\`d.T.~Ed/"
$UserACL = "SCHOLLE\\`d.T.~Ed/{70D59E59-DB18-4D99-B7FE-FF591376E64C}.{F857D2AB-8976-40C1-B25A-6965985B8541}\`d.T.~Ed/"
$arguments = "$UserACL","Modify", "3", "None", "Allow"
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $arguments
$acl.SetAccessRule($accessRule)
$acl | Set-Acl "\`d.T.~Ed/{0FFE6E93-2182-4081-B0B3-7C9DD2B1F871}.Folder\`d.T.~Ed/"

Thursday, December 19, 2013

On Battery Powershell Script


I have a laptop in a remote site that loses AC Power from time to time, I wrote the following script and added it to a schedule task to run every hour.

Main line of code is very simple:


Rest of the code is here, this is version 1, I plan on adding other monitoring.

$strComputer = "." 
$colItems = get-wmiobject -class "Win32_Battery" -namespace "root\CIMV2" -computername $strComputer 
$word1 = "Availability: "
$word2 = "Battery Recharge Time: "
$word3 = "Battery Status: "
$word4 = "Description: "
$word5 = "Estimated Charge Remaining: "
$word6 = "Estimated Run Time: "
$word7 = "Last Error Code: " 
$word8 = "Maximum Recharge Time: "
$word9 = "Status: " 
$word10 = "Time On Battery: " 
$word11 = "Time To Full Charge: " 
$br = "
" if ($colItems.Availability -eq "3") { foreach ($objItem in $colItems) { $Bat1 = $objItem.Availability $Bat2 = $objItem.BatteryRechargeTime $Bat3 = $objItem.BatteryStatus $Bat4 = $objItem.Description $Bat5 = $objItem.EstimatedChargeRemaining $Bat6 = $objItem.EstimatedRunTime $Bat7 = $objItem.LastErrorCode $Bat8 = $objItem.MaxRechargeTime $Bat9 = $objItem.Status $Bat10 = $objItem.TimeOnBattery $Bat11 = $objItem.TimeToFullCharge }} else {write-host "NO"} $word1 + $Bat1 + $br | out-file c:\temp\battery.txt $word2 + $Bat2 + $br | out-file c:\temp\battery.txt -Append $word3 + $Bat3 + $br | out-file c:\temp\battery.txt -Append $word4 + $Bat4 + $br | out-file c:\temp\battery.txt -Append $word5 + $Bat5 + $br | out-file c:\temp\battery.txt -Append $word6 + $Bat6 + $br | out-file c:\temp\battery.txt -Append $word7 + $Bat7 + $br | out-file c:\temp\battery.txt -Append $word8 + $Bat8 + $br | out-file c:\temp\battery.txt -Append $word9 + $Bat9 + $br | out-file c:\temp\battery.txt -Append $word10 + $Bat10 + $br | out-file c:\temp\battery.txt -Append $word11 + $Bat11 + $br | out-file c:\temp\battery.txt -Append Del c:\temp\battery.htm Rename-Item C:\temp\battery.txt battery.htm $EmailBody1= get-content "c:\temp\battery.htm" $SmtpClient = new-object system.net.mail.smtpClient $MailMessage = New-Object system.net.mail.mailmessage $SmtpClient.Host = "MBX01" $mailmessage.IsBodyHTML = $true $mailmessage.from = ("stein@olle.com") $mailmessage.To.add("stein@olle.com") $mailmessage.Subject = "Test HTML" $mailmessage.Body = $EmailBody1 $mailmessage.Headers.Add("message-id", "<3BD50098E401463AA228377848493927-1>") $smtpclient.Send($mailmessage)



Tuesday, December 17, 2013

System Center Orchestrator

Below is a layout for Notifying people based on location.



Check out the Powershell code here
                                https://github.com/stein97/Orchestrator/blob/master/notify.ps1                                                 

Thursday, September 10, 2009

Exchange Certificates

Need to Renew your Exchange Certificates?

Fast tutorial:

New-ExchangeCertificate -GenerateRequest:$true -Path c:\Exchange.req -DomainName sch-ca01,sch-ca02 -PrivateKeyExportable:$true -FriendlyName "Exchange Certificate" -IncludeAcceptedDomains:$false -Force:$true

Now Import it:
Import-ExchangeCertificate c:\exchange.cer

Now Enable it:
Enable-ExchangeCertificate -Thumbprint DFFA81EFC7650C536BD435D4EB406C0F8FE7B471 -Services "IMAP, POP, UM, IIS, SMTP"