PS script help

13 views
Skip to first unread message

Dave Lum

unread,
Jul 2, 2026, 11:26:07 AM (12 days ago) Jul 2
to ntsys...@googlegroups.com

I am looking to use PowerShell to change IIS pool identities.  I have 20 app pools and I’d like the $appPoolName part be able to cycle thorough values in a TXT file so the credentials get applied to whatever app pool names I have in the TXT file.  The Application Pool names aren’t consistent enough for me to just use a filter on the name so a TXT file is the more reliable route here.

$appPoolName = "AppPool_1"

$username = "DOMAIN\ACCOUNT$"

 

# Apply the custom identity credentials

Set-ItemProperty "IIS:\AppPools\$appPoolName" -Name processModel -Value @{

    identityType = 3;

    userName = $username;

  

}

 

TIA,

Dave Lum (he/him)

Systems Administrator
Work hours: Tues – Fri 5:30a – 4:30p Pacific
P:
503.546.2163
E: lu...@ochin.org

Facebook LinkTwitter LinkLinkedin Link www.ochin.org
OCHIN email

 

Attention: Information contained in this message and or attachments is intended only for the recipient(s) named above and may contain confidential and or privileged material that is protected under State or Federal law. If you are not the intended recipient, any disclosure, copying, distribution or action taken on it is prohibited. If you believe you have received this email in error, please contact the sender with a copy to compl...@ochin.org, delete this email and destroy all copies.

Solodow, Damien

unread,
Jul 2, 2026, 11:31:42 AM (12 days ago) Jul 2
to ntsys...@googlegroups.com

Are you planning on using the same username for all of the app pools you want to change?

 

Gaylor Electric logo

Facebook logo

Instagram logo

LinkedIn logo

X logo

YouTube logo

Damien Solodow
IT Engineering Manager

Gaylor Electric, Inc.
10405 Crosspoint Blvd
Indianapolis, IN. 46256
O: 317.815.3103 | M: 317.506.8521

--
You received this message because you are subscribed to the Google Groups "ntsysadmin" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ntsysadmin+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/ntsysadmin/DM8PR17MB4918A37B41DD24FB160FAA72DDF52%40DM8PR17MB4918.namprd17.prod.outlook.com.

Michael B. Smith

unread,
Jul 2, 2026, 11:35:49 AM (12 days ago) Jul 2
to ntsys...@googlegroups.com

You know that “Get-ChildItem IIS:\AppPools” returns all appPools (including their name)?

 

(I understand that you might still just want to update certain appPools – just askin’)

 

From: 'Dave Lum' via ntsysadmin <ntsys...@googlegroups.com>
Sent: Thursday, July 2, 2026 11:26 AM
To: 'ntsys...@googlegroups.com' <ntsys...@googlegroups.com>
Subject: [ntsysadmin] PS script help

 

I am looking to use PowerShell to change IIS pool identities.  I have 20 app pools and I’d like the $appPoolName part be able to cycle thorough values in a TXT file so the credentials get applied to whatever app pool names I have in the TXT file.  The Application Pool names aren’t consistent enough for me to just use a filter on the name so a TXT file is the more reliable route here.

$appPoolName = "AppPool_1"

--

Dave Lum

unread,
Jul 2, 2026, 11:58:39 AM (12 days ago) Jul 2
to ntsys...@googlegroups.com

Yes

 

From: ntsys...@googlegroups.com <ntsys...@googlegroups.com> On Behalf Of Solodow, Damien
Sent: Thursday, July 2, 2026 8:32 AM
To: ntsys...@googlegroups.com
Subject: [ntsysadmin] RE: PS script help

 

CAUTION: This email originated from outside of OCHIN’s network

Do not click links or open attachments unless you recognize the sender and know the content is safe. If you suspect this email is phishing or a scam, use the report button in the Outlook toolbar to report it to Desktop Support.

 

Dave Lum

unread,
Jul 2, 2026, 11:59:26 AM (12 days ago) Jul 2
to ntsys...@googlegroups.com

Yep.  I do that, drop to a file and them remove the pools I don’t want to change.

 

From: ntsys...@googlegroups.com <ntsys...@googlegroups.com> On Behalf Of Michael B. Smith
Sent: Thursday, July 2, 2026 8:36 AM
To: ntsys...@googlegroups.com
Subject: [ntsysadmin] RE: PS script help

 

CAUTION: This email originated from outside of OCHIN’s network

Do not click links or open attachments unless you recognize the sender and know the content is safe. If you suspect this email is phishing or a scam, use the report button in the Outlook toolbar to report it to Desktop Support.

 

You know that “Get-ChildItem IIS:\AppPools” returns all appPools (including their name)?

Dave Lum

unread,
Jul 2, 2026, 12:03:34 PM (12 days ago) Jul 2
to ntsys...@googlegroups.com

This is what I have so far, but I get Cannot find path 'IIS:\AppPools\MyAppPool1 because it does not exist.  If I remove the foreach parts and run the script replacing the $inputs line with $appPoolName = "MyAppPool1", it works.


$inputs = Get-Content -Path "C:\Automate\Reports\IISAppPools.txt"

$username = "DOMAIN\ACCOUNT"

 

foreach ($appPoolName in $inputs) {

    # Process each line here

    Write-Output "Processing: $appPoolName"

      

 

Stop-WebAppPool -Name $appPoolName

 

Start-Sleep -Seconds 10

 

# Apply the custom identity credentials

Set-ItemProperty "IIS:\AppPools\$appPoolName" -Name processModel -Value @{

    identityType = 3;

    userName = $username;

  

}

 

Start-WebAppPool -Name $appPoolName

 

}

