header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Remote powershell script
Last Post 15 Aug 2011 10:05 AM by Karl Mitschke. 1 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
kraigkUser is Offline
New Member
New Member
Posts:11
Avatar

--
15 Aug 2011 09:51 AM
    All,

    I need help with a script we're embarking on to mail enable accounts via a datafeed.  We will be doing this from a remote server which will have the remote connection commands like this:

    $user = Get-Credential
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://server1.comany.com/PowerShell/" target="_blank" rel="nofollow">http://server1.comany.com/PowerShell/ -Authentication Kerberos
    Import-PSSession $session
    Get-ExecutionPolicy
    Set-ExecutionPolicy unrestricted

    The question is this - Is there a way to have the script make the remote connection and if it fails it will go on a try the next Exchange server?

    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://server1.comany.com/PowerShell/" target="_blank" rel="nofollow">http://server1.comany.com/PowerShell/ -Authentication Kerberos
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://server2.comany.com/PowerShell/ -Authentication Kerberos
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://server3.comany.com/PowerShell/ -Authentication Kerberos
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://server4.comany.com/PowerShell/ -Authentication Kerberos

    Not sure how to have the script confim successful connection or to show a failure?

    thanks,

    -k


    Karl MitschkeUser is Offline
    Basic Member
    Basic Member
    Posts:457
    Avatar

    --
    15 Aug 2011 10:05 AM
    Try:

    
    If(!$Session.state -eq "opened")
    {
    Next server....
    }
    


    Karl
    http://unlockpowershell.wordpress.com
    Co-Author, Windows PowerShell 2.0 Bible
    -join("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer