learning...
learning...

Reputation: 3174

PowerShell pointing the site to new location.

I can get the current location as

#Connect to webserver1 or webserver2 to find the current location of site, this depends upon powershell remoting being enabled
    $Session = New-PSSession -ComputerName $ServerName

    Invoke-Command -Session $Session {Add-PSSnapin WebAdministration}
    Invoke-Command -Session $Session {Set-Location IIS:\}
    $CurrentLocation = Invoke-Command -Session $Session {Get-WebFilePath 'IIS:\Sites\Staging'}

    $LogMessage = "Staging site currently located at: " + $CurrentLocation
    write-host "##teamcity[message text='$LogMessage']"

I have posted my changes to

$dirname = "\\" + $ServerName + "\d$\inetpub\Staging\Mvc-" + $today.ToString("yyyyMMdd")

How can i set this new location to be the site location?

Thanks.

Upvotes: 1

Views: 335

Answers (1)

Raf
Raf

Reputation: 10107

Try this:

$Session = New-PSSession -ComputerName $ServerName
$dirname = "\\" + $ServerName + "\d$\inetpub\Staging\Mvc-" + $today.ToString("yyyyMMdd")
Invoke-Command -Session $Session -ScriptBlock{
    param($dirname)
    Add-PSSnapin WebAdministration 
    Set-ItemProperty 'IIS:\Sites\Staging' -Name physicalPath -Value $dirname        
}  -ArgumentList $dirname

Upvotes: 2

Related Questions