1

I have the command which exports websites of the current logged in server (as below). I need the command to export websites of a different server.

%windir%\system32\inetsrv\appcmd list site /config /xml > c:\websites.xml

AnupDharia
  • 21
  • 1
  • 5

1 Answers1

3

try with Invoke-Command

Note the syntax you have is for a dos command. The following should get you on track. Of course there is credentials you may have to pass in.

Remoting must be enabled on the remote servers Run Enable-PSRemoting -Force on each server.

Invoke-Command -Computer remoteserver -ScriptBlock { 
    & $Env:Windir\system32\inetsrv\appcmd.exe list site /config /xml
} | Out-File c:\websites.xml -Append

Note that the 'powershell' way of getting sites as powershell objects is shown here: https://stackoverflow.com/a/25091831/1165140

Community
  • 1
  • 1
Avner
  • 4,286
  • 2
  • 35
  • 42
  • Thank you, @avvi I kind of figured it out later. I used the PSSession command to establish the connection to the remote server and executed the Invoke-Command as you have mentioned. ` Enter-PSSession $SourceServerName Invoke-Command -ComputerName $SourceServerName -FilePath $ExtractWebsiteScriptPath -ArgumentList $WebServerTemplateXML,$SourceServerName,$DestinationServerName Exit-PSSession` – AnupDharia Mar 17 '17 at 19:36
  • New to stackoverflow, so please don't mind the formatting – AnupDharia Mar 17 '17 at 19:43