{"id":915,"date":"2016-06-24T13:05:28","date_gmt":"2016-06-24T11:05:28","guid":{"rendered":"http:\/\/blogs.msdn.microsoft.com\/lavanack\/?p=915"},"modified":"2022-05-30T13:51:57","modified_gmt":"2022-05-30T11:51:57","slug":"powershell-w3wp-mapping","status":"publish","type":"post","link":"https:\/\/laurentvanacker.com\/index.php\/2016\/06\/24\/powershell-w3wp-mapping\/","title":{"rendered":"Cartographie des application pools au travers d\u2019IIS, de Performance Monitor et du syst\u00e8me\/Mapping of the application pools across IIS, Performance Monitor and the System."},"content":{"rendered":"<div id=\"fr-FR\" align=\"justify\"><a href=\"#en-US\">English version<\/a><\/div>\n<p align=\"justify\">[MAJ 10\/03\/2017] Performance Monitor (ou PerfMon) est l&rsquo;outil indispensable pour monitorer les performances de vos serveurs Windows. L&rsquo;un des probl\u00e8mes les plus fr\u00e9quents avec Perfmon est d&rsquo;identifier une instance particuli\u00e8re d&rsquo;un processus. En effet PerfMon les num\u00e9rotent de mani\u00e8re s\u00e9quentielle (ici pour des worker processes IIS) : w3wp, w3wp#1, w3wp#2, w3wp#3 &#8230; Il est donc difficile de faire la correspondance avec un ID de processus (PID). Heureusement un workaround existe : <a href=\"https:\/\/techcommunity.microsoft.com\/t5\/ask-the-performance-team\/perfmon-identifying-processes-by-pid-instead-of-instance\/ba-p\/374561\">https:\/\/techcommunity.microsoft.com\/t5\/ask-the-performance-team\/perfmon-identifying-processes-by-pid-instead-of-instance\/ba-p\/374561<\/a>.<\/p>\n<p align=\"justify\">Dans le cadre d&rsquo;un serveur IIS, il ne nous reste plus qu&rsquo;\u00e0 faire le lien entre le PID et l&rsquo;application concern\u00e9e via le task manager (ou autres outil comme <a href=\"https:\/\/technet.microsoft.com\/en-us\/sysinternals\/bb545027.aspx\" target=\"_blank\" rel=\"noopener noreferrer\">pslist<\/a>, PowerShell).<\/p>\n<p align=\"justify\">Deux possibilit\u00e9s :<\/p>\n<ul>\n<li>\n<div align=\"justify\">Pour le peu que l&rsquo;on utilise l&rsquo;identit\u00e9 par d\u00e9faut depuis IIS 7.5 (cf. <a href=\"http:\/\/www.iis.net\/learn\/manage\/configuring-security\/application-pool-identities\" target=\"_blank\" rel=\"noopener noreferrer\">ApplicationPoolIdentity<\/a>), il est alors facile de faire la correspondance (Identit\u00e9 = Nom de l&rsquo;application pool &#8211; voire le nom du site web si celui ci a \u00e9t\u00e9 cr\u00e9\u00e9 via la console IIS) comme en atteste la capture d&rsquo;\u00e9cran ci-dessous:<\/div>\n<\/li>\n<\/ul>\n<p style=\"text-align: center;\" align=\"justify\"><a href=\"http:\/\/laurentvanacker.com\/wp-content\/uploads\/2016\/06\/applicationpoolidentity.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-925\" src=\"http:\/\/laurentvanacker.com\/wp-content\/uploads\/2016\/06\/applicationpoolidentity.png\" alt=\"applicationpoolidentity\" width=\"404\" height=\"446\" \/><\/a><\/p>\n<ul>\n<li style=\"text-align: left;\">\n<div align=\"justify\">Dans d&rsquo;autres cas cela parait un peu plus compliqu\u00e9 \ud83d\ude42<\/div>\n<\/li>\n<\/ul>\n<p align=\"justify\"><a href=\"http:\/\/laurentvanacker.com\/wp-content\/uploads\/2016\/06\/applicationpoolidentity2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-945 aligncenter\" src=\"http:\/\/laurentvanacker.com\/wp-content\/uploads\/2016\/06\/applicationpoolidentity2.png\" alt=\"applicationpoolidentity2\" width=\"406\" height=\"445\" srcset=\"https:\/\/laurentvanacker.com\/wp-content\/uploads\/2016\/06\/applicationpoolidentity2.png 406w, https:\/\/laurentvanacker.com\/wp-content\/uploads\/2016\/06\/applicationpoolidentity2-274x300.png 274w\" sizes=\"auto, (max-width: 406px) 100vw, 406px\" \/><\/a><\/p>\n<p align=\"justify\">Je vous propose dans cette article un script PowerShell (disponible <a href=\"https:\/\/github.com\/lavanack\/laurentvanacker.com\/blob\/master\/Windows%20Powershell\/IIS\/Get-W3WPData.ps1\" target=\"_blank\" rel=\"noopener noreferrer\">ici<\/a>) qui vous offrira un \u00e9tat des lieux comme celui-ci et sans devoir effectuer par le workaround pr\u00e9c\u00e9demment \u00e9voqu\u00e9 (une solution universelle en somme) :<\/p>\n<p align=\"justify\"><a href=\"http:\/\/laurentvanacker.com\/wp-content\/uploads\/2017\/02\/Get-W3WPData.png\"><img loading=\"lazy\" decoding=\"async\" style=\"padding-top: 0px; padding-left: 0px; padding-right: 0px; border-width: 0px;\" title=\"Get-W3WPData\" src=\"http:\/\/laurentvanacker.com\/wp-content\/uploads\/2017\/02\/Get-W3WPData_thumb.png\" alt=\"Get-W3WPData\" width=\"1149\" height=\"123\" border=\"0\" \/><\/a><\/p>\n<p align=\"justify\">On constate rapidement que :<\/p>\n<ul>\n<li>\n<div align=\"justify\">Nous avons 6 applications r\u00e9parties sur 5 sites (le site www.northwindtraders.com h\u00e9bergent 2 applications : www.northwindtraders.com et www.northwindtraders.com\/HR)<\/div>\n<\/li>\n<li>\n<div align=\"justify\">L&rsquo;application pool www.northwindtraders.com est utilis\u00e9 par les sites www.northwindtraders.com et intranet.northwindtraders.com<\/div>\n<\/li>\n<li>\n<div align=\"justify\">Le site www.contoso.com est configur\u00e9 en mode \u00ab\u00a0web gardening\u00a0\u00bb et actuellement 2 worker processes prennent en charge les requ\u00eates \u00e0 destination de ce site.<\/div>\n<\/li>\n<li>\n<div align=\"justify\">Les colonnes PID et Instance\u00a0 nous permettent de faire le lien entre les PID et les instances sous PerfMon. Dans le cas de la deuxi\u00e8me ligne le processus 1512 correspond \u00e0 l&rsquo;instance w3wp#1 et le processus 1520 correspond \u00e0 l&rsquo;instance w3wp#2 (l&rsquo;ordre est pr\u00e9serv\u00e9)<\/div>\n<\/li>\n<\/ul>\n<div align=\"justify\">\n<hr \/>\n<\/div>\n<div align=\"justify\"><\/div>\n<div id=\"en-US\" align=\"justify\"><a href=\"#fr-FR\">Version fran\u00e7aise<\/a><\/div>\n<div id=\"gt-c\" class=\"g-section\" align=\"justify\">\n<div id=\"gt-form-c\">\n<form id=\"gt-form\" action=\"\/\" method=\"post\" name=\"text_form\">\n<div id=\"gt-text-all\">\n<div id=\"gt-main\">\n<div id=\"gt-text-c\">\n<div id=\"gt-text-top\">\n<div id=\"gt-res-c\" class=\"g-unit\">\n<div id=\"gt-res-p\">\n<div id=\"gt-res-data\">\n<div id=\"gt-res-wrap\">\n<div id=\"gt-res-content\" class=\"almost_half_cell\">\n<div dir=\"ltr\">[Update 03\/10\/2017] <span id=\"result_box\" lang=\"en\">Performance Monitor (or Perfmon) is the essential tool to monitor the performance of your Windows servers. One of the most common problems with Perfmon is to identify a particular instance of a process. Indeed PerfMon numbers them sequentially (here for the IIS worker processes): w3wp, w3wp # 1, w3wp # 2, # 3 w3wp &#8230; It is difficult to match a process ID (PID). Fortunately, a workaround exists: <a href=\"https:\/\/techcommunity.microsoft.com\/t5\/ask-the-performance-team\/perfmon-identifying-processes-by-pid-instead-of-instance\/ba-p\/374561\">https:\/\/techcommunity.microsoft.com\/t5\/ask-the-performance-team\/perfmon-identifying-processes-by-pid-instead-of-instance\/ba-p\/374561<\/a>.<\/span><\/div>\n<div dir=\"ltr\"><\/div>\n<\/div>\n<div dir=\"ltr\">\n<div id=\"gt-c\" class=\"g-section\">\n<div id=\"gt-form-c\">\n<div id=\"gt-text-all\">\n<div id=\"gt-main\">\n<div id=\"gt-text-c\">\n<div id=\"gt-text-top\">\n<div id=\"gt-res-c\" class=\"g-unit\">\n<div id=\"gt-res-p\">\n<div id=\"gt-res-data\">\n<div id=\"gt-res-wrap\">\n<div id=\"gt-res-content\" class=\"almost_half_cell\">\n<div dir=\"ltr\">\n<p><span id=\"result_box\" lang=\"en\">As part of an IIS server, it remains for us to make the connection between the PID and the relevant application via the task manager (or other tool like <a href=\"https:\/\/technet.microsoft.com\/en-us\/sysinternals\/bb545027.aspx\" target=\"_blank\" rel=\"noopener noreferrer\">pslist<\/a>, PowerShell).<\/span><\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<div dir=\"ltr\"><span id=\"result_box\" lang=\"en\">Two possibilities :<\/span><br \/>\n<span id=\"result_box\" lang=\"en\"><\/span><span id=\"result_box\" lang=\"en\"><br \/>\n<\/span><\/div>\n<ul>\n<li><span id=\"result_box\" lang=\"en\">If the default identity for IIS 7.5 (cf. <a href=\"http:\/\/www.iis.net\/learn\/manage\/configuring-security\/application-pool-identities\" target=\"_blank\" rel=\"noopener noreferrer\">ApplicationPoolIdentity<\/a>) is used, it is easy to make the connection (ID = Name of the application pool &#8211; even the name of the website if it has created via the IIS console) as illustrated in the screenshot below:<\/span><\/li>\n<\/ul>\n<p><a href=\"http:\/\/laurentvanacker.com\/wp-content\/uploads\/2016\/06\/applicationpoolidentity.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-925 aligncenter\" src=\"http:\/\/laurentvanacker.com\/wp-content\/uploads\/2016\/06\/applicationpoolidentity.png\" alt=\"applicationpoolidentity\" width=\"404\" height=\"446\" \/><\/a><\/p>\n<ul>\n<li>In other cases it seems a little more complicated \ud83d\ude42<\/li>\n<\/ul>\n<p><a href=\"http:\/\/laurentvanacker.com\/wp-content\/uploads\/2016\/06\/applicationpoolidentity2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-945 aligncenter\" src=\"http:\/\/laurentvanacker.com\/wp-content\/uploads\/2016\/06\/applicationpoolidentity2.png\" alt=\"applicationpoolidentity2\" width=\"406\" height=\"445\" srcset=\"https:\/\/laurentvanacker.com\/wp-content\/uploads\/2016\/06\/applicationpoolidentity2.png 406w, https:\/\/laurentvanacker.com\/wp-content\/uploads\/2016\/06\/applicationpoolidentity2-274x300.png 274w\" sizes=\"auto, (max-width: 406px) 100vw, 406px\" \/><\/a><\/p>\n<div id=\"gt-c\" class=\"g-section\">\n<div id=\"gt-form-c\">\n<div id=\"gt-text-all\">\n<div id=\"gt-main\">\n<div id=\"gt-text-c\">\n<div id=\"gt-text-top\">\n<div id=\"gt-res-c\" class=\"g-unit\">\n<div id=\"gt-res-p\">\n<div id=\"gt-res-data\">\n<div id=\"gt-res-wrap\">\n<div id=\"gt-res-content\" class=\"almost_half_cell\">\n<div dir=\"ltr\"><span id=\"result_box\" lang=\"en\">I propose in this article a PowerShell script (available <a href=\"https:\/\/github.com\/lavanack\/laurentvanacker.com\/blob\/master\/Windows%20Powershell\/IIS\/Get-W3WPData.ps1\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>) that offers an inventory like this and without having to perform the previously mentioned workaround (an universal solution):<\/span><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/form>\n<\/div>\n<\/div>\n<div align=\"justify\"><\/div>\n<p align=\"justify\"><a href=\"http:\/\/laurentvanacker.com\/wp-content\/uploads\/2017\/02\/Get-W3WPData1.png\"><img loading=\"lazy\" decoding=\"async\" style=\"padding-top: 0px; padding-left: 0px; padding-right: 0px; border-width: 0px;\" title=\"Get-W3WPData\" src=\"http:\/\/laurentvanacker.com\/wp-content\/uploads\/2017\/02\/Get-W3WPData_thumb1.png\" alt=\"Get-W3WPData\" width=\"1149\" height=\"119\" border=\"0\" \/><\/a><\/p>\n<div class=\"almost_half_cell\" dir=\"ltr\" align=\"justify\"><\/div>\n<div class=\"almost_half_cell\" dir=\"ltr\" align=\"justify\"><span id=\"result_box\" lang=\"en\">We quickly found that:<\/span><\/div>\n<div class=\"almost_half_cell\" align=\"justify\">\n<ul>\n<li><span id=\"result_box\" lang=\"en\">We have 6 applications spread over 5 sites (The site www.northwindtraders.com hosts 2 applications www.northwindtraders.com and www.northwindtraders.com\/HR)<\/span><\/li>\n<li><span id=\"result_box\" lang=\"en\">The www.northwindtraders.com application pool is used by the www.northwindtraders.com and intranet.northwindtraders.com sites <\/span><\/li>\n<li><span id=\"result_box\" lang=\"en\">The site www.contoso.com is configured for \u00ab\u00a0web gardening\u00a0\u00bb mode and 2 worker processes currently support queries to this site.<\/span><\/li>\n<li><span id=\"result_box\" lang=\"en\">The PID and Instance columns allow us to make the connection between the PID and the instances in PerfMon. In the case of the second line the PID 1512 matches the instance w3wp#1 and the PID 1250 matches the instance w3wp#2 (the order is preserved)<\/span><\/li>\n<\/ul>\n<\/div>\n<div id=\"scid:9D7513F9-C04C-4721-824A-2B34F0212519:f35aab08-1876-4869-90e7-85413c7b6db3\" class=\"wlWriterEditableSmartContent\" style=\"float: none; margin: 0px; padding: 0px;\"><\/div>\n<div align=\"justify\">Laurent.<\/div>\n","protected":false},"excerpt":{"rendered":"<p>English version [MAJ 10\/03\/2017] Performance Monitor (ou PerfMon) est l&rsquo;outil indispensable pour monitorer les performances de vos serveurs Windows. L&rsquo;un des probl\u00e8mes les plus fr\u00e9quents [&#8230;]<\/p>\n","protected":false},"author":2,"featured_media":2465,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,19,11],"tags":[25,39],"class_list":["post-915","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-iis","category-powershell","category-scripting","tag-iis","tag-powershell"],"_links":{"self":[{"href":"https:\/\/laurentvanacker.com\/index.php\/wp-json\/wp\/v2\/posts\/915","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/laurentvanacker.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/laurentvanacker.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/laurentvanacker.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/laurentvanacker.com\/index.php\/wp-json\/wp\/v2\/comments?post=915"}],"version-history":[{"count":23,"href":"https:\/\/laurentvanacker.com\/index.php\/wp-json\/wp\/v2\/posts\/915\/revisions"}],"predecessor-version":[{"id":2890,"href":"https:\/\/laurentvanacker.com\/index.php\/wp-json\/wp\/v2\/posts\/915\/revisions\/2890"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/laurentvanacker.com\/index.php\/wp-json\/wp\/v2\/media\/2465"}],"wp:attachment":[{"href":"https:\/\/laurentvanacker.com\/index.php\/wp-json\/wp\/v2\/media?parent=915"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/laurentvanacker.com\/index.php\/wp-json\/wp\/v2\/categories?post=915"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/laurentvanacker.com\/index.php\/wp-json\/wp\/v2\/tags?post=915"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}