From 7d9586d61a13dcb4364b6ceefc6b3ee98397be12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ewerton=20Jord=C3=A3o?= Date: Tue, 12 Jan 2021 11:54:50 -0300 Subject: [PATCH 1/2] Update index.md add sample from pull request #536 --- .../sites/site/ftpServer/sessions/index.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/iis/configuration/system.applicationHost/sites/site/ftpServer/sessions/index.md b/iis/configuration/system.applicationHost/sites/site/ftpServer/sessions/index.md index 14a764a7f..ab5df19fb 100644 --- a/iis/configuration/system.applicationHost/sites/site/ftpServer/sessions/index.md +++ b/iis/configuration/system.applicationHost/sites/site/ftpServer/sessions/index.md @@ -170,3 +170,7 @@ You cannot query FTP session information by using AppCmd.exe. ### VBScript [!code-vb[Main](index/samples/sample4.vb)] + +### PowerShell + +[!code-powershell[Main](index/samples/sample5.ps1)] From 9f83fc89263b7fbabdc666d209ff35d35bd6c089 Mon Sep 17 00:00:00 2001 From: Ewerton R Jordao Date: Sat, 19 Mar 2022 19:51:20 -0300 Subject: [PATCH 2/2] include sessions sample5.ps1 --- .../sessions/index/samples/sample5.ps1 | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 iis/configuration/system.applicationHost/sites/site/ftpServer/sessions/index/samples/sample5.ps1 diff --git a/iis/configuration/system.applicationHost/sites/site/ftpServer/sessions/index/samples/sample5.ps1 b/iis/configuration/system.applicationHost/sites/site/ftpServer/sessions/index/samples/sample5.ps1 new file mode 100644 index 000000000..28e7b151b --- /dev/null +++ b/iis/configuration/system.applicationHost/sites/site/ftpServer/sessions/index/samples/sample5.ps1 @@ -0,0 +1,47 @@ +[Reflection.Assembly]::LoadWithPartialName('Microsoft.IIS.PowerShell.Framework') +[Reflection.Assembly]::LoadWithPartialName('Microsoft.Web.Administration') +function Get-ConfigElement { + param ( + [Microsoft.Web.Administration.ConfigurationElement]$ElementCollection, + [String]$ElementTagName, + [string[]]$KeyValues + ) + [Microsoft.Web.Administration.ConfigurationElement]$element = $null + foreach ($element in $ElementCollection) { + if ([String]::Equals($element.ElementTagName, $ElementTagName, [System.StringComparison]::OrdinalIgnoreCase)) { + $find = $true + for ($i = 0; $i -lt $KeyValues.Count; $i += 2) { + [System.Object]$o = $element.GetAttributeValue($KeyValues[$i]) + if ($null -ne $o ) { + $ftpname = $o.ToString() + } + if ([String]::Equals($ftpname, $KeyValues[$i + 1], [System.StringComparison]::OrdinalIgnoreCase) -eq $false) { + $find = $false + break + } + } + if ($find) { + return $element + } + } + } +} + +$serverManager = New-Object Microsoft.Web.Administration.ServerManager +[Microsoft.Web.Administration.Configuration]$config = $serverManager.GetApplicationHostConfiguration() +$sitesSection = $config.GetSection("system.applicationHost/sites") +[Microsoft.Web.Administration.ConfigurationElementCollection]$listaSites = $sitesSection.GetCollection() +$element = Get-ConfigElement -ElementCollection $listaSites -ElementTagName "site" -KeyValues @("name", "ftp.example.com") + +[Microsoft.Web.Administration.ConfigurationElement]$ftpServerElement = $element.GetChildElement("ftpServer") +[Microsoft.Web.Administration.ConfigurationElementCollection]$sessionsElement = $ftpServerElement.GetChildElement("sessions").GetCollection() +if ($sessionsElement.count -gt 0) { + $attributesList = ($sessionsElement | Select-Object -First 1 | ForEach-Object -MemberName Attributes).name + foreach ($sessionElement in $sessionsElement) { + $sessionObject = [PSCustomObject]@{} + for ($j = 0; $j -lt $attributesList.Count; $j++) { + Add-Member -Name $attributesList[$j] -MemberType NoteProperty -Value $sessionElement.GetAttribute($attributesList[$j]).value.ToString() -InputObject $sessionObject + } + $sessionObject + } +} \ No newline at end of file