Pages

Thursday, January 30, 2014

Powershell script to remove smtp addresses with a domain from mailboxes in Exchange 2010

This script is to remove a smtp domain from a client’s mailboxes. Email address policy is how these domains get added to the mailboxes. However email address policies are additive only and cannot be used to remove the domain that was added using email address policy. They have to removed manually from each mailbox.

When will we need this?

A good scenario is when a client company ABC has changed their company smtp domain from abc.com to xyz.com and no longer want to receive any email on the old smtp abc.com that is they want that if somebody sends an email to abc.com they should get a bounceback. The old domain abc.com has been  removed from the accepted domains and the MX records for abc.com no longer point to your exchange server. Externally this will work correctly because obviously the DNS has been modified and abc.com has been removed from accepted domains in our exchange. But internally on the same exchange server, users will still be able to send and receive an email to abc.com address. The email addresses with abc.com either needs to be removed manually from each users exchange properties or you can use powershell to do it for you.

How will this work?


1       I am using a custom attribute for filtering the get-mailbox command, but you can use –scope to use OU for filtering or select all the users. Modify the customattribute1 value to the of the client and domain name (domain.com) to the target smtp domain in the script and copy the script
2       Open the exchange management shell and paste the script in the shell window (press enter once)

All the email address for client with clientcode ‘clientcode’ that contain email addresses with smtp domain ‘domain.com’ will be removed.

#Script to remove email address for a particular domain as EAP is additive Only
# BEFORE USING - please change the domain name and custom attribute as mentioned in comments
# IMPORTANT: DOMAIN IS NOT YOUR AD DOMAIN BUT THE SMTP DOMAIN YOU WANT TO REMOVE


#Gets the client mailboxes for the users with customattribute1 set as 'abc'

foreach($Clientmailbox in Get-mailbox -ResultSize Unlimited | where{$_.CustomAttribute1 -eq 'abc'})
{
#for each mailbox grabs the email addresses and filters the addresslist
#for the smtp domain the needs to be removed
#and then removes the email address
#CHANGE THE DOMAIN from domain.com to the corresponding domain
$Clientmailbox.EmailAddresses |
    ?{$_.AddressString -like '*@domain.com'} | %{
      Set-Mailbox $clientmailbox -EmailAddresses @{remove=$_}
    }
}



Wednesday, January 29, 2014

Powershell script to create a report for whether or not a Citrix Xenapp Hotfix is installed on Citrix Xenapp farm servers or not


One of the second biggest pain for me as a farm administrator has always been to figure out if the XenApp Servers in the farm do have the latest rollup (or hotfix installed. And which are the servers where the latest roll up is not installed. The biggest pain of course is to install it remotely on all the XenApp servers ( I am still working in that one).

So I have this script that creates a report for a particular rollup pack or hotfix telling which servers have the hotfix installed and which don’t. It also creates a list of servers where the hotfix is not installed so I can install the hotfix on those servers.

I have tested this script on XenApp 6.0 farm. I ran the script from a XenApp server in the farm.



# Script to create a report on whether the hotfix is installed or not on the
# XenApp servers
# Created by: Ruby Nahal


# Register Addins if missing
$snapin = Get-PSSnapin | where {$_.name -eq 'Citrix.Common.Commands'}
if($snapin -eq $null){ Add-PSSnapin Citrix.Common.Commands }
$snapin = Get-PSSnapin | where {$_.name -eq 'Citrix.XenApp.Commands'}
if($snapin -eq $null){ Add-PSSnapin Citrix.XenApp.Commands }

$farm = Get-XAfarm          #get farm info
$servers = Get-XAServer    # get all the xenapp servers in the farm
[string]$CXAName              # string object to store the Xenapp server name
$logfile = "C:\Support\XAreport.txt"         # log file to store CXA name and if the hotfix is installed or not
$CXAList = "C:\Support\CXAlist.txt"                   #list of servers that do not have the hotfix installed

Foreach($CXA in $servers)            #run for each CXA or Xenapp server in the farm
{
[Boolean]$RUisInstalled = $false    #boolean variable to check the status of hotfix on the server
$CXAName = $CXA.Servername                        #Get the server name for the CXA in the current loop
Write-Output $CXAName                                # write the cxa name

#function XenappHotfixRU2Report([string]$HotfixName)           #can also use this script as a function for multiple hotfixes
#       {
    # Get current computername and XenServer object
    [String]$HotfixName = 'XA600W2K8R2X64R02'          #hotfix in question - will be commented out if used as the function
   
    foreach($hotfix in (Get-XAServerHotFix -ServerName $CXAName)) #run for each hotfix installed on the server
          {
           
        if($hotfix.HotfixName -eq $HotfixName) #if hotfix name is equal to the $hotfixname set the boolean variable to true
                             {
                             $RUisInstalled = $true
                             }
                   else
                             {
                             echo ".." # else, basically do nothing
                             }
          }
                   echo "'n****** $CXAName *******" | Out-File $logfile -Append -Width 240 # write the CXA name to the log file
                   if ($RUisInstalled# tell us if hotfix is installed or not by writing it to the log file
                             {
                             echo "Rollup Installed" | Out-File $logfile -Append -Width 240
                             }
                   Else
                             {
                             echo "Rollup was Not Installed" | Out-File $logfile -Append -Width 240
                             echo $CXAName | Out-File $CXAList -Append -Width 240
                             }
#       }
          #XenappHotfixRU2Report 'XA600W2K8R2X64R02'

}

Tuesday, January 28, 2014

Workspace control on Citrix Xenapp published desktop


What this means?

-          If you login to published Desktop from computer 1 and then go to computer 2 and login from there, your session will automatically get disconnected from computer 1 and launch on computer 2. You will NOT get the error “you have reached the concurrent session limit

-          Auto- launch is disabled. This is a default from citrix that when workspace control is enabled, auto-launch will be disabled. This means, when you open the login page and enter your username and password, the session will NOT launch automatically. You will have to click on the Application icon to launch your session

Where this does not work?

-          If a session is running on computer 1 and you attempt to launch another session to the same desktop, you WILL get the concurrent limit error.

How this is done?

In Citrix Appcenter, expand “applications” and right click on the application you want to enable this on and select application properties. Select the “Name” section and under “application description”, type in the following

KEYWORDS:TreatAsApp Auto

TreatAsApp forces the desktop to be treated as a published application and enables workspace control

Auto automatically subscribes to the application in the storefront and the user does not need to manually add the application.

Tuesday, January 7, 2014

Script to backup ESXi configurations for all hosts in the cluster





This script is used to backup the ESXi configuration of all the hosts in the cluster. This backup will serve in the event if a VMware host has to be rebuild and if the configuration of a host goes corrupt  or compromised.This is a powershell script that requires the vmware powercli module.






#This script will backup the hosts Configuration


#Created By: Ruby Nahal

#run as scheduled task using the a service account that has 
#administrative rights on vcente. vcenter must have powercli installed

#this script creates the backup in D:\esxibackups and each backup is replaced # by the new one

# it also copies the backups to \\fileserver\share\backups



#Load the vmware powershell snapin

add-pssnapin vmware.vimautomation.core



#Connect to the vCenter Server

Connect-VIServer vcenter-01



#grab the list of hostnames

$esxihosts = get-VMhost | select name



#Print the list

Write-Output $esxihosts



#variable of type string to convert the object $esxihost to string value

[string]$esxihostname

Foreach ($esxihost in $esxihosts)

                {

                $esxihostname = $esxihost.Name

                Write-Output $esxihostname

                Get-VMHostFirmware -VMHost $esxihostname -BackupConfiguration -DestinationPath D:\esxibackups

                }

Copy-Item -Path D:\esxibackups -Destination \\fileserver\share\backups -Recurse -Force