Monday, August 5, 2013

Changing StartMode and State for Exchange Services

When patching Exchange Mailbox servers, there is often a need to reboot several times, and we have often stopped and disabled the exchange services to allow for quicker boot times. I have written two powershell scripts as follows:
1.     Stop-ExchangeServices.ps1 - This script will list all the exchange services (DisplayName, StartMode, State), stop the services and then set any that have a StartMode of Automatic to Disabled. It transcripts its every action and makes an entry to the Application Event Log of the server. It also will leave a text file (called Stop-ExchangeServices.txt) transcript "C:\Transcripts" folder of the server.
2.     Start-ExchangeServices.ps1 - This script will list all the exchange services (DisplayName, StartMode, State), set any that have a StartMode of Disabled to Automatic and then starts the services. It transcripts its every action and makes an entry to the Application Event Log of the server. It also will leave a text file (called Start-ExchangeServices.txt) transcript "C:\Transcripts" folder of the server.
Both scripts require elevated privileges, but you should be logged into the server with your admin account, so that won’t be a worry. To prep the mailbox server for patching, first dismount the mail databases, through the EMC or powershell. I will write a robust script to do this later on. Once all databases are dismounted, open a powershell prompt and navigate to the E:\scripts directory. Then type “.\Stop-ExchangeServices.ps1” and hit ENTER. You will see the following:
PS C:\Scripts> .\Stop-ExchangeServices.ps1
Transcript started, output file is C:\Transcripts\Stop-ExchangeServices.txt
Stop-ExchangeServices.ps1 - Exchange Service States at beginning:
DisplayName                                                         StartMode              State
-----------                                                                ---------                  -----
Microsoft Exchange Active Directory Topology         Auto                      Running
Microsoft Exchange Information Store                      Auto                      Running
Microsoft Exchange Mail Submission Service            Auto                     Running
Microsoft Exchange Mailbox Assistants                    Auto                      Running
Microsoft Exchange Monitoring                               Manual                  Stopped
Microsoft Exchange Replication Service                   Auto                      Running
Microsoft Exchange RPC Client Access                    Auto                      Running
Microsoft Exchange Search Indexer                         Auto                      Running
Microsoft Exchange Service Host                            Auto                      Running
Microsoft Exchange System Attendant                      Auto                      Running
Microsoft Exchange Throttling                                Auto                      Running
Microsoft Exchange Transport Log Search               Auto                      Running

Stopping Exchange Services

Disabling Exchange Services
Exchange Service States at conclusion:

DisplayName                                                         StartMode              State
-----------                                                                ---------                  -----
Microsoft Exchange Active Directory Topology        Disabled                Stopped
Microsoft Exchange Information Store                     Disabled                Stopped
Microsoft Exchange Mail Submission Service          Disabled                Stopped
Microsoft Exchange Mailbox Assistants                   Disabled                Stopped
Microsoft Exchange Monitoring                              Manual                  Stopped
Microsoft Exchange Replication Service                  Disabled                Stopped
Microsoft Exchange RPC Client Access                   Disabled                Stopped
Microsoft Exchange Search Indexer                         Disabled                Stopped
Microsoft Exchange Service Host                            Disabled                Stopped
Microsoft Exchange System Attendant                      Disabled                Stopped
Microsoft Exchange Throttling                                Disabled                Stopped
Microsoft Exchange Transport Log Search               Disabled                Stopped

Server is now ready for Patching. For a transcript of the activities, go to  C:\Transcripts\Stop-ExchangeServices.txt
Transcript stopped, output file is C:\Transcripts\Stop-ExchangeServices.txt
Script concluded, Services stopped and disabled.

The transcript file that is written looks like:
**********************
Windows PowerShell transcript start
Start time: 20130804173135
Username  : DOMAIN\AdminAccount
Machine          : YOUR-SERVER (Microsoft Windows NT 6.1.7601 Service Pack 1)
**********************
Transcript started, output file is C:\Transcripts\Stop-ExchangeServices.txt
Stop-ExchangeeServices.ps1 - Exchangee Service States at beginning:
   
