Export-IISConfiguration and Invoke-command

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