Solved

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

Posted on 2016-09-23
3
52 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_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 43

Expert Comment

by:Amit
ID: 41812511
Did  you test same script on 2010? What error are you getting.
0
 
LVL 40

Accepted Solution

by:
Adam Brown earned 500 total points (awarded by participants)
ID: 41812586
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 40

Expert Comment

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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to install and use the NTBackup utility that comes with Windows Server.
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
This video discusses moving either the default database or any database to a new volume.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

752 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