Solved

Convert script between different powershell versions "exchange command shell 2013 ---> 2010"

Posted on 2016-09-23
3
27 Views
Last Modified: 2016-10-12
hi Folks,
could anybody help me to convert this powershell script to older Version? This is for Exchange command Shell 2013.
i needed for Exchange command Shell 2010.

$admodule = (get-module -ListAvailable | where {$_.name -match "ActiveDirectory"}).name
if ($admodule)
	{
		import-module activedirectory
	}
else
	{
		write-host "ActiveDirectory Modul not found" -foregroundcolor red
		exit 0
	}

clear-host
write-host "
---------------------------------------------------------------------

                    ExchangeCertificateAssistant
                      für Exchange Server 2013
                        by Frank Zöchling

                        www.FrankysWeb.de

---------------------------------------------------------------------"
write-host ""
write-host "
 Before you start ExchangeCertificateAssistent, you must create a certificate template.
" -foregroundcolor yellow
write-host ""

$ans = read-host "Did you create the Certificate template? (j/n)"

if ($ans -match "j")
	{
	}
elseif ($ans -match "n")
	{
		write-host "The template must create before" -foregroundcolor red
		exit 0
	}
else
	{
		write-host "yes or no?" -foregroundcolor red
		exit 0
	}

$template = read-host "Pls enter the name of the certificate template"	

[string]$templatepath = "ad:\CN=Certificate Templates,CN=Public Key Services,CN=Services," + (Get-ChildItem ad:\ | where {$_.name -match "Configuration"}).DistinguishedName
$templatecheck = Get-ChildItem $templatepath | where {$_.Name -match "$template"}

if ($templatecheck)
	{
		write-host " Template found" -foregroundcolor green
	}
else
	{
		write-host " Template not found" -foregroundcolor red
		exit 0
	}

$password = read-host "Pls enter the Password for the pfx" -AsSecureString

#Hostnames for the certificate
write-host ""
write-host "Get DNS-Names"
$dnsnames = $NULL

$owadirs = Get-OwaVirtualDirectory
foreach ($owadir in $owadirs)
	{
		$internal = $owadir.internalurl.host
		$external = $owadir.externalurl.host
		
		$dnsnames += @("$internal")
		$dnsnames += @("$external")
	}
	
$easdirs = Get-ActiveSyncVirtualDirectory
foreach ($easdir in $easdirs)
	{
		$internal = $easdir.internalurl.host
		$external = $easdir.externalurl.host
		
		$dnsnames += @("$internal")
		$dnsnames += @("$external")
	}

$ewsdirs = Get-WebServicesVirtualDirectory
foreach ($ewsdir in $ewsdirs)
	{
		$internal = $ewsdir.internalurl.host
		$external = $ewsdir.externalurl.host
		
		$dnsnames += @("$internal")
		$dnsnames += @("$external")
	}
	
$ecpdirs = Get-EcpVirtualDirectory
foreach ($ecpdir in $ecpdirs)
	{
		$internal = $ecpdir.internalurl.host
		$external = $ecpdir.externalurl.host
		
		$dnsnames += @("$internal")
		$dnsnames += @("$external")
	}
	
$oabdirs = Get-OabVirtualDirectory
foreach ($oabdir in $oabdirs)
	{
		$internal = $oabdir.internalurl.host
		$external = $oabdir.externalurl.host
		
		$dnsnames += @("$internal")
		$dnsnames += @("$external")
	}
	
$casservers = Get-ClientAccessServer
foreach ($casserver in $casservers)
	{
		$casshortname = $casserver.name
		$casfqdn = $casserver.fqdn
		
		$dnsnames += @("$casshortname")
		$dnsnames += @("$casfqdn")
	}

$domains = Get-AcceptedDomain
foreach ($domain in $domains)
	{
		$domainname = $domain.domainname
		$autodiscover = "autodiscover." + "$domainname"
		
		$dnsnames += @("$autodiscover")
	}		
	
$oas = Get-OutlookAnywhere
foreach ($server in $oa)
	{
		$oaintern = $server.internalhostname
		$oaextern = $server.externalhostname

		$dnsnames += @("$oaintern")
		$dnsnames += @("$oaextern")
	}
 
$dnsnames = $dnsnames | select -Unique

write-host "Following DNS-Names will be include on the certificate:"
write-host ""
$dnsnames
write-host ""

$addname = "j"
while ($addname -match "j")
{
	$addname = read-host "Should include more names to the certificate? (j/n)"
	if ($addname -match "j")
		{
			$addhost = read-host "Pls enter DNS Name"
			$dnsnames += @("$addhost")
		}
}

write-host ""
write-host "The certificate will issued with following:"
write-host ""
$dnsnames
write-host ""

#get certificate
$loc = Get-Location
Set-Location "Cert:\LocalMachine\My"
$cert = Get-Certificate -Template $template -DnsName $dnsnames -CertStoreLocation cert:\LocalMachine\My -Url ldap:
$thumbprint = $cert.Certificate.Thumbprint
Set-Location $loc

#Export certificat
$exportdir = "c:\Zertifikat"
$pathvalid = test-path $exportdir
if ($pathvalid -notmatch "True")
	{
		$folder = New-Item -ItemType directory -Path $exportdir
	}

$filepath = "$exportdir" + "\Exchange.pfx"
$export = Get-ChildItem -Path "cert:\localMachine\my\$thumbprint" | Export-PfxCertificate -FilePath $filepath -Password $password
$remove = Get-ChildItem -Path "cert:\localMachine\my\$thumbprint" | Remove-Item

#Importiere Zertifikat
$servername = $env:computername
$pfxpath = "\\" + "$servername" + "\c`$" + "\Zertifikat\Exchange.pfx"
$exservers = get-mailboxserver
$fn = "ExchangeCertificateAssistant by www.FrankysWeb.de"
foreach ($exserver in $exservers)
{
	$exservername  = $exserver.name
	write-host "Import and activate certificate on $exservername"
	$import = Import-ExchangeCertificate -Password $password -PrivateKeyExportable:$true -FileName $pfxpath -server $exservername -FriendlyName $fn
	$activate = Enable-ExchangeCertificate -Thumbprint $thumbprint -Services SMTP,IMAP,POP,IIS -force
}

write-host "
---------------------------------------------------------------------
The certificate is saved under $filepath
"

Open in new window

0
Comment
Question by:Mandy_
  • 2
3 Comments
 
LVL 41

Expert Comment

by:Amit
Comment Utility
Did  you test same script on 2010? What error are you getting.
0
 
LVL 38

Accepted Solution

by:
Adam Brown earned 500 total points (awarded by participants)
Comment Utility
There are no cmdlets in this that don't exist in both Exchange 2010 and 2013, as far as I can tell, so it should work just fine for 2010 as well.
0
 
LVL 38

Expert Comment

by:Adam Brown
Comment Utility
No response. Script should work in Exchange 2010 and 2013
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

We are happy to announce a brand new addition to our line of acclaimed email signature management products – CodeTwo Email Signatures for Office 365.
Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager
how to add IIS SMTP to handle application/Scanner relays into office 365.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now