DisplayName                                                         StartMode             State
-----------                                                                ---------                 -----
Microsoft Exchange Active Directory Topology       Auto                     Running
Microsoft Exchange Information Store                    Auto                     Running
Microsoft Exchange Mail Submission Service          Auto                     Running
Microsoft Exchange Mailbox Assistants                   Auto                     Running
Microsoft Exchange Monitoring                              Manual                 Stopped
Microsoft Exchange Replication Service                  Auto                     Running
Microsoft Exchange RPC Client Access                  Auto                     Running
Microsoft Exchange Search Indexer                        Auto                     Running
Microsoft Exchange Service Host                           Auto                     Running
Microsoft Exchange System Attendant                    Auto                     Running
Microsoft Exchange Throttling                               Auto                     Running
Microsoft Exchange Transport Log Search              Auto                     Running

Stopping Exchange Services

Disabling Exchange Services

Exchange Service States at conclusion:

DisplayName                                                         StartMode             State
-----------                                                                ---------                  -----
Microsoft Exchange Active Directory Topology         Disabled                Stopped
Microsoft Exchange Information Store                      Disabled                 Stopped
Microsoft Exchange Mail Submission Service            Disabled                Stopped
Microsoft Exchange Mailbox Assistants                     Disabled                Stopped
Microsoft Exchange Monitoring                                Manual                  Stopped
Microsoft Exchange Replication Service                    Disabled                 Stopped
Microsoft Exchange RPC Client Access                     Disabled                Stopped
Microsoft Exchange Search Indexer                           Disabled                Stopped
Microsoft Exchange Service Host                              Disabled                Stopped
Microsoft Exchange System Attendant                       Disabled                Stopped
Microsoft Exchange Throttling                                  Disabled                Stopped
Microsoft Exchange Transport Log Search                 Disabled                Stopped

Server is now ready for Patching. For a transcript of the activities, go to  C:\Transcripts\Stop-ExchangeServices.txt
Transcript stopped, output file is C:\Transcripts\Stop-ExchangeServices.txt

**********************
Windows PowerShell transcript end
End time: 20130804173136
**********************



The Script also makes an entry into the Application Event Log of the server that will look like this:
- <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
- <System>
  <Provider Name="Start-AdobeServices" />
  <EventID Qualifiers="0">1111</EventID>
  <Level>4</Level>
  <Task>1</Task>
  <Keywords>0x80000000000000</Keywords>
  <TimeCreated SystemTime="2013-08-05T01:18:57.000000000Z" />
  <EventRecordID>20005</EventRecordID>
  <Channel>Application</Channel>
  <Computer>YOUR-SERVER </Computer>
  <Security />
  </System>
- <EventData>
  <Data>**********************Windows PowerShell transcript start Start time: 20130804173135 Username  : DOMAIN\AdminAccount Machine      : YOUR-SERVER (Microsoft Windows NT 6.1.7601 Service Pack 1) ********************** Transcript started, output file is C:\Transcripts\Stop-ExchangeServices.txt Stop-ExchangeeServices.ps1 - Exchangee Service States at beginning:
DisplayName StartMode State ----------- --------- ----- Microsoft Exchange Active Directory Topology Auto  Running Microsoft Exchange Information Store  Auto Running Microsoft Exchange Mail Submission Service     Auto Running Microsoft Exchange Mailbox Assistants Auto                Running Microsoft Exchange Monitoring Manual Stopped Microsoft Exchange Replication Service Auto Running Microsoft Exchange RPC Client Access Auto Running Microsoft Exchange Search Indexer       Auto Running Microsoft Exchange Service Host                     Auto Running Microsoft Exchange System Attendant Auto Running Microsoft Exchange Throttling Auto Running Microsoft Exchange Transport Log Search Auto Running Stopping Exchange Services Disabling Exchange Services Exchange Service States at conclusion: DisplayName  StartMode State ----------- --------- ----- Microsoft Exchange Active Directory Topology Disabled Stopped Microsoft Exchange Information Store Disabled Stopped Microsoft Exchange Mail Submission Service Disabled Stopped Microsoft Exchange Mailbox Assistants Disabled Stopped Microsoft Exchange Monitoring Manual Stopped Microsoft Exchange Replication Service Disabled Stopped Microsoft Exchange RPC Client Access    Disabled Stopped Microsoft Exchange Search Indexer Disabled Stopped Microsoft Exchange Service Host Disabled Stopped Microsoft Exchange System Attendant Disabled             Stopped Microsoft Exchange Throttling Disabled Stopped Microsoft Exchange Transport Log Search              Disabled Stopped Server is now ready for Patching. For a transcript of the activities, go to  C:\Transcripts\Stop-ExchangeServices.txt Transcript stopped, output file is C:\Transcripts\Stop-ExchangeServices.txt ********************** Windows PowerShell transcript end End time: 20130804173136 **********************</Data>
  <Binary>0A14</Binary>
  </EventData>
  </Event>

The server is now ready for patching and can be rebooted as many times as necessary to apply the appropriate number of passes from Windows Update. Once all patching is complete, you can run the next script. The Start-ExchangeServices.ps1 script has all the same outputs, except, of course that it sets the StartMode of the disabled services to automatic and starts the services.
Once all patches are applied, open a powershell prompt and navigate to the E:\scripts directory. Then type “.\Start-ExchangeServices.ps1” and hit ENTER. You will see the following:

PS E:\Scripts> .\Start-ExchangeServices.ps1
Transcript started, output file is C:\Transcripts\Start-ExchangeServices.txt
Start-ExchangeServices.ps1 - Exchange Service States at beginning:

DisplayName                                                         StartMode              State
-----------                                                                ---------                  -----
Microsoft Exchange Active Directory Topology        Disabled                Stopped
Microsoft Exchange Information Store                     Disabled                Stopped
Microsoft Exchange Mail Submission Service          Disabled                Stopped
Microsoft Exchange Mailbox Assistants                   Disabled                Stopped
Microsoft Exchange Monitoring                              Manual                  Stopped
Microsoft Exchange Replication Service                  Disabled                Stopped
Microsoft Exchange RPC Client Access                   Disabled                Stopped
Microsoft Exchange Search Indexer                         Disabled                Stopped
Microsoft Exchange Service Host                            Disabled                Stopped
Microsoft Exchange System Attendant                      Disabled                Stopped
Microsoft Exchange Throttling                                Disabled                Stopped
Microsoft Exchange Transport Log Search               Disabled                Stopped


Enabling Exchange Services

Starting Exchange Services

Exchange Service States at conclusion:

DisplayName                                                         StartMode              State
-----------                                                                ---------                  -----
Microsoft Exchange Active Directory Topology        Auto                     Running
Microsoft Exchange Information Store                     Auto                     Running
Microsoft Exchange Mail Submission Service           Auto                     Running
Microsoft Exchange Mailbox Assistants                    Auto                     Running
Microsoft Exchange Monitoring                               Manual                Stopped
Microsoft Exchange Replication Service                   Auto                     Running
Microsoft Exchange RPC Client Access                    Auto                     Running
Microsoft Exchange Search Indexer                         Auto                      Running
Microsoft Exchange Service Host                            Auto                      Running
Microsoft Exchange System Attendant                      Auto                      Running
Microsoft Exchange Throttling                                Auto                      Running
Microsoft Exchange Transport Log Search               Auto                      Running

Server is now restored to normal. For a transcript of the activities, go to  C:\Transcripts\Stop-ExchangeServices.txt
Transcript stopped, output file is C:\Transcripts\Start-ExchangeServices.txt
Script concluded, Services stopped and disabled.

