Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2016-09-23
3
Medium Priority
?
69 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 44

Expert Comment

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

Accepted Solution

by:
Adam Brown earned 2000 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 42

Expert Comment

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

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
Are you an Exchange administrator employed with an organization? And, have you encountered a corrupt Exchange database due to which you are not able to open its EDB file. This article will explain all the steps to repair corrupt Exchange database.
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…
This video discusses moving either the default database or any database to a new volume.

688 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