I\'m currently working on a deployment script that will take my site, export it from svn, remove any testing files etc in it, minify the javascript/css, copy the code to a remot
I'd like to build on top of @Kev's post.
You can use his method locally, but as he says there's no real way of providing credentials for his commented-out method of remotely connecting:
$serverManager = [Microsoft.Web.Administration.ServerManager]::OpenRemote($serverIP)
#configure your remote credentials
$computerName = "remotehostname"
$securePassword = ConvertTo-SecureString "password" -AsPlainText -force
$credential = New-Object System.Management.Automation.PsCredential("username", $securePassword)
#remove –SkipCACheck –SkipCNCheck –SkipRevocationCheck if you don't have any SSL problems when connecting
$options = New-PSSessionOption –SkipCACheck –SkipCNCheck –SkipRevocationCheck
$session = New-PSSession -ComputerName $computerName -Authentication Basic -Credential $credential -UseSSL -SessionOption $options
$block = {
[Void][Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration")
$siteName = "Default Web Site"
$serverIP = "your ip address"
$newPath = "your new path"
$serverManager = New-Object Microsoft.Web.Administration.ServerManager
$site = $serverManager.Sites | where { $_.Name -eq $siteName }
$rootApp = $site.Applications | where { $_.Path -eq "/" }
$rootVdir = $rootApp.VirtualDirectories | where { $_.Path -eq "/" }
$rootVdir.PhysicalPath = $newPath
$serverManager.CommitChanges()
}
#run the code in $block on your remote server via the $session var
Invoke-Command -Session $session -ScriptBlock $block
Note: For remote PowerShell scripting, ensure TCP ports 5985 and 5986 are open outbound on your local network and inbound on your remote server.