Reputation: 9
Im having a problem trying to run windows shell code from my computer via a vbs script. In short it should connect to our exchange server and create a mail address for said user. It works on the server but we want it all in one script....
'Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run "$UserCredential = Get-Credential"
oShell.run "$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://<FQDN of Exchange 2013 Client Access server>/PowerShell/ -Authentication Kerberos -Credential $UserCredential"
oShell.run "Import-PSSession $Session"
oShell.run "Enable-Mailbox [email protected] -Database ""Students"
oShell.run "Remove-PSSession $Session"
oShell.run "cmd"
Set oShell = Nothing'
Upvotes: 0
Views: 133
Reputation: 11
You may find that its running each command line in a separate shell, then exiting. I would suggest you create a PowerShell script which does all the work. Then you call the script from your .vbs script. This will also allow you to test it by running the script outside of the calling .vbs script.
If you really do not want to call a PowerShell script though, then split each command using ;
between them, so you can run multiple commands on one line, e.g.:
$UserCredential = Get-Credential ; $Session = New-PSSession -ConfigurationName Microsoft.Exchange ...
Upvotes: 1