Rebuild the PowerShell Virtual Directory in Exchange
By: Cam Wohlfeil
Published: 2018-06-13 0000 EDT
Category: Solutions
Tags:
powershell,
exchange
If you're a dumb-ass like me who tends to make changes faster than he thinks them through, you may have screwed up the PowerShell virtual directory in Exchange and want (or need) to rebuild it and set things back to default. You should absolutely, under no circumstances, do this from the Exchange Management Shell! It may not be obvious (it wasn't to me) that the Exchange Shell connects to Exchange via this virtual directory, so if you delete it you'll no longer be able to connect. What you have to do instead is load the PSSnapIn in a regular PowerShell console on the server you'd like to manage.
# 2013/2016
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn
# 2010
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
# Remove the current PowerShell Virtual Directory
# Don't forget to specify the server, or this will remove all of them on all of your server!
Get-PowerShellVirtualDirectory -Server <server name> | Remove-PowerShellVirtualDirectory
# Create the new PowerShell Virtual Directory
New-PowerShellVirtualDirectory
Hopefully you can learn from my mistakes. Also, do not ever, under any circumstances, start mucking around in the Exchange Back-end Virtual Directories on Exchange 2013/2016, everything you want is in the Front-end ones. There's a reason the shell hides them from you unless you explicitly ask for them!
More Info: