Quantcast
Channel: PowerShell General
Viewing all articles
Browse latest Browse all 10624

Running Exchange Management Shell from Excel VBS

$
0
0

Private Sub CommandButton1_Click()

Counter = 3

Do

Dim Command

Command = Worksheets("table1").Cells(Counter, 1).Value

Shell ("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -PSConsoleFile ""C:\Program Files\Microsoft\Exchange Server\V15\bin\ExShell.psc1"" -noexit icm -ScriptBlock {" & Command & "}")

Counter = Counter + 1

Loop Until Command = ""

End Sub

 

With the script above i'm running every command been stored in excel from row 2,col1 until

an empty row iscoming. Every command line opens in his own EMS window.  How can i execute

every command in only one Shell window? How can i implement an errorlog?

 

The commands in excel are exchange2010 specific like below

 


 

New-Mailbox -Name 'USER1' -Alias 'USER1' -OrganizationalUnit 'contoso.con.com/Mail/Mailboxes' -UserPrincipalName 'USER1@contoso.com' -SamAccountName 'USER1' -Password $pass -ResetPasswordOnNextLogon $false

Add-MailboxPermission -identity USER1 -user Group1 -AccessRights “FullAccess”

Add-ADPermission USER1 -User GROUP1 -ExtendedRights “Send as”


Viewing all articles
Browse latest Browse all 10624

Trending Articles