Posted in Windows Powershell | No Comment | 1,244 views | 17/06/2015 17:40
These are IIS Website Script Map properties that you can get using CIM via PowerShell.
1
2
3
4
5
6
7
8
9
10
11
| # Get WebSites
$WebSites = Get-CimInstance -Namespace "root\MicrosoftIISv2" -ClassName "IIsWebServerSetting" -OperationTimeoutSec 15 -EA Stop
$WebSite = $WebSites[0];
# WebSite Script Map Information
$WebSiteScriptMap = $WebSite.ScriptMaps[0]
[string]$WebSiteScriptMapExtensions = $WebSiteScriptMap.Extensions
[string]$WebSiteScriptMapFlags = $WebSiteScriptMap.Flags
[string]$WebSiteScriptMapIncludedVerbs = $WebSiteScriptMap.IncludedVerbs
[string]$WebSiteScriptMapScriptProcessor = $WebSiteScriptMap.ScriptProcessor |
# Get WebSites
$WebSites = Get-CimInstance -Namespace "root\MicrosoftIISv2" -ClassName "IIsWebServerSetting" -OperationTimeoutSec 15 -EA Stop
$WebSite = $WebSites[0];
# WebSite Script Map Information
$WebSiteScriptMap = $WebSite.ScriptMaps[0]
[string]$WebSiteScriptMapExtensions = $WebSiteScriptMap.Extensions
[string]$WebSiteScriptMapFlags = $WebSiteScriptMap.Flags
[string]$WebSiteScriptMapIncludedVerbs = $WebSiteScriptMap.IncludedVerbs
[string]$WebSiteScriptMapScriptProcessor = $WebSiteScriptMap.ScriptProcessor
You can find more properties in my blog.
Posted in Windows Powershell | 2 Comments | 8,519 views | 15/06/2015 12:28
Some WMI queries may be effected from system performance, so queries may run very long times. In some cases, I see that wmi query hangs, so PowerShell script is not able to continue. In that cases, we should use timeout parameter.
Since CIM is the new method for us, we should go with CIM. For example this is our WMI query:
Get-WmiObject -Class "Win32_PerfFormattedData_PerfProc_Process" |
Get-WmiObject -Class "Win32_PerfFormattedData_PerfProc_Process"
If you run this on PowerShell, you will notice that it will takes for a while. So lets run same query with CIM:
Get-CimInstance -Class "Win32_PerfFormattedData_PerfProc_Process" -OperationTimeoutSec 15 |
Get-CimInstance -Class "Win32_PerfFormattedData_PerfProc_Process" -OperationTimeoutSec 15
As you see, CIM and WMI query is almost same. But additionally I’ve added OperationTimeoutSec parameters to avoid from hangs. That gives us ability to cancel query if it takes more than 15 seconds. You can change it anytime you want.
Posted in Windows Powershell | No Comment | 1,509 views | 28/05/2015 10:54
Following script will get System Logs in last hour.
1
2
3
4
5
6
7
8
9
| # System Log Parameters
$SystemLogParameters = @{
LogName= "System"
EntryType= "Error","Warning"
After= (Get-Date).AddHours(-1)
}
# Get System Logs
Get-EventLog @SystemLogParameters |
# System Log Parameters
$SystemLogParameters = @{
LogName= "System"
EntryType= "Error","Warning"
After= (Get-Date).AddHours(-1)
}
# Get System Logs
Get-EventLog @SystemLogParameters
You can set scope by changing EntryType parameter.
Posted in Windows Powershell | No Comment | 1,586 views | 28/05/2015 10:51
Following script will get Application Logs in last hour with “vmic*” source logs.
1
2
3
4
5
6
7
8
9
| # Application Log Parameters
$ApplicationLogParameters = @{
LogName= "Application"
EntryType= "Error","Warning"
After= (Get-Date).AddHours(-1)
}
# Get Application Logs
Get-EventLog @ApplicationLogParameters -Source vmic* |
# Application Log Parameters
$ApplicationLogParameters = @{
LogName= "Application"
EntryType= "Error","Warning"
After= (Get-Date).AddHours(-1)
}
# Get Application Logs
Get-EventLog @ApplicationLogParameters -Source vmic*
You can set scope by changing EntryType parameter.
Posted in Windows Powershell | 4 Comments | 7,371 views | 28/05/2015 10:47
Following creates a new event log folder called “yusufozturk” in your Application Log Folder.
1
2
3
4
5
| # Create Event Log
New-EventLog -LogName "yusufozturk" -Source "Hyper-V" -EA SilentlyContinue
# Limit Event Log Properties
Limit-EventLog -LogName "yusufozturk" -OverflowAction "OverWriteAsNeeded" -MaximumSize 100MB -EA SilentlyContinue |
# Create Event Log
New-EventLog -LogName "yusufozturk" -Source "Hyper-V" -EA SilentlyContinue
# Limit Event Log Properties
Limit-EventLog -LogName "yusufozturk" -OverflowAction "OverWriteAsNeeded" -MaximumSize 100MB -EA SilentlyContinue
As you see, you can also set OverFlowAction and MaximumSize.
Posted in Windows Powershell | No Comment | 2,808 views | 27/05/2015 18:00
As you know, LoadWithPartialName is now deprecated. So you need to change your codes.
You should use Add-Type instead of LoadWithPartialName. This is example alternative for that:
Add-Type -Path "C:\Windows\System32\inetsrv\Microsoft.Web.Administration.dll" |
Add-Type -Path "C:\Windows\System32\inetsrv\Microsoft.Web.Administration.dll"
That will load DLL into PowerShell session. So you have to specify full path now.
Then you can use it like:
New-Object Microsoft.Web.Administration.ServerManager |
New-Object Microsoft.Web.Administration.ServerManager
Now you can start exploring IIS using with Add-Type :)
Posted in Windows Powershell | No Comment | 1,195 views | 16/05/2015 13:48
These are IIS Application Pool Limits that you can get using CIM via PowerShell.
1
2
3
4
5
6
7
8
9
10
11
12
| # WebSite AppPool Information
$WebSiteAppPools = Get-CimInstance -Namespace "root\MicrosoftIISv2" -ClassName "IIsApplicationPoolSetting" -OperationTimeoutSec 15 -EA Stop
$WebSiteAppPool = $WebSiteAppPools[0];
# IIS AppPool Limits Information
[string]$WebSiteAppPoolAppPoolState = $WebSiteAppPool.AppPoolState
[string]$WebSiteAppPoolCPUAction = $WebSiteAppPool.CPUAction
[string]$WebSiteAppPoolCPULimit = $WebSiteAppPool.CPULimit
[string]$WebSiteAppPoolCPUResetInterval = $WebSiteAppPool.CPUResetInterval
[string]$WebSiteAppPoolDisallowOverlappingRotation = $WebSiteAppPool.DisallowOverlappingRotation
[string]$WebSiteAppPoolDisallowRotationOnConfigChange = $WebSiteAppPool.DisallowRotationOnConfigChange |
# WebSite AppPool Information
$WebSiteAppPools = Get-CimInstance -Namespace "root\MicrosoftIISv2" -ClassName "IIsApplicationPoolSetting" -OperationTimeoutSec 15 -EA Stop
$WebSiteAppPool = $WebSiteAppPools[0];
# IIS AppPool Limits Information
[string]$WebSiteAppPoolAppPoolState = $WebSiteAppPool.AppPoolState
[string]$WebSiteAppPoolCPUAction = $WebSiteAppPool.CPUAction
[string]$WebSiteAppPoolCPULimit = $WebSiteAppPool.CPULimit
[string]$WebSiteAppPoolCPUResetInterval = $WebSiteAppPool.CPUResetInterval
[string]$WebSiteAppPoolDisallowOverlappingRotation = $WebSiteAppPool.DisallowOverlappingRotation
[string]$WebSiteAppPoolDisallowRotationOnConfigChange = $WebSiteAppPool.DisallowRotationOnConfigChange
You can find more properties in my blog.
|