Dave

From: ntsys...@googlegroups.com <ntsys...@googlegroups.com> On Behalf Of Michael B. Smith
Sent: Thursday, July 2, 2026 8:36 AM
To: ntsys...@googlegroups.com
Subject: [ntsysadmin] RE: PS script help

 

CAUTION: This email originated from outside of OCHIN’s network

Do not click links or open attachments unless you recognize the sender and know the content is safe. If you suspect this email is phishing or a scam, use the report button in the Outlook toolbar to report it to Desktop Support.

 

You know that “Get-ChildItem IIS:\AppPools” returns all appPools (including their name)?

Solodow, Damien

unread,
Jul 2, 2026, 12:07:39 PM (12 days ago) Jul 2
to ntsys...@googlegroups.com

Does the write-output have the right app pool name, and does it successfully stop the app pool?

What I’d try is this change to the set-itemproperty line:

 

Set-ItemProperty "IIS:\AppPools\$($appPoolName)" -Name processModel -Value @{

 

 

Gaylor Electric logo

Facebook logo

Instagram logo

LinkedIn logo

X logo

YouTube logo

Damien Solodow
IT Engineering Manager

Gaylor Electric, Inc.
10405 Crosspoint Blvd
Indianapolis, IN. 46256
O: 317.815.3103 | M: 317.506.8521

 

Dave Lum

unread,
Jul 2, 2026, 12:27:36 PM (12 days ago) Jul 2
to ntsys...@googlegroups.com

In the script without foreach the correct app name is displayed and the app pool does stop. Wrapping foreach in there I get “object not found”.

My export command is Get-ChildItem -Path IIS:\AppPools\ | Select-Object name | Format-Table -AutoSize and it lists the app pools, and the TXT file has just the name property for each pool in it.

Dave

Wright, John M

unread,
Jul 2, 2026, 12:31:42 PM (12 days ago) Jul 2
to ntsys...@googlegroups.com

From what you’re saying, I would think there was something wrong with the string—except that it seems to be failing for you at Set-ItemProperty while succeeding at Stop-WebAppPool.  And if it works when you hard-code the variable, it can’t be what prepends it on the path for Set-ItemProperty.

 

So a wild guess.  What do you get from the following?

 

$content = Get-Content -Path "C:\Automate\Reports\IISAppPools.txt"

$content[0].gettype()

 

--

John Wright

IT Support Specialist

1800 Old Bluegrass Avenue, Louisville, KY 40215

502.708.9953

Please submit IT requests to Hazelwoo...@bluegrass.org

24 Hour Helpline 1.800.928.8000

  

CONFIDENTIALITY NOTICE: This message contains confidential information and is intended only for the individual(s) addressed in the message. If you are not the named addressee, you should not disseminate, distribute, or copy this e-mail. If you are not the intended recipient, you are notified that disclosing, distributing, or copying this e-mail is strictly prohibited.

 

From: 'Dave Lum' via ntsysadmin <ntsys...@googlegroups.com>
Sent: Thursday, July 2, 2026 12:03 PM
To: ntsys...@googlegroups.com
Subject: [ntsysadmin] RE: PS script help

 

EXTERNAL EMAIL - This email was sent by a person from outside your organization. Exercise caution when clicking links, opening attachments or taking further action, before validating its authenticity.

Secured by Check Point

Wright, John M

unread,
Jul 2, 2026, 12:34:38 PM (12 days ago) Jul 2
to ntsys...@googlegroups.com

I’m thinking it’s the data type:

 

(Get-ChildItem -Path IIS:\AppPools\ | Select-Object name | Format-Table -AutoSize)[0].gettype()

 

IsPublic IsSerial Name                                     BaseType

-------- -------- ----                                     --------

False    False    FormatStartData                          Microsoft.PowerShell.Commands.Internal.Format.StartData

 

 

Probably work if you export like:   (Get-ChildItem -Path IIS:\AppPools\ | Select-Object name | Format-Table -AutoSize).name

--

John Wright

IT Support Specialist

1800 Old Bluegrass Avenue, Louisville, KY 40215

502.708.9953

Please submit IT requests to Hazelwoo...@bluegrass.org

24 Hour Helpline 1.800.928.8000

  

CONFIDENTIALITY NOTICE: This message contains confidential information and is intended only for the individual(s) addressed in the message. If you are not the named addressee, you should not disseminate, distribute, or copy this e-mail. If you are not the intended recipient, you are notified that disclosing, distributing, or copying this e-mail is strictly prohibited.

 

From: 'Dave Lum' via ntsysadmin <ntsys...@googlegroups.com>
Sent: Thursday, July 2, 2026 12:27 PM
To: ntsys...@googlegroups.com
Subject: [ntsysadmin] RE: PS script help

 

EXTERNAL EMAIL - This email was sent by a person from outside your organization. Exercise caution when clicking links, opening attachments or taking further action, before validating its authenticity.

Secured by Check Point

 

In the script without foreach the correct app name is displayed and the app pool does stop. Wrapping foreach in there I get “object not found”.

Dave Lum

unread,
Jul 2, 2026, 12:35:25 PM (12 days ago) Jul 2
to ntsys...@googlegroups.com

PS C:\WINDOWS\system32> $content = Get-Content -Path "C:\Automate\Reports\IISAppPools.txt"

$content[0].gettype()

 

IsPublic IsSerial Name                                     BaseType                                                                      

-------- -------- ----                                     --------                                                                       

True     True     String                                   System.Object  

Reply all
Reply to author
Forward
0 new messages