Export-IISConfiguration and Invoke-command

%3CLINGO-SUB%20id%3D%22lingo-sub-1010882%22%20slang%3D%22en-US%22%3EExport-IISConfiguration%20and%20Invoke-command%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1010882%22%20slang%3D%22en-US%22%3E%3CP%3EMy%20goal%20is%20to%20export%20the%20IIS%20configuration%20from%20a%20remote%20server%20to%20a%20share.%3C%2FP%3E%3CP%3EWhen%20I%20run%20the%20following%20command%20locally%2C%20the%20configuration%20is%20exported%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eif(!(Test-path%20-path%20%22%5C%5Cpath%5Cto%5Cshare%5C*%22))%7Bexport-iisconfiguration%20-physicalpath%20%22%5C%5Cpath%5Cto%5Cshare%22%20-KeyEncryptionPassword%20(ConvertTo-SecureString%20-AsPlainText%20-String%20'verysecurepassword'%20-Force)%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHowever%2C%20when%20I%20add%20Invoke-Command%20to%20the%20mix%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EInvoke-Command%20-Session%20%24session%20-ScriptBlock%20%7Bif(!(Test-path%20-path%20%22%5C%5Cpath%5Cto%5Cshare%5C*%22))%7Bexport-iisconfiguration%20-physicalpath%20%22%5C%5Cpath%5Cto%5Cshare%5C%22%20-KeyEncryptionPassword%20(ConvertTo-SecureString%20-AsPlainText%20-String%20'verysecurepassword'%20-Force)%7D%7D%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EI%20get%20the%20following%20result%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EExport%20of%20configuration%20files%20failed.%3CBR%20%2F%3E%2B%20CategoryInfo%20%3A%20NotSpecified%3A%20(%3A)%20%5BExport-IISConfiguration%5D%2C%20Exception%3CBR%20%2F%3E%2B%20FullyQualifiedErrorId%20%3A%20System.Exception%2CMicrosoft.IIS.Powershell.Commands.ExportIISConfiguration%3CBR%20%2F%3E%2B%20PSComputerName%20%3A%20tst-web01%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat's%20the%20best%20(or%20any)%20way%20to%20solve%20this%20issue%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1010882%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Occasional Visitor

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?

 

0 Replies