Powershell - Automated Lync Deployment V1
If you need to deploy an environment this may help...
the script should deploy the windows pre-reqs, the lync pre-reqs, the local management store, the role specifc stuff , request the certificate and assign it and start the services and install network monitor
you need to have the CMS built and a topology published for this script to work!!
Please configure the first 3 variables for your environment.....
##################################################################################################################################
# Please Configure the following variables
$location = "D:\setup\amd64\"
$issuingCA = "dc-01.corp.contoso.com\CorpCA"
$nmloc = "d:\Tools\NM34_x64.exe"
##################################################################################################################################
Start-Transcript
Write-Host "This script will check for the installed components if they do not exist they will install them and reboot the server"
Write-Host "`n`nCheck Windows Pre-Requisites...."
import-module servermanager
$checkinstall = get-windowsfeature RSAT-ADDS, MSMQ, MSMQ-Services, MSMQ-Server, MSMQ-Directory, Web-Server, Web-Scripting-Tools, Web-Windows-Auth, Web-Asp-Net, Web-Log-Libraries, Web-Http-Tracing, Web-Stat-Compression, Web-Default-Doc, Web-ISAPI-Ext, Web-ISAPI-Filter, Web-Http-Errors, Web-Http-Logging, Web-Net-Ext, Web-Client-Auth, Web-Filtering, Web-Mgmt-Console
foreach ($check in $checkinstall)
{
if ($check.installed -eq $false)
{
$testinstall = add-windowsfeature $check
if ($testinstall.restartneeded -eq "Yes")
{
$restart = $true
}
}
}
$osver = Get-WmiObject Win32_OperatingSystem
if ($osver.version -eq "6.1.7600")
{
pkgmgr.exe /quiet /ip /m:"%windir%\servicing\Packages\Microsoft-Windows-Media-Format-Package~31bf3856ad364e35~amd64~~6.1.7600.16385.mum"
}
elseif ($osver.version -eq "6.1.7601")
{
pkgmgr.exe /quiet /ip /m:"%windir%\servicing\Packages\Microsoft-Windows-Media-Format-Package~31bf3856ad364e35~amd64~~6.1.7601.17514.mum"
}
else
{
Write-Host "Unsupported OS... Exiting Script..."
exit 0
}
cls
Write-Host "Installing Visual C Pre-Requisites.."
$visualcinstall = "vcredist_x64.exe"
$installer = $location + $visualcinstall
& "$installer" /q
$installfin = "1"
Write-Host "Waiting For Install To Complete.."
while ($installfin -ne $null)
{
$installfin = get-process | where {$_.processname -eq "vcredist_x64"}
Write-Host "." -NoNewline
}
$verifyinstall = Get-WmiObject Win32_Product |where {$_.IdentifyingNumber -eq "{4B6C7001-C7D6-3710-913E-5BC23FCE91E6}"}
if ($verifyinstall -eq $null)
{
Write-Host "Visual C Components Installation Failed"
}
else
{
Write-Host "Visual C Components Installation Successful!!"
}
Write-Host "Installing SQL Server 2005 Backward Compatibility Components Pre-Requisites.."
$sqlbcinstall = "SQLServer2005_BC.msi"
$installer = $location + $sqlbcinstall
& "$installer" /quiet
$verifyinstall = $null
while ($verifyinstall -eq $null)
{
$verifyinstall = Get-WmiObject Win32_Product |where {$_.IdentifyingNumber -eq "{62D2F823-0EAA-496D-B0F9-A869BFC51550}"}
}
Write-Host "SQL Server 2005 Backward Compatibility Components Installation Successful!!"
Write-Host "Installing SQL Server Native Client Components Pre-Requisites.."
$sqlcliinstall = "sqlncli.msi"
$installer = $location + $sqlcliinstall
& "$installer" /quiet
$verifyinstall = $null
while ($verifyinstall -eq $null)
{
$verifyinstall = Get-WmiObject Win32_Product |where {$_.IdentifyingNumber -eq "{BBDE8A3D-64A2-43A6-95F3-C27B87DF7AC1}"}
}
Write-Host "SQL Server Native Client Components Installation Successful!!"
Write-Host "Installing OCS Core Components Pre-Requisites.."
$extlocation = $location + "setup\"
$ocscoreinstall = "ocscore.msi"
$installer = $extlocation + $ocscoreinstall
& "$installer" /quiet ADDLOCAL=Feature_LocalMgmtStore REBOOT=ReallySuppress
$verifyinstall = $null
while ($verifyinstall -eq $null)
{
$verifyinstall = Get-WmiObject Win32_Product |where {$_.IdentifyingNumber -eq "{9521B708-9D80-46A3-9E58-A74ACF4E343E}"}
write-host "." -nonewline
}
import-module -name 'c:\program files\common files\microsoft lync server 2010\modules\lync'
cls
Write-Host "Installing Local Management Store.."
$progfiles = "C:\Program Files\Microsoft Lync Server 2010\Deployment\"
$bootstrapinstall = "bootstrapper.exe"
$installer = $progfiles + $bootstrapinstall
& "$installer" /BootStrapLocalMgmt /SourceDirectory:$location
Write-Host "Enabling Replication From CMS......."
$config = export-csconfiguration -asbytes
import-csconfiguration -byteinput $config -verbose -localstore
Enable-CSReplica -Verbose
Start-CsWindowsService Replica
Write-Host "Installing Roles defined in Topology Builder.."
& "$installer" /SourceDirectory:$location
Write-Host "Requesting Certificate...."
$certreq = $null
$certreq = Request-CSCertificate -New -Type Default -CA $issuingCA -FriendlyName "Default" -KeySize 2048 -PrivateKeyExportable $True -Organization "HP" -OU "IT"
if ($certreq -ne $null)
{
Write-Host "Assigning Certificate..."
set-cscertificate -type Default -thumbprint $certreq.thumbprint
}
else
{
Write-Host "No Certificate Obtained... Please Debug exiting script..."
exit 0
}
Write-Host "Starting Lync Services...."
Start-CsWindowsService
$timeout = 1000
write-host "Waiting for Services To Start...."
for ($count=0;$count -le $timeout;$count++)
{
$checkstart = get-cswindowsservice
foreach ($check in $checkstart)
{
if ($check.status -ne "Running")
{
write-host "." -nonewline
}
}
}
if ($Count -eq $timeout)
{
write-host "Service did not start in an appropriate amount of time, please investigate logs`n"
$checkstart
}
else
{
write-host "Services started successfully"
}
$localcache = "c:\temp"
Copy-Item $nmloc $localcache
$finalpath = $localcache + "\NM34_x64.exe"
$copycomplete = Test-Path $finalpath
if ($copycomplete -ne $true)
{
Write-Host "Copy Did Not Succeed exiting..."
exit 0
}
& "$finalpath" /q
$installfin = "1"
Write-Host "Waiting For Install To Complete.."
while ($installfin -ne $null)
{
$installfin = get-process | where {$_.processname -eq "NM34_x64"}
Write-Host "." -NoNewline
}
$verifyinstall = Get-WmiObject Win32_Product |where {$_.Name -eq "Microsoft Network Monitor 3.4"}
if ($verifyinstall -eq $null)
{
Write-Host "Product Installation Failed"
}
else
{
Write-Host "Product Installation Successful!!"
}
stop-transcript
Comments
Anonymous
January 01, 2003
cool... thanks for the share will play with it in my lab! and report the script..Anonymous
February 14, 2012
You don´t need to use while loop to install software. You can use Start-Process -wait and -PassThru parameters and capture the return code - depsharee.blogspot.com/.../how-to-install-software-with-powershell.html