The transcript file that is written looks like:
**********************
Windows PowerShell transcript start
Start time: 20130804212013
Username  : DOMAIN\AdminAccount
Machine          : YOUR-SERVER (Microsoft Windows NT 6.1.7601 Service Pack 1)
**********************
Transcript started, output file is C:\Transcripts\Start-ExchangeServices.txt
Start-ExchangeServices.ps1 - Exchange Service States at beginning:

DisplayName                                                         StartMode             State
-----------                                                                ---------                  -----
Microsoft Exchange Active Directory Topology         Disabled                Stopped
Microsoft Exchange Information Store                      Disabled                 Stopped
Microsoft Exchange Mail Submission Service            Disabled                 Stopped
Microsoft Exchange Mailbox Assistants                     Disabled                Stopped
Microsoft Exchange Monitoring                                Manual                  Stopped
Microsoft Exchange Replication Service                    Disabled                Stopped
Microsoft Exchange RPC Client Access                    Disabled                Stopped
Microsoft Exchange Search Indexer                          Disabled                Stopped
Microsoft Exchange Service Host                             Disabled                Stopped
Microsoft Exchange System Attendant                      Disabled                Stopped
Microsoft Exchange Throttling                                 Disabled                Stopped
Microsoft Exchange Transport Log Search                Disabled                Stopped

Starting Exchange Services

Enabling Exchange Services

Exchange Service States at conclusion:
DisplayName                                                         StartMode             State
-----------                                                                ---------                  -----
Microsoft Exchange Active Directory Topology         Auto                     Running
Microsoft Exchange Information Store                      Auto                     Running
Microsoft Exchange Mail Submission Service            Auto                     Running
Microsoft Exchange Mailbox Assistants                     Auto                     Running
Microsoft Exchange Monitoring                                Manual                 Stopped
Microsoft Exchange Replication Service                    Auto                     Running
Microsoft Exchange RPC Client Access                    Auto                     Running
Microsoft Exchange Search Indexer                          Auto                     Running
Microsoft Exchange Service Host                             Auto                      Running
Microsoft Exchange System Attendant                      Auto                      Running
Microsoft Exchange Throttling                                 Auto                     Running
Microsoft Exchange Transport Log Search                Auto                     Running

Server is now restored to normal. For a transcript of the activities, go to  C:\Transcripts\Stop-ExchangeServices.txt
Transcript stopped, output file is C:\Transcripts\Stop-ExchangeServices.txt

**********************
Windows PowerShell transcript end
End time: 20130804212014
**********************

The Script also makes an entry into the Application Event Log of the server that will look like this:
- <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
- <System>
  <Provider Name="Start-AdobeServices" />
  <EventID Qualifiers="0">1111</EventID>
  <Level>4</Level>
  <Task>1</Task>
  <Keywords>0x80000000000000</Keywords>
  <TimeCreated SystemTime="2013-08-05T01:18:57.000000000Z" />
  <EventRecordID>20005</EventRecordID>
  <Channel>Application</Channel>
  <Computer>YOUR-SERVER.DOMAIN.COM</Computer>
  <Security />
  </System>
- <EventData>
  <Data>**********************Windows PowerShell transcript start Start time: 20130804173135 Username  : DOMAIN\AdminAccount Machine      : YOUR-SERVER (Microsoft Windows NT 6.1.7601 Service Pack 1) ********************** Transcript started, output file is C:\Transcripts\Stop-ExchangeServices.txt Stop-ExchangeeServices.ps1 - Exchangee Service States at beginning:
