Solved

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

Posted on 2016-09-23
3
48 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

Backup Solution for AWS

Read about how CloudBerry Backup fully integrates your backups with Amazon S3 and Amazon Glacier to provide military-grade encryption and dramatically cut storage costs on any platform.

Question has a verified solution.

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

MS Outlook is a world-class email client application that is mainly used for e-communication globally.  In this article, we will discuss the basic idea about MS Outlook, its advanced features, and types of MS Outlook File formats.
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
In this video we show how to create a Contact in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >> Contact ta…
In this video we show how to create an Address List in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Organization >> Ad…

756 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