Question

I in the process of building a ps1 file to create all my IIS site(s), Virtual Directories and app pools via appcmd. I have used the appcmd list /xml to get the settings from the master machine and saved them into config files. What I am trying to get powershell to execute an appcmd command

  appcmd add apppool /IN < pathtoFile.xml

my issue is within powershell is I can not use the less than symbol:

PS C:\temp\deployments> .\createIISSetup.ps1
The '<' operator is reserved for future use.
At C:\temp\deployments\createIISSetup.ps1:36 char:28
+     .$appcmd add apppool /IN < <<<<  $pathToAppPoolSettings;
    + CategoryInfo          : ParserError: (<:OperatorToken) [], ParseException
    + FullyQualifiedErrorId : RedirectionNotSupported

if I use the pipe:

  appcmd add apppool /IN | pathtoFile.xml

I get:

PS C:\temp\deployments> .\createIISSetup.ps1
Expressions are only allowed as the first element of a pipeline.
At C:\temp\deployments\createIISSetup.ps1:36 char:51
+     .$appcmd add apppool /IN | $pathToAppPoolSettings <<<< ;
    + CategoryInfo          : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : ExpressionsMustBeFirstInPipeline
Was it helpful?

Solution

A colleague gave me the answer for this. Just spun it on its head:

type $pathToapppoolSettings | .$appcmd add apppool/IN; 

this works great.

OTHER TIPS

Get-Content appppols.xml | .\appcmd.exe add apppool /in
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top