DisplayName StartMode State ----------- --------- ----- Microsoft Exchange Active Directory Topology Auto  Running Microsoft Exchange Information Store  Auto Running Microsoft Exchange Mail Submission Service     Auto Running Microsoft Exchange Mailbox Assistants Auto                Running Microsoft Exchange Monitoring Manual Stopped Microsoft Exchange Replication Service Auto Running Microsoft Exchange RPC Client Access Auto Running Microsoft Exchange Search Indexer       Auto Running Microsoft Exchange Service Host  Auto Running Microsoft Exchange System Attendant Auto Running Microsoft Exchange Throttling Auto Running Microsoft Exchange Transport Log Search Auto Running Stopping Exchange Services Disabling Exchange Services Exchange Service States at conclusion: DisplayName  StartMode State ----------- --------- ----- Microsoft Exchange Active Directory Topology Disabled Stopped Microsoft Exchange Information Store Disabled Stopped Microsoft Exchange Mail Submission Service Disabled Stopped Microsoft Exchange Mailbox Assistants Disabled Stopped Microsoft Exchange Monitoring Manual Stopped Microsoft Exchange Replication Service Disabled Stopped Microsoft Exchange RPC Client Access Disabled Stopped Microsoft Exchange Search Indexer Disabled Stopped Microsoft Exchange Service Host Disabled Stopped Microsoft Exchange System Attendant Disabled Stopped Microsoft Exchange Throttling Disabled Stopped Microsoft Exchange Transport Log Search Disabled Stopped Server is now ready for Patching. For a transcript of the activities, go to  C:\Transcripts\Stop-ExchangeServices.txt Transcript stopped, output file is C:\Transcripts\Stop-ExchangeServices.txt ********************** Windows PowerShell transcript end End time: 20130804173136 **********************</Data>
  <Binary>0A14</Binary>
  </EventData>
  </Event>


The server is now in a normalized state, and the Mail Databases can be mounted and normal operation can be resumed. 

The Scripts:
Note: Log_this function used in both scripts written by: Som Dutt Tripathi, used from: http://powershell-tips.blogspot.com/2012/10/how-to-write-in-windows-event-log-with.html

Stop-ExchangeServices.ps1
<#
    .SYNOPSIS
    Stops Exchange Services and sets their start mode to disabled. 
   
                Sean McNamara sean.mcnamara@spx.com
                Log_this function written by: Som Dutt Tripathi, used from: http://powershell-tips.blogspot.com/2012/10/how-to-write-in-windows-event-log-with.html
               
                THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE ENTIRE 
                RISK OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER.
               
                Version 1 - August 4, 2013
               
    .DESCRIPTION
               
    This script Stops Exchange Services and sets their start mode to disabled. It writes a transcript to the Application 
                Event log on the server. 
               
                .EXAMPLE
    .\Stop-ExchangeServices.ps1 
               
    #>
$SCRIPT_NAME="Stop-ExchangeServices" 
$Script_Path="C:\Sandbox\Stop-ExchangeServices.txt"

function log_this([string]$MESSAGE) { 

                if ( !([System.Diagnostics.EventLog]::SourceExists($SCRIPT_NAME)) ) 
                { 
                                New-EventLog -LogName Application -Source $SCRIPT_NAME 
                } 

                Write-EventLog -logname Application -source $SCRIPT_NAME -eventID 1111 -entrytype Information -message $MESSAGE -category 1 -rawdata 10,20 
}


Start-Transcript -path $Script_Path 

# Show Current Service Status
Write-Host "Stop-ExchangeServices.ps1 - Exchange Service States at beginning:"
Get-WmiObject Win32_Service | where{$_.DisplayName -like '*Exchange*'} | Select DisplayName, StartMode, State
write-host ""

# Stop Exchange Services
Write-host "Stopping Exchange Services"
# Note ** Using -Force because MsExchangeADTopology Service has dependancies and will not stop without it
Get-Service | where{($_.DisplayName –Like ‘*Exchange*’) -and ($_.Status -eq "Running")}  | Stop-Service -Force

# Disable Services
Write-host""
Write-host "Disabling Exchange Services"
Get-WmiObject Win32_Service | where{($_.DisplayName -like '*Exchange*') -and ($_.StartMode -eq "Auto")} | set-Service –StartupType ‘Disabled’
Write-Host""

# Show current Start Mode
Write-Host "Exchange Service States at conclusion:"
Write-Host""
Get-WmiObject Win32_Service | where{$_.DisplayName -like '*Exchange*'} | Select DisplayName, StartMode, State
Write-Host "Server is now ready for Patching. For a transcript of the activities, go to " $Script_Path
stop-transcript

