Forum Discussion

janten's avatar
janten
Copper Contributor
Nov 15, 2019

Export-IISConfiguration and Invoke-command

My goal is to export the IIS configuration from a remote server to a share.

When I run the following command locally, the configuration is exported

 

if(!(Test-path -path "\\path\to\share\*")){export-iisconfiguration -physicalpath "\\path\to\share" -KeyEncryptionPassword (ConvertTo-SecureString -AsPlainText -String 'verysecurepassword' -Force)}

 

However, when I add Invoke-Command to the mix

 

Invoke-Command -Session $session -ScriptBlock {if(!(Test-path -path "\\path\to\share\*")){export-iisconfiguration -physicalpath "\\path\to\share\" -KeyEncryptionPassword (ConvertTo-SecureString -AsPlainText -String 'verysecurepassword' -Force)}}


I get the following result:

 

Export of configuration files failed.
+ CategoryInfo : NotSpecified: (:) [Export-IISConfiguration], Exception
+ FullyQualifiedErrorId : System.Exception,Microsoft.IIS.Powershell.Commands.ExportIISConfiguration
+ PSComputerName : tst-web01

 

What's the best (or any) way to solve this issue?

 

1 Reply

  • T_rey_S's avatar
    T_rey_S
    Copper Contributor
    You may be suffering from "second hop syndrome". When you remote to ServerA, from Workstation1, you lose the ability to access other computers, depending on domain security settings. The general topic is "delegation" and whether it is allowed, and then properly configured.
    What I have done, in an environment not allowing delegation, is to "stage" the information, on ServerA with a remote script, or invoke-command, then retrieve file, from ServerA, with code running on Workstation1. Then Workstation1 can copy it to your final destination.