Setting IIS config via appcmd.exe for Load User Profile - iis

I am attempting to set the config setting for 'Load User Profile' to true via a powershell script using appcmd.exe. After reading through many documents I cannot figure out the correct syntax.
The app pool's name is like 'accountsmanagement.example.com' I have tried variations on the following but all error out:
c:\Windows\system32\inetsrv\appcmd.exe set config -section:applicationPools /accountsmanagement.example.com.processModel.loadUserProfile:true
How do I correctly set the Load User Profile to true via appcmd.exe?

If you want to purely use PowerShell you can use the following PowerShell command to change the 'Load User Profile' property of an application pool.
Import-Module WebAdministration
Set-ItemProperty "IIS:\AppPools\YourAppPoolName" -Name "processModel.loadUserProfile" -Value "False"

Try this with quotes.
c:\windows\system32\inetsrv\appcmd.exe set config -section:applicationPools "/[name='accountsmanagement.example.com'].processModel.loadUserProfile:false"

Instead of using appcmd.exe set config you can also use the following
appcmd.exe set apppool "App Pool name here" -processmodel.loaduserprofile:"true"
To show all values that can be set use
appcmd.exe set apppool "App Pool name here" /?

Related

Azure staticwebapp not allowing to add config with "&" in value using Azure CLI in terminal

I am using Azure CLI to use the azure. I am trying to create a staticwebapp and later try to add the configuration from CLI.
I tried to run this
az staticwebapp appsettings set -n appname --setting-names MONGO_CONNECTION_STRING="mongodb+srv://anirudha:testing#cluster4340.v45343.mongodb.net/?retryWrites=true&w=majority"
I am getting error
'w' is not recognized as an internal or external command,
operable program or batch file.
I go to portal and seen before &w=majority is added into configuration but this part is not added after &.
I tried to put singlequote and key=("val") but none of them working for me. I found this in azure app config github repo.
Anyone have idea how to make it work from CLI
--setting-names property accepts the app settings in 'key=value' format as mentioned here in this documentation of az staticwebapp app settings set cmdlet.
You need to change the above shared cmdlet to the below:
az staticwebapp appsettings set -n <staticWebAppName> --setting-names 'MONGO_CONNECTION_STRING=<AppsettingValue>'
I have tested this and it is working fine from my end Here is the sample output screenshot for your reference:
Updated Answer:
Alternatively, you can use this PowerShell cmdlet
(New-AzStaticWebAppSetting) to update the app settings of the static web app
New-AzStaticWebAppSetting -ResourceGroupName resourceGroup -Name staticweb01 -AppSetting #{'function01' = 'value01'; 'function02' = 'value02' }

Recycle all application pools at a specific time

How do I set the recycling for a specific time for all of my current and future application pools in the IIS Manager.
I have tried to achieve this by going under Set Application Pool Defaults -> Recycling -> Specific Times, but this doesn't affect already created application pools.
Is there any way to achieve this - maybe with some kind of PowerShell script ?
You could use below PowerShell script to set the application pool recycling time for all the application pool:
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.applicationHost/applicationPools/applicationPoolDefaults/recycling/periodicRestart" -name "time" -value "1.08:00:00"
using the command line:
appcmd.exe set config -section:system.applicationHost/applicationPools /applicationPoolDefaults.recycling.periodicRestart.time:"1.08:00:00" /commit:apphost
to set periodic restart value:
appcmd.exe set config -section:system.applicationHost/applicationPools /+"applicationPoolDefaults.recycling.periodicRestart.schedule.[value='07:55:00']" /commit:apphost
command line:
Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.applicationHost/applicationPools/applicationPoolDefaults/recycling/periodicRestart/schedule" -name "." -value #{value='07:55:00'}

How to start/stop IIS Website and application pool on another server while deploying my project through Bamboo?

Currently I am using this Powershell script which runs before deployment script.
$Password=Convertto-SecureString -String ${bamboo.deploy.password} -AsPlainText -force
$Credentials=New-object System.Management.Automation.PSCredential ${bamboo.deploy.username},$Password
Enter-PSSession -ComputerName ${Server} -Credential $Credentials
Invoke-Command -ScriptBlock {start cmd;cd C:\Windows\System32\inetsrv;appcmd stop apppool /apppool.name:"${app_pool_name}"}
But it gives the following error:
The term 'appcmd' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
I have also tried using the Stop-WebAppPool cmdlet. It also gave an error saying Stop-WebAppPool is not recognized as the name of any cmdlet. I have also tried Import-Module WebAdministration before Stop-WebAppPool cmdlet. It also was not successful.
Edit: When I use the same script from my localhost, it works successfully. When I use this script on BAMBOO, it gives the above mentioned error. Is it possible that the WebAdministration Module is not installed on the agent's environment or Bamboo server?
Make sure you enabled IIS Management Scripts and Tools feature of iis.
you could try these steps:
1. Open Turn Windows features on or off.
Enable IIS Management Scripts and Tools under “Internet Information Services” => “Web Management Tools”.
We will see the appcmd.exe in C:\Windows\System32\inetsrv folder then.
Add C:\Windows\System32\inetsrv to PATH system environment variable.

Get Azure HybridWorker Environement Variable in Powershell

I have an Azure Powershell Runbook which is used to invoke a java jar inside the Hybrid Worker Groups.
Currently we pass the absolute java path and run the program, Iwant to change this and pass JAVA_HOME instead. I have set java home as environment variable and is able to access inside the hybrid worker.
$java = $Env:JAVA_HOME
Write-Output "$java"
this give the right path when ran inside the hybrid.
When passing this value via runbook it is not returning any value. The Write-Output returns empty when running via Automation Runbooks
$java = $Env:JAVA_HOME
Write-Output "$Env:JAVA_HOME"
$arguments = "-cp C:\\prgm\jws\jar\jwsClient-0.0.1.jar"
$p = Start-Process -FilePath $java -ArgumentList $arguments
Any help is appreciated.
Just a suggestion. Based on my experience, JAVA_HOME is usually used to store JDK path while in development. And to run a jar, we just need JRE.
But, I am not sure how Azure runbook sets its environment variables. You can output all environment variables as following:
Get-ChildItem env:* | sort-object name
If you know which variable stores the path of JRE, you may retrieve it with script then.

Powershell command to set IIS logging settings

I'm creating a powershell script so I can create website hosting with a single command using the IIS Powershell Management Console.
I have the commands I need to create the IIS Site and add bindings for the domain names etc...
The one piece of the puzzle I'm missing though is how to change the default Logging directory from %SystemDrive%\inetpub\logs\LogFiles to my own folder that's not on the boot drive of the server.
After extensive searching I expected to find a command along the lines of the following pseudo powershell
New-ItemProperty IIS:\Sites\MyNewSite -name logging -value #{format='W3C';directory='d:\sites\site\logs';encoding=UTF-8}
Please could you show me with an example how you change the logging folder in the IIS Powershell Management Console
Thanks in advance
Import-Module WebAdministration
Set-WebConfigurationProperty "/system.applicationHost/sites/siteDefaults" -name logfile.directory -value $logdir
While testing the answer from this thread, toggling options via IIS Manager and PowerShell, I stumbled on something that has been hidden to me. In IIS Manager, choosing Configuration Editor and making a change, allows the IIS Manager to generate and display the script for the change in C#, JavaScript, AppCmd.exe and PowerShell. Just click the Generate Script option.
[]
For changing an individual web site's logFile configuration, the original post was nearly correct. Instead of New-ItemProperty, use Set-ItemProperty, like so...
Set-ItemProperty "IIS:\Sites\$SiteName" -name logFile -value #{directory=$LogPath}
For changing the server-wide default settings, see Andy Schneider's answer.
For more information about the options available, see this IIS.net article.
This works as well, using the WebAdministration Module
Import-Module WebAdministration
$site = gi IIS:\Sites\MyNewSite
$site.Logging.format='W3C'
$site.Logging.directory='d:\sites\site\logs'
$site.Logging.encoding=UTF-8
$site | set-item
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration")
$iis = new-object Microsoft.Web.Administration.ServerManager
$web = $iis.Sites["test"]
#set new logpath, must be existing
$web.LogFile.Directory = "F:\Logfiles\"
$iis.CommitChanges()
If you host multiple sites on a single server and want them to all log to the same log file, the process is quite different. It took some digging to find clues here and here, so I thought I would leave a description behind for anyone else with this need.
The following two statements will combine logs for all of your websites into a folder e:\log\w3svc.
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter 'system.applicationHost/log' -name CentralLogFileMode -Value 'CentralW3C'
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter 'system.applicationHost/log' -name centralW3CLogFile.directory -value 'e:\log'

Resources