# Write information to Event Log
$Trans_Info = Get-Content $Script_Path  

log_this $Trans_Info

#End Script

Start-ExchangeServices.ps1

<#
    .SYNOPSIS
    Sets Exchange Services StartMode to Auto and starts the service. 
   
                Sean McNamara sean.mcnamara@spx.com
                Log_this function written by: Som Dutt Tripathi, used from: http://powershell-tips.blogspot.com/2012/10/how-to-write-in-windows-event-log-with.html
               
                THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE ENTIRE 
                RISK OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER.
               
                Version 1 - August 4, 2013
               
    .DESCRIPTION
               
    This script sets the startup type of any Exchange service that are disabled to automatic, starts the service and writes a transcript
                to the application event log on the server. 
               
                .EXAMPLE
    .\Start-ExchangeServices.ps1 
               
    #>
$SCRIPT_NAME="Start-ExchangeServices" 
$Script_Path="E:\files\Transcripts\Start-ExchangeServices.txt" 

function log_this([string]$MESSAGE) { 

                if ( !([System.Diagnostics.EventLog]::SourceExists($SCRIPT_NAME)) ) 
                { 
                                New-EventLog -LogName Application -Source $SCRIPT_NAME 
                } 

                Write-EventLog -logname Application -source $SCRIPT_NAME -eventID 1111 -entrytype Information -message $MESSAGE -category 1 -rawdata 10,20 
}


Start-Transcript -path $Script_Path

# Show Current Service Status
Write-Host "Start-ExchangeServices.ps1 - Exchange Service States at beginning:"
Get-WmiObject Win32_Service | where{$_.DisplayName -like '*Exchange*'} | Select DisplayName, StartMode, State
write-host ""

# Enable Services
Write-host""
Write-host "Enabling Exchange Services"
Get-WmiObject Win32_Service | where{($_.DisplayName -like '*Exchange*') -and ($_.StartMode -eq "Disabled")} | set-Service –StartupType ‘Auto’
Write-Host""

# Start Exchange Services
Write-host "Starting Exchange Services"
Get-WmiObject Win32_Service | where{($_.DisplayName –Like ‘*Exchange*’) -and ($_.StartMode -eq "Auto")} | Start-Service 

# Show current Start Mode
Write-Host "Exchange Service States at conclusion:"
Write-Host""
Get-WmiObject Win32_Service | where{$_.DisplayName -like '*Exchange*'} | Select DisplayName, StartMode, State
Write-Host "Server is now restored to normal. For a transcript of the activities, go to " $Script_Path
Stop-transcript

# Write information to Event Log
$Trans_Info = Get-Content $Script_Path  

log_this $Trans_Info


Write-host "Script concluded, Services enabled and started."

#End Script


Monday, July 1, 2013

Creating Additional SMTP Addresses For Exchange Users

I recently had to add an additional SMTP Address for all the users in my domain. I wrote this quick script that made it a no brainer:

<#
.NAME
    Append-EmailAddresses.ps1
.SYNOPSIS
    This script adds a new smtp address of first.last@exchange.yourdomain.com
    to all email users that have an @yourdomain.com email address
.DESCRIPTION 
  Versions
    1.0 - 12/21/2011 Initial release
.LINK
    http://unicomsta.blogspot.com/
.EMAIL
    sean.mcnamara@live.com
.EXAMPLE
    .\Append-EmailAddresses.PS1
.INPUTS
    None. You cannot pipe objects to this script.
#>

$mailboxes = Get-Mailbox -resultsize unlimited -RecipientTypeDetails UserMailbox"
foreach ($mailbox in $mailboxes)
{
  
$newaddress = $mailbox.windowsemailaddress -replace '@yourdomain.com' , '@exchange.yourdomain.com'

$mailbox.EmailAddresses += $newaddress

Set-Mailbox -Identity $mailbox.alias -EmailAddresses $mailbox.EmailAddresses
}

