Forked from serdarb/Download and Install MongoDB as Windows Service PowerShell Script
Created
March 6, 2013 21:21
-
-
Save tugberkugurlu/5103195 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Set-ExecutionPolicy RemoteSigned | |
$mongoDbPath = "C:\MongoDB" | |
$mongoDbConfigPath = "$mongoDbPath\mongod.cfg" | |
$url = "http://downloads.mongodb.org/win32/mongodb-win32-x86_64-2008plus-2.2.3.zip" | |
$zipFile = "$mongoDbPath\mongo.zip" | |
$unzippedFolderContent ="$mongoDbPath\mongodb-win32-x86_64-2008plus-2.2.3" | |
if ((Test-Path -path $mongoDbPath) -eq $True) | |
{ | |
write-host "Seems you already installed MongoDB" | |
exit | |
} | |
md $mongoDbPath | |
md "$mongoDbPath\log" | |
md "$mongoDbPath\data" | |
md "$mongoDbPath\data\db" | |
[System.IO.File]::AppendAllText("$mongoDbConfigPath", "dbpath=C:\MongoDB\data`r`n") | |
[System.IO.File]::AppendAllText("$mongoDbConfigPath", "logpath=C:\MongoDB\log\mongo.log") | |
$webClient = New-Object System.Net.WebClient | |
$webClient.DownloadFile($url,$zipFile) | |
$shellApp = New-Object -com shell.application | |
$destination = $shellApp.namespace($mongoDbPath) | |
$destination.Copyhere($shellApp.namespace($zipFile).items()) | |
Copy-Item "$unzippedFolderContent\*" $mongoDbPath -recurse | |
Remove-Item $unzippedFolderContent -recurse -force | |
Remove-Item $zipFile -recurse -force | |
& $mongoDBPath\bin\mongod.exe --config $mongoDbConfigPath --install | |
& net start mongodb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment