How do I get the specific value from configuration in IIS 8.0 (and above) using appcmd? - windows

I am using IIS 8.5 and I need a getter for a specific property from configuration.
For example, in order to set connectionTimeout property I am using the following syntax :
appcmd.exe set config -section:system.applicationHost/sites /siteDefaults.limits.connectionTimeout:"00:04:00" /commit:apphost
but when I am trying to read the proprety by the following command:
appcmd.exe list config -section:system.applicationHost/sites /siteDefaults.limits.connectionTimeout
I get the following error:
ERROR ( message:The attribute "siteDefaults.limits.connectionTimeout"
is not supported in the current command usage. )
and from what I tried so far it seems that list config command can give me only the section level and not further.
Is there any other way to get a specific property using appcmd?

If Powershell is an acceptable alternative for you, then you can use the WebAdministration Powersell module to get the timeout. Here is a simple script :
#import WebAdministration to access IIS configuration
Import-Module WebAdministration
#declare variables containing your filters
$pspath = "MACHINE/WEBROOT/APPHOST"
$filter = "system.applicationHost/sites/siteDefaults/limits"
$name = "connectionTimeout"
#Read timeout from IIS
$res = Get-WebConfigurationProperty -name $name -filter $filter -pspath $pspath
#Format & write output
Write-Host "Timeout (in seconds): " $res.Value.TotalSeconds -ForegroundColor Yellow
You probably need to run it as admin.
Here is the output:

You can get this using /text:
appcmd.exe list config -section:system.applicationHost/sites /text:siteDefaults.limits.connectionTimeout
if you want to get all possible options for /text: use the following code:
appcmd.exe list config -section:system.applicationHost/sites /text:?

Related

Windows Audit Policy/Registry Key Command Check To Only Apply On Domain Controllers

I am trying to craft a command that would run against all of my Windows machines to check if the "Audit Distribution Group Management" audit policy setting is set to "Success and Failure". I would only like to apply this check to Domain Controller servers and for any other server type to echo out something like "NoCheckRequired", is this possible?
I tried to create an if-else statement on PowerShell for this, but it was not successful.
I tried to use the "wmic.exe ComputerSystem get DomainRole" command to find out the type of machine, values 4 / 5 mean DC server from my understanding, and using an IF statement, I tried to match those values and check if the group policy audit settings were set and for any other values returned other than 4 / 5
wmic.exe ComputerSystem get DomainRole outputs the property name on a separate line before outputting the actual value, so comparing to the number 4 (as an example) will not work.
Instead, use the Get-CimInstance cmdlet:
$CS = Get-CimInstance Win32_ComputerSystem
if($CS.DomainRole -in 4,5){
# We're on a Domain Controller
}
elseif($CS.DomainRole -in 1,3) {
# We're on a Domain member
}
else {
# We're on a workgroup machine
}
Get-ADComputer -Filter 'primarygroupid -eq "516"'
Will filter the Domain controller

How to format CCM_UserAffinity output to tyoe Microsoft.PowerShell.Commands.LocalPrincipal

I am trying to create a deployment script which adds freshly deployed workstation primary users to local admin group. I utilized CCM_userAffinity class to obtain username, however - Add-LocalGroupMember does not accept its output.
Ive tried creating task sequence variable to pass into powershell script which adds to group with no success either. Preferably the solution would be integrated within deployment TS, however due to no success i have reverted to ps package deployment.
$computer = "LocalHost"
$namespace = "root\ccm\Policy\Machine"
$query = "ConsoleUser"
$PrimaryUser = Get-WmiObject -class CCM_UserAffinity -computername $computer -namespace $namespace | select-object $query | format-wide
i expected the output from -class CCM_UserAffinity to be accepted by Add-LocalGroupMember, however i get this instead -
Add-LocalGroupMember : Cannot bind parameter 'Member'. Cannot convert the "Microsoft.PowerShell.Commands.Internal.Format.FormatStartData" value of type
"Microsoft.PowerShell.Commands.Internal.Format.FormatStartData" to type "Microsoft.PowerShell.Commands.LocalPrincipal".
As you plan on using the value you retrieve and not displaying it there is no need to use something like "format-wide" which only makes the output human readable and is the reason for your FormatStartData datatype.
You can just use :
$PrimaryUser = (Get-WmiObject -class CCM_UserAffinity -computername $computer -namespace $namespace).ConsoleUser
which returns a string and that is taken by the -Member argument of Add-LocalGroupMember
One thing to keep in mind is that in theory there can be more than one ConsoleUser per machine. So the ConsoleUser might be an Array or not. If you can guarantee that there is always only one user in your environment per machine (at the point where the ts runs) you can just use it as is. Otherwise you would have to specify which user you want to use and I can of course not tell you what a good rule for that for your environment would be.
Also I hope you checked that the WMI class CCM_UserAffinity is already populated at the stage where you want to run this script, I could not tell you if this is the case.

Change JVM logs path use jython

I would like to change path JVM logs in WebSphere 8.5.5.
Via GUI in: Logging and tracing > NorkomServer > JVM Logs.
There is:
Information required File Name:
${SERVER_LOG_ROOT}/SystemOut.log
I have to change it to: "/opt/logs/SystemOut.log"
Instead use "sed", i must use jython. Any help, please ?
You can run the below wsadmin script (with -lang jython) to update the default file path for SystemOut.log file.
#Update the below Environment variables before running this script
#Enter the nodename below
nodename=''
#Enter the servername below
servername=''
#Set the updated file path below
filename='/opt/logs/SystemOut.log'
#Set the Stream name
#outputStreamRedirect for SystemOut & errorStreamRedirect for SystemError
streamName = 'outputStreamRedirect'
#get the server Id
serverId = AdminConfig.getid('/Cell:/Node:'+nodename+'/Server:'+servername+'')
#get the Stream Id
streamId = AdminConfig.showAttribute(serverId, streamName)
#update the file path
AdminConfig.modify(streamId, [['fileName', filename]])
#Save the changes
AdminConfig.save()
Restart JVM post this change.

Validate parameters for function doesnt work for OU and CN

I am trying to validate my OUs for a function with the following snippet
Param(
[parameter(Mandatory=$True,Position=1)]
[ValidateScript({Get-ADOrganizationalUnit -Identity $_ -Server $Domain})]
[String]$SourceOu
)
This works for normal OUs like the following like a charm
"OU=Desktops,OU=Germany,DC=dom,DC=de")
But I also need to process the built in AD containers like these
"CN=Computers,DC=dom,DC=de",
Unfortunately they fail (maybe because their distinguishedName starts with CN and not with OU like for other OUs) with the error:
Delete-OldADaccount : Cannot validate argument on parameter 'SourceOu'. Cannot find an object with identity: 'CN=Computers,DC=dom,DC=de' under: 'DC=dom,DC=de'.
Is there a way around this or can I just not check both types with one cmdlet? :(
Maybe just check that the object is a container?
Param(
[parameter(Mandatory=$True,Position=1)]
[ValidateScript({"container","organizationalUnit" -contains (Get-ADObject -Identity $_ -Server $Domain).ObjectClass})]
[String]$SourceOu
)
EDIT: Ah. It should be container or organizationalUnit. Updated.

Is there a way to modify TeamCity system properties in a shell script?

I'm trying to figure out how to modify some custom system properties that I've defined in the build configurations parameters.
For example, if I have a system property named system.TestProperty with value 0 and I want to modify it's value from shell, I've tryed using ##teamcity[setParameter name='system.TestProperty' value='1'] as explained here but the next time I get it's value, it gives me 0 again.
The script i'm using to test:
Write-Host "-------------"
$testProperty = "%system.TestProperty%"
Write-Host "system.TestProperty: $testProperty"
Write-Host "##teamcity[setParameter name='system.TestProperty' value='1']"
$testProperty = "%system.TestProperty%"
Write-Host "system.TestProperty: $testProperty"
Write-Host "-------------"
What I'm getting:
-------------
system.TestProperty: 0
##teamcity[setParameter name='system.TestProperty' value='1']
system.TestProperty: 0
-------------
You wont see the parameter updated in the same script. If you split the check into another build step, you should see it there.

Resources