header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
how to execute exchange cmdlets remotely using script
Last Post 26 Mar 2010 11:25 PM by mallikarjun shetty. 0 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
mallikarjun shettyUser is Offline
New Member
New Member
Posts:6
Avatar

--
26 Mar 2010 11:25 PM

    Hi,
    currently i have installed powershell 1.0 on top of XP SP3 and trying to execute exchange cmdlets remotely using following script but it is giving following error.   


    Active Directory server vanguard.itsmenabler.co.in is not available. Error message: The supplied credential is invalid. + CategoryInfo : NotSpecified: (0:Int32) [Get-MailboxServer], ADOperationException + FullyQualifiedErrorId : EB633F97,Microsoft.Exchange.Management.SystemConfigurationTasks.GetMailboxServer

    Script: takes servername username and password  as arguments.  


    function Get-PassCred {
           $pass =    ConvertTo-SecureString -force -AsPlainText -string $password
           $return = New-Object System.Management.Automation.PSCredential -ArgumentList $username ,$pass
           $return
    }

    function Get-Connection {
     $return =  new-pssession -ComputerName $hostname -credential $cred
     $return
     

    }

    function Get-Data{
     
    #invoke-command -ComputerName $hostname -credential $cred -scriptblock {Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin}
    invoke-command -session $mysession  -scriptblock {Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin;get-wmiobject win32_computersystem;get-queue;get-mailboxserver;Remove-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin}
    #invoke-command -ComputerName $hostname -credential $cred -scriptblock {Remove-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin}
    }

    function Disconnect-Session{
         
      remove-pssession -session (get-pssession)
    }

    $hostname = $args[0]
    $username = $args[1]
    $password = $args[2]
    $cred = Get-PassCred

    #$cred | Out-Host
    $mysession = Get-Connection
    Get-Data
    #$error
    Disconnect-Session
    # Set-User Administrator -RemotePowerShellEnabled $true;
    # | Export-Clixml e:\exchange.xml -noclobber


    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