Wednesday, April 17, 2013

Getting and Using Your IP Address in Powershell

UPDATE: 1/14/2015: PowerShell now has built in cmdlets to handle this. Try

Get-NetIPAddress




Getting an IP Address from a machine is something we need to do often, for many reasons. Typically, you would employ the CLI tool IPCONFIG to get it, and if you wanted to quickly get just the IP Addresses for your machine, you might use:

ipconfig -all | findstr IPv4

The output of which would look like:

C:\>ipconfig -all | findstr IPv4
   IPv4 Address. . . . . . . . . . . : 129.168.34.233(Preferred)
   IPv4 Address. . . . . . . . . . . : 129.168..93.194(Preferred)


Which is fine but doesn't give you the flexibility to use that information within a powershell script to do other things, so where's the fun in that? Also, getting it with powershell is a necessary skill for anyone that administers servers (at least to my way of thinking). I wrote the following code and saved it as "Get-IpAddress.ps1" on all my machines. It gives me the output I want in the format I want for most of my quick needs:

$strComputer ="."
$colItems = Get-WmiObject Win32_NetworkAdapterConfiguration -Namespace "root\CIMV2" | where{$_.IPEnabled -eq “True”}

Write-Host " "
Write-Host "********************************************"
Write-Host " "
foreach($objItem in $colItems) {
     Write-Host "Adapter:" $objItem.Description
     Write-Host "         DNS Domain:" $objItem.DNSDomain
     Write-Host "         IPv4 Address:" $objItem.IPAddress[0]
     Write-Host "         IPv6 Address:" $objItem.IPAddress[1]
     Write-Host " "
      }
Write-Host "********************************************"
Write-Host " "

I can then run it from any powershell prompt by invoking the script. The output of the above script is:

PS C:\scripts> .\Get-IpAddress
********************************************

Adapter: Intel(R) Centrino(R) Advanced-N 6205
         DNS Domain: global.mydomain.com
         IPv4 Address: 192.10.93.194
         IPv6 Address: fe99::68a8:5ac:89b2:ffff


Adapter: Intel(R) 82579LM Gigabit Network Connection
         DNS Domain: global.mydomain.com
         IPv4 Address: 192.168.34.233
         IPv6 Address: fe99::d191:bbb1:a067:ffff
********************************************

PS C:\scripts>
 
Now, the basis of the script can be used as a function in other scripts. Say, for example you wanted to use a script to determine whether you were working from the office, home or a remote location at start-up and act on the location by starting or not starting certain applications. You might want to, say, start outlook and lync only if you're in the office at start-up, and leave them offline if you're working from home, at least until you've had the chance to VPN in (Yes, some companies will not allow Outlook Anywhere or Lync Edge Connections or split tunneling). You could accomplish this with a script that looks something like this:

Friday, March 15, 2013

List A User's Response Group Memberships

We just had an issue where a response group in Lync was not working properly. While troubleshooting, we discovered that the user to whom the response group pointed had recently been married and had her name changed. Per normal process, her AD account, email address and SIP name were changed to her new name. This caused an issue with the response group, however. Since there was a gap in the process, and we had no procedure in place for checking the user’s membership in response groups, the group was trying to transfer a call to a now non-existent SIP address. So, that means whenever we change an account we must know if the user is Enterprise Voice enabled, and if they are, we must also know if they belong to any response groups. Unfortunately, there is no clean way to find that membership in the Lync Control Panel. You would have to open each response group and look at its membership one at a time to see if the user was a member. To get around this, you’ll have to RDP into a Lync  Server and open a Lync Powershell session and enter the following command:

get-csrgsagentgroup | Where-Object {$_.AgentsByUri -like "sip:first.last@spx.com"} | Select name

See the example below to illustrate what it looks like and what the results would be:
This will give you a list of response groups the user is a member of. You can then make the appropriate changes to the groups, if any.