Reputation: 5231
I am trying to copy an existing IIS 7.5 app pool using the Powershell WebAdministration module without stopping the application.
When I copy the app pool, with an application running and loaded, I receive a NullReferenceException.
$pool = 'app1-0'
$newpool = 'app1-1'
cp "iis:/apppools/$pool" "iis:/apppools/$newpool" -force
Output:
Copy-Item : Object reference not set to an instance of an object.
If I stop the pool, or start the app pool and do not load the application, the copy command succeeds.
Short of copying the properties one by one, is there a way to copy/clone a running, and loaded, app pool?
Upvotes: 4
Views: 6022
Reputation: 41
To export the application pool use %windir%\system32\inetsrv\appcmd list apppool "AppPoolName" /config /xml > D:\AppPoolConfig.xml
Without the /config you're missing all of the settings within the application pool and when you go to import that you're only going to create a new application pool with default application pool settings.
Upvotes: 4
Reputation: 7499
Have you tried using appcmd instead?
Update: try a combination of both -
Maybe add doesn't let you both import and specify commands. You could try something like this:
appcmd list appool thing1 /xml > c:\tempfile.xml
(Get-Content c:\tempfile.xml).Replace("thing1", "thing2") | Out-File c:\tempfile2.xml
appcmd add apppool /in < c:\tempfile2.xml
You may have to debug that script a bit :)
Upvotes: 4