Friday, February 20, 2015

Bulk Import Custom Contact Groups into Lync User accounts

Was looking for a way to Populate our Lync Room systems into end users Lync Contacts as a group rather than a bunch of individual accounts.  (More on Lync Room Systems here

Based on the PowerShell script found below, a new section was created for the Contact Groups.

Rather than repost the entire code, here's the updated sections...
For each Lync group that you want to create I would suggest creating new scripts.

For Individual account testing...

#Old version Enable for All users Disable for individual testing
$AllSipAddresses = Get-CsUser -Filter {Enabled -eq $True} | Select SipAddress | %{$_.SipAddress.Replace('sip:','')}

#GM Added - Enable for individual testing
#$AllSipAddresses = Get-CsUser -Identity -Filter {Enabled -eq $True} | Select SipAddress | %{$_.SipAddress.Replace('sip:','')}

# Common Contacts - Enable and populate this variable with a set of Lync contacts to distribute to all users instead of distributing all users to all users. Overrides $DontAddUsers.
#$CommonContacts = "",""

To add /verify the Group exists.
$AllContacts = @($SipAddressesToAdd | ?{$_ -ne $User})
    [xml]$XMLFile = Get-Content "$WorkingFolder\DocItemSet.xml"
    $XMLPart = $XMLFile.DocItemSet.DocItem | ?{$_.Name -like "urn:lcd:*"}
    $XMLNode = $XMLPart.Data.HomedResource.Contacts
$XMLNodeGroup = $XMLPart.Data.HomedResource.ContactGroups #GM
    $ExistingContacts = @($XMLNode.Contact | Select -ExpandProperty Buddy)
$ExistingContactGroups = @($XMLNodeGroup.ContactGroup | Select -ExpandProperty DisplayName) #GM
#GM Lync Rooms Contact Group Add
If($ExistingContactGroups -eq "THluYyBSb29tcw=="){
write-host "`r`nLync Room Group Exists. Nothing changed.`r`n"
write-host "`r`nLync Room Group will be added.`r`n"
[System.XML.XMLLinkedNode]$NewContactGroup = $XMLFile.CreateElement('ContactGroup','')
            $NewContactGroup.SetAttribute('Number','20') #High number so as to not overwrite existing groups.
            #Display name in ContactGroups found in XMl file in test account
            #Export-CsUserData -PoolFqdn "" -UserFilter -FileName "c:\scripts\"
write-host "`r`nNo existing contact groups found.`r`n"
write-host "`r`nAdding New Contact Group XML Element.`r`n"
[System.XML.XMLLinkedNode]$NewNodeGroup = $XMLFile.CreateElement('ContactGroups','')
            [System.XML.XMLLinkedNode]$NewContactGroup = $XMLFile.CreateElement('ContactGroup','')
            $NewContactGroup.SetAttribute('Number','20') #High number so as to not overwrite existing groups.
            $XMLCGroup = $XMLPart.Data.HomedResource.Containers
            [xml]$XMLFile = Get-Content "$WorkingFolder\DocItemSet.xml"
            $XMLPart = $XMLFile.DocItemSet.DocItem | ?{$_.Name -like "urn:lcd:*"}
            $XMLNode = $XMLPart.Data.HomedResource.Contacts
#Back to original code
    Write-Host "`r`nExisting contacts:`r`n" 

Change these lines to include 1 and the group number in the $ContactstoAdd | foreach{} section
$NewContact.SetAttribute('Groups','1 20') 

If you have a large organization, you will need to create a new policy or edit the Global Presence policy.  Once all the Lync users had the Lync Rooms in the list, the "Maximum Followers Reached" error showed up on the Lync Room systems.

A new Presence Policy was created and applied to the Lync Room accounts. The MaxCategorySubcriptions was to 3000 and the error went away.

 Since it was only applied to the Lync Room systems it should not drastically increase the server traffic as compared to applying to all our Lync users.

Monday, February 2, 2015

SCCM 2012 Hard Drive with Bad Blocks Baseline

This PowerShell script will detect systems where the main hard drive is developing bad blocks.
Or as I call it, the "Click of Death".

Continuing with my previous posts on SCCM 2012 baselines items...

Same steps as Option 2 in the above mentioned post but using the discovery script below...
  1. You can add more If statements or expand it use ElseIf to record bad blocks from other hard drives.
  2. Or change the text in the If statement to just '*bad block*' to count all bad blocks event entries.

#Version 1.00 Feb 2, 2015
#SCCM Baseline for Bad Block on C Drive
$AllEvents = 0

#Default Event Logs
$Provider = "Disk"
$HourChange = 24 
$TimeNow = [DateTime]::Now
$TimeChange = [DateTime]::Now.AddHours(-$HourChange)

#Check Event Log for errors
$EventLogNames = "System"

ForEach ($log in $EventLogNames){
    $entry = " " 
    #Search Event Logs
    $LogEntry = Get-WinEvent -LogName $log | Where-Object {$_.timeCreated -ge $TimeChange -and $_.ProviderName -eq $Provider}
        ForEach ($entry in $LogEntry){
            $EvLevel = "Level: `t" + $entry.LevelDisplayName + $nl
            $EvEventID = "EventID: `t" + $entry.ID + $nl
            $EvMessage = "Message: `t" + $entry.Message
            $EvSource = "Source: `t" + $entry.ProviderName + $nl
            $EvTime = "Time Created: `t" + $entry.TimeCreated + $nl
            #write-host $EvLevel + $EvEventID + $EvMessage + $EvSource +$EvTime + $nl

           If ($EvMessage -like '*The device, \Device\Harddisk0\DR0, has a bad block*'){
                $AllEvents += 1

write-host $AllEvents

More SCCM related posts