简体   繁体   中英

Copy running IIS App Pool with Powershell WebAdministration

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?

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 :)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM