search
Categories
Sponsors
VirtualMetric Hyper-V Monitoring, Hyper-V Reporting
Archive
Blogroll

Badges
MCSE
Community

Cozumpark Bilisim Portali
Posted in Windows Powershell | No Comment | 1,355 views | 23/01/2016 17:38

You can use Test-Path to test if file is exist.

But you can also use [System.IO.File]::Exists() to check it fast.

1
[System.IO.File]::Exists("Your File Path")

You can use in if block to check it on one line:

1
2
3
4
if ([System.IO.File]::Exists("C:\setup.log"))
{
Write-Output "File Exist"
}

It will also use less memory.


Posted in Windows Powershell | No Comment | 1,920 views | 16/01/2016 15:20

You can simply check .NET Core status with following code:

1
2
3
4
5
# Check PSEdition
if ($PSVersionTable.PSEdition -eq "Core")
{
Write-Host "Core Edition";
}

You can check it on Nano server.


Posted in Windows Powershell | No Comment | 1,871 views | 10/01/2016 00:16

Bir değişkenin değerini, dosya içeriğinden aşağıdaki gibi okuyabilirsiniz.

${C:\deneme.txt}

Değişkene aşağıdaki gibi yazdığınızda ise dosya içeriği güncellenir.

${C:\deneme.txt} = "test"

Farklı PowerShell session’larına bu şekilde variable aktarılabilir.


Posted in Windows Powershell, Windows Server | No Comment | 1,912 views | 04/10/2015 20:22

Windows Containers are finally here! Lets start our new series :)

Container management is very similar to Hyper-V management. For example:

container

Lets check our commands:

PS C:\Users\Administrator> get-command *container*
 
CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Function        Install-ContainerOSImage                           1.0.0.0    Containers
Function        Uninstall-ContainerOSImage                         1.0.0.0    Containers
Cmdlet          Add-ContainerNetworkAdapter                        1.0.0.0    Containers
Cmdlet          Connect-ContainerNetworkAdapter                    1.0.0.0    Containers
Cmdlet          Disconnect-ContainerNetworkAdapter                 1.0.0.0    Containers
Cmdlet          Export-ContainerImage                              1.0.0.0    Containers
Cmdlet          Get-Container                                      1.0.0.0    Containers
Cmdlet          Get-ContainerHost                                  1.0.0.0    Containers
Cmdlet          Get-ContainerImage                                 1.0.0.0    Containers
Cmdlet          Get-ContainerNetworkAdapter                        1.0.0.0    Containers
Cmdlet          Import-ContainerImage                              1.0.0.0    Containers
Cmdlet          Move-ContainerImageRepository                      1.0.0.0    Containers
Cmdlet          New-Container                                      1.0.0.0    Containers
Cmdlet          New-ContainerImage                                 1.0.0.0    Containers
Cmdlet          Remove-Container                                   1.0.0.0    Containers
Cmdlet          Remove-ContainerImage                              1.0.0.0    Containers
Cmdlet          Remove-ContainerNetworkAdapter                     1.0.0.0    Containers
Cmdlet          Set-ContainerNetworkAdapter                        1.0.0.0    Containers
Cmdlet          Start-Container                                    1.0.0.0    Containers
Cmdlet          Stop-Container                                     1.0.0.0    Containers
Cmdlet          Test-ContainerImage                                1.0.0.0    Containers

I can create a new container with following command:

New-Container -Name "MyContainer" -ContainerImageName WindowsServerCore -SwitchName "Virtual Switch"

If you install Windows Containers with Microsoft Documentation, then you should have a virtual switch called “Virtual Switch” in your environment.

New-Container accepts many parameters:

NAME
    New-Container
 
SYNTAX
    New-Container [[-Name] <string>] -ContainerImageName <string> [-ContainerImagePublisher <string>]
    [-ContainerImageVersion <version>] [-CimSession <CimSession[]>] [-ComputerName <string[]>] [-Credential
    <pscredential[]>] [-MemoryStartupBytes <long>] [-SwitchName <string>] [-Path <string>] [-AsJob] [-WhatIf]
    [-Confirm]  [<CommonParameters>]
 
    New-Container [[-Name] <string>] -ContainerImage <ContainerImage> [-MemoryStartupBytes <long>] [-SwitchName
    <string>] [-Path <string>] [-AsJob] [-WhatIf] [-Confirm]  [<CommonParameters>]

There is a parameter called “MemoryStartupBytes” but it seems it just changes startup memory. It seems there is no memory or processor limit yet.

container2

Starting Container is similar like Hyper-V VMs:

Start-Container -Name "MyContainer"

After start your container, you should configure your Host’s Firewall because Container uses Host Firewall. If you try to configure firewall inside Container, you will get warning.

You can use Enter-PSSession like in Hyper-V VMs to connect Container:

Enter-PSSession -ContainerId (Get-Container MyContainer).ContainerId -RunAsAdministrator

You can disable firewall with following command to test RDP connection:

Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False

After that, you may have to enable Administrator account in Container with:

net use administrator /active:yes
net use administrator Password1!

See you in next part!


Posted in Windows Powershell | No Comment | 1,272 views | 21/09/2015 17:39

These are IIS Website properties that you can get using CIM via PowerShell.

1
2
3
4
5
6
7
8
9
10
# Get WebSites
$WebSites = Get-CimInstance -Namespace "root\MicrosoftIISv2" -ClassName "IIsWebServerSetting" -OperationTimeoutSec 15 -EA Stop
 
$WebSite = $WebSites[0];
 
# WebSite Cache Information
[string]$WebSiteCacheControlCustom = $WebSite.CacheControlCustom
[string]$WebSiteCacheControlMaxAge = $WebSite.CacheControlMaxAge
[string]$WebSiteCacheControlNoCache = $WebSite.CacheControlNoCache
[string]$WebSiteCacheISAPI = $WebSite.CacheISAPI

You can find more properties in my blog.


Posted in Windows Powershell | No Comment | 2,101 views | 04/09/2015 17:15

This is an example for StringBuilder in PowerShell. This is fast :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# IIS: Application Pools
 
# PowerShell String Builder
$HostIISAppPoolsStringBuilder = New-Object System.Text.StringBuilder
 
# Append to String Builder
$Null = $HostIISAppPoolsStringBuilder.Append("[")
 
# Get IIS Application Pools
$IISServerManager.ApplicationPools | % {
 
	# Clear Variables
	$HostIISAppPoolName = $Null;
	$HostIISAppPoolStartMode = $Null;
	$HostIISAppPoolEnable32BitAppOnWin64 = $Null;
	$HostIISAppPoolManagedPipelineMode = $Null;
	$HostIISAppPoolManagedRuntimeVersion = $Null;
	$HostIISAppPoolQueueLength = $Null;
	$HostIISAppPoolAutoStart = $Null;
	$HostIISAppPoolState = $Null;
	$HostIISAppPoolCpuAction = $Null;
	$HostIISAppPoolCpuLimit = $Null;
	$HostIISAppPoolCpuResetInterval = $Null;
	$HostIISAppPoolRapidFailProtection = $Null;
	$HostIISAppPoolRapidFailProtectionInterval = $Null;
	$HostIISAppPoolRapidFailProtectionMaxCrashes = $Null;
	$HostIISAppPoolIdentityType = $Null;
	$HostIISAppPoolIdleTimeout = $Null;
	$HostIISAppPoolIdleTimeoutAction = $Null;
	$HostIISAppPoolShutdownTimeLimit = $Null;
	$HostIISAppPoolStartupTimeLimit = $Null;
	$HostIISAppPoolMaxProcesses = $Null;
	$HostIISAppPoolPingingEnabled = $Null;
	$HostIISAppPoolPingInterval = $Null;
	$HostIISAppPoolPingResponseTime = $Null;
	$HostIISAppPoolLogEventOnProcessModel = $Null;
	$HostIISAppPoolLogEventOnRecycle = $Null;
	$HostIISAppPoolRecycleMemory = $Null;
	$HostIISAppPoolRecyclePrivateMemory = $Null;
	$HostIISAppPoolRecycleRequests = $Null;
	$HostIISAppPoolRecycleTime = $Null;
 
	# Get IIS AppPool Properties
	$HostIISAppPoolName = $_.Name;
	$HostIISAppPoolStartMode = $_.StartMode;
	$HostIISAppPoolEnable32BitAppOnWin64 = $_.Enable32BitAppOnWin64;
	$HostIISAppPoolManagedPipelineMode = $_.ManagedPipelineMode;
	$HostIISAppPoolManagedRuntimeVersion = $_.ManagedRuntimeVersion;
	$HostIISAppPoolQueueLength = $_.QueueLength;
	$HostIISAppPoolAutoStart = $_.AutoStart;
	$HostIISAppPoolState = $_.State;
	$HostIISAppPoolCpuAction = $_.Cpu.Action;
	$HostIISAppPoolCpuLimit = $_.Cpu.Limit;
	$HostIISAppPoolCpuResetInterval = $_.Cpu.ResetInterval.ToString();
	$HostIISAppPoolRapidFailProtection = $_.Failure.RapidFailProtection;
	$HostIISAppPoolRapidFailProtectionInterval = $_.Failure.RapidFailProtectionInterval.ToString();
	$HostIISAppPoolRapidFailProtectionMaxCrashes = $_.Failure.RapidFailProtectionMaxCrashes;
	$HostIISAppPoolIdentityType = $_.ProcessModel.IdentityType;
	$HostIISAppPoolIdleTimeout = $_.ProcessModel.IdleTimeout.ToString();
	$HostIISAppPoolIdleTimeoutAction = $_.ProcessModel.IdleTimeoutAction;
	$HostIISAppPoolShutdownTimeLimit = $_.ProcessModel.ShutdownTimeLimit.ToString();
	$HostIISAppPoolStartupTimeLimit = $_.ProcessModel.StartupTimeLimit.ToString();
	$HostIISAppPoolMaxProcesses = $_.ProcessModel.MaxProcesses;
	$HostIISAppPoolPingingEnabled = $_.ProcessModel.PingingEnabled;
	$HostIISAppPoolPingInterval = $_.ProcessModel.PingInterval.ToString();
	$HostIISAppPoolPingResponseTime = $_.ProcessModel.PingResponseTime.ToString();
	$HostIISAppPoolLogEventOnProcessModel = $_.ProcessModel.LogEventOnProcessModel;
	$HostIISAppPoolLogEventOnRecycle = $_.Recycling.LogEventOnRecycle;
	$HostIISAppPoolRecycleMemory = $_.Recycling.PeriodicRestart.Memory;
	$HostIISAppPoolRecyclePrivateMemory = $_.Recycling.PeriodicRestart.PrivateMemory;
	$HostIISAppPoolRecycleRequests = $_.Recycling.PeriodicRestart.Requests;
	$HostIISAppPoolRecycleTime = $_.Recycling.PeriodicRestart.Time.ToString();
 
	# Parameter Validation
	if($HostIISAppPoolName -eq $Null) { $HostIISAppPoolName = "Unknown"; }
	if($HostIISAppPoolStartMode -eq $Null) { $HostIISAppPoolStartMode = "Unknown"; }
	if($HostIISAppPoolEnable32BitAppOnWin64 -eq $Null) { $HostIISAppPoolEnable32BitAppOnWin64 = "Unknown"; }
	if($HostIISAppPoolManagedPipelineMode -eq $Null) { $HostIISAppPoolManagedPipelineMode = "Unknown"; }
	if($HostIISAppPoolManagedRuntimeVersion -eq $Null) { $HostIISAppPoolManagedRuntimeVersion = "Unknown"; }
	if($HostIISAppPoolQueueLength -eq $Null) { $HostIISAppPoolQueueLength = "-1"; }
	if($HostIISAppPoolAutoStart -eq $Null) { $HostIISAppPoolAutoStart = "Unknown"; }
	if($HostIISAppPoolState -eq $Null) { $HostIISAppPoolState = "Unknown"; }
	if($HostIISAppPoolCpuAction -eq $Null) { $HostIISAppPoolCpuAction = "Unknown"; }
	if($HostIISAppPoolCpuLimit -eq $Null) { $HostIISAppPoolCpuLimit = "Unknown"; }
	if($HostIISAppPoolCpuResetInterval -eq $Null) { $HostIISAppPoolCpuResetInterval = "Unknown"; }
	if($HostIISAppPoolRapidFailProtection -eq $Null) { $HostIISAppPoolRapidFailProtection = "Unknown"; }
	if($HostIISAppPoolRapidFailProtectionInterval -eq $Null) { $HostIISAppPoolRapidFailProtectionInterval = "Unknown"; }
	if($HostIISAppPoolRapidFailProtectionMaxCrashes -eq $Null) { $HostIISAppPoolRapidFailProtectionMaxCrashes = "-1"; }
	if($HostIISAppPoolIdentityType -eq $Null) { $HostIISAppPoolIdentityType = "Unknown"; }
	if($HostIISAppPoolIdleTimeout -eq $Null) { $HostIISAppPoolIdleTimeout = "Unknown"; }
	if($HostIISAppPoolIdleTimeoutAction -eq $Null) { $HostIISAppPoolIdleTimeoutAction = "Unknown"; }
	if($HostIISAppPoolShutdownTimeLimit -eq $Null) { $HostIISAppPoolShutdownTimeLimit = "Unknown"; }
	if($HostIISAppPoolStartupTimeLimit -eq $Null) { $HostIISAppPoolStartupTimeLimit = "Unknown"; }
	if($HostIISAppPoolMaxProcesses -eq $Null) { $HostIISAppPoolMaxProcesses = "-1"; }
	if($HostIISAppPoolPingingEnabled -eq $Null) { $HostIISAppPoolPingingEnabled = "Unknown"; }
	if($HostIISAppPoolPingInterval -eq $Null) { $HostIISAppPoolPingInterval = "Unknown"; }
	if($HostIISAppPoolPingResponseTime -eq $Null) { $HostIISAppPoolPingResponseTime = "Unknown"; }
	if($HostIISAppPoolLogEventOnProcessModel -eq $Null) { $HostIISAppPoolLogEventOnProcessModel = "Unknown"; }
	if($HostIISAppPoolLogEventOnRecycle -eq $Null) { $HostIISAppPoolLogEventOnRecycle = "Unknown"; }
	if($HostIISAppPoolRecycleMemory -eq $Null) { $HostIISAppPoolRecycleMemory = "-1"; }
	if($HostIISAppPoolRecyclePrivateMemory -eq $Null) { $HostIISAppPoolRecyclePrivateMemory = "-1"; }
	if($HostIISAppPoolRecycleRequests -eq $Null) { $HostIISAppPoolRecycleRequests = "-1"; }
	if($HostIISAppPoolRecycleTime -eq $Null) { $HostIISAppPoolRecycleTime = "Unknown"; }
 
	# Create Host IIS App Pool Json Data
	$HostIISAppPoolJson = @{
		ReportDate = "$VMReportDate"
		HostID = "$VirtualMetricHostID"
		HostName = "$VirtualMetricHostName"
		FQDN = "$VirtualMetricHostFQDN"
		Name = "$HostIISAppPoolName"
		StartMode = "$HostIISAppPoolStartMode"
		Enable32BitAppOnWin64 = "$HostIISAppPoolEnable32BitAppOnWin64"
		ManagedPipelineMode = "$HostIISAppPoolManagedPipelineMode"
		ManagedRuntimeVersion = "$HostIISAppPoolManagedRuntimeVersion"
		QueueLength = "$HostIISAppPoolQueueLength"
		AutoStart = "$HostIISAppPoolAutoStart"
		State = "$HostIISAppPoolState"
		CpuAction = "$HostIISAppPoolCpuAction"
		CpuLimit = "$HostIISAppPoolCpuLimit"
		CpuResetInterval = "$HostIISAppPoolCpuResetInterval"
		RapidFailProtection = "$HostIISAppPoolRapidFailProtection"
		RapidFailProtectionInterval = "$HostIISAppPoolRapidFailProtectionInterval"
		RapidFailProtectionMaxCrashes = "$HostIISAppPoolRapidFailProtectionMaxCrashes"
		IdentityType = "$HostIISAppPoolIdentityType"
		IdleTimeout = "$HostIISAppPoolIdleTimeout"
		IdleTimeoutAction = "$HostIISAppPoolIdleTimeoutAction"
		ShutdownTimeLimit = "$HostIISAppPoolShutdownTimeLimit"
		StartupTimeLimit = "$HostIISAppPoolStartupTimeLimit"
		MaxProcesses = "$HostIISAppPoolMaxProcesses"
		PingingEnabled = "$HostIISAppPoolPingingEnabled"
		PingInterval = "$HostIISAppPoolPingInterval"
		PingResponseTime = "$HostIISAppPoolPingResponseTime"
		LogEventOnProcessModel = "$HostIISAppPoolLogEventOnProcessModel"
		LogEventOnRecycle = "$HostIISAppPoolLogEventOnRecycle"
		RecycleMemory = "$HostIISAppPoolRecycleMemory"
		RecyclePrivateMemory = "$HostIISAppPoolRecyclePrivateMemory"
		RecycleRequests = "$HostIISAppPoolRecycleRequests"
		RecycleTime = "$HostIISAppPoolRecycleTime"
	}| ConvertTo-Json -Compress
 
	# Append to String Builder
	$Null = $HostIISAppPoolsStringBuilder.Append("$HostIISAppPoolJson`r`n")
 
	# Append to String Builder
	$Null = $HostIISAppPoolsStringBuilder.Append(",")
}
 
# Append to String Builder
$Null = $HostIISAppPoolsStringBuilder.Append("{}]")
 
# Get Output String
$HostIISAppPoolsOutputString = $HostIISAppPoolsStringBuilder.ToString()

You will get all string output using with .ToString() for StringBuilder.


Posted in Windows Powershell | No Comment | 1,244 views | 28/08/2015 17:34

These are IIS Website properties that you can get using CIM via PowerShell.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Get WebSites
$WebSites = Get-CimInstance -Namespace "root\MicrosoftIISv2" -ClassName "IIsWebServerSetting" -OperationTimeoutSec 15 -EA Stop
 
$WebSite = $WebSites[0];
 
# WebSite ASP Information
[string]$WebSiteAspAllowOutOfProcComponents = $WebSite.AspAllowOutOfProcComponents
[string]$WebSiteAspAllowSessionState = $WebSite.AspAllowSessionState
[string]$WebSiteAspAppServiceFlags = $WebSite.AspAppServiceFlags
[string]$WebSiteAspBufferingLimit = $WebSite.AspBufferingLimit
[string]$WebSiteAspBufferingOn = $WebSite.AspBufferingOn
[string]$WebSiteAspCalcLineNumber = $WebSite.AspCalcLineNumber
[string]$WebSiteAspCodepage = $WebSite.AspCodepage
[string]$WebSiteAspDiskTemplateCacheDirectory = $WebSite.AspDiskTemplateCacheDirectory
[string]$WebSiteAspEnableApplicationRestart = $WebSite.AspEnableApplicationRestart
[string]$WebSiteAspEnableAspHtmlFallback = $WebSite.AspEnableAspHtmlFallback
[string]$WebSiteAspEnableChunkedEncoding = $WebSite.AspEnableChunkedEncoding
[string]$WebSiteAspEnableParentPaths = $WebSite.AspEnableParentPaths
[string]$WebSiteAspEnableSxs = $WebSite.AspEnableSxs
[string]$WebSiteAspEnableTracker = $WebSite.AspEnableTracker
[string]$WebSiteAspEnableTypelibCache = $WebSite.AspEnableTypelibCache
[string]$WebSiteAspErrorsToNTLog = $WebSite.AspErrorsToNTLog
[string]$WebSiteAspExceptionCatchEnable = $WebSite.AspExceptionCatchEnable
[string]$WebSiteAspExecuteInMTA = $WebSite.AspExecuteInMTA
[string]$WebSiteAspKeepSessionIDSecure = $WebSite.AspKeepSessionIDSecure
[string]$WebSiteAspLCID = $WebSite.AspLCID
[string]$WebSiteAspLogErrorRequests = $WebSite.AspLogErrorRequests
[string]$WebSiteAspMaxDiskTemplateCacheFiles = $WebSite.AspMaxDiskTemplateCacheFiles
[string]$WebSiteAspMaxRequestEntityAllowed = $WebSite.AspMaxRequestEntityAllowed
[string]$WebSiteAspPartitionID = $WebSite.AspPartitionID
[string]$WebSiteAspProcessorThreadMax = $WebSite.AspProcessorThreadMax
[string]$WebSiteAspQueueConnectionTestTime = $WebSite.AspQueueConnectionTestTime
[string]$WebSiteAspQueueTimeout = $WebSite.AspQueueTimeout
[string]$WebSiteAspRequestQueueMax = $WebSite.AspRequestQueueMax
[string]$WebSiteAspRunOnEndAnonymously = $WebSite.AspRunOnEndAnonymously
[string]$WebSiteAspScriptEngineCacheMax = $WebSite.AspScriptEngineCacheMax
[string]$WebSiteAspScriptErrorMessage = $WebSite.AspScriptErrorMessage
[string]$WebSiteAspScriptErrorSentToBrowser = $WebSite.AspScriptErrorSentToBrowser
[string]$WebSiteAspScriptFileCacheSize = $WebSite.AspScriptFileCacheSize
[string]$WebSiteAspScriptLanguage = $WebSite.AspScriptLanguage
[string]$WebSiteAspScriptTimeout = $WebSite.AspScriptTimeout
[string]$WebSiteAspSessionMax = $WebSite.AspSessionMax
[string]$WebSiteAspSessionTimeout = $WebSite.AspSessionTimeout
[string]$WebSiteAspSxsName = $WebSite.AspSxsName
[string]$WebSiteAspTrackThreadingModel = $WebSite.AspTrackThreadingModel
[string]$WebSiteAspUsePartition = $WebSite.AspUsePartition

You can find more properties in my blog.