简体   繁体   English

通过电源 Shell 在 iis 上查找物理路径

[英]Finding physical path on iis via power Shell

I want to find and store an IIS site physical path to a variable, however the shown result has so many lines, is it possible to just store "C:\.netpub\wwwroot" in a variable like $Directory in the following lines?我想查找并存储一个 IIS 站点物理路径到一个变量,但是显示的结果有这么多行,是否可以在以下几行中将“C:\.netpub\wwwroot”存储在 $Directory 之类的变量中?

MY COMMAND我的命令

$Site = Get-IISSite "Default Web Site"
$Site

###RESULT ###结果

Name             ID   State      Physical Path                  Bindings                                                                                                                      
----             --   -----      -------------                  --------                                                                                                                      
Default Web Site 1    Started    **C:\inetpub\wwwroot**             http *:80:                                                                                                                    
                                                                http 192.168.97.7:80:                                                                                                         
                                                                net.tcp 808:*                                                                                                                 
                                                                net.msmq localhost                                                                                                            
                                                                msmq.formatname localhost                                                                                                     
                                                                net.pipe *

Thanks谢谢

To make the code from Pba even shorter you can use the "dot notation" to expand the attributes you're after:为了使 Pba 中的代码更短,您可以使用“点符号”来扩展您所追求的属性:

$Directory = 
    Get-IISSite "Default Web Site" | 
    Foreach-Object {$_.Applications.VirtualDirectories.PhysicalPath}
$Directory

This way it's even easier to actually see the relations of the attributes.这样就更容易实际看到属性之间的关系。

This gives me the expected result这给了我预期的结果

Written out version:写出来的版本:

$Directory = Get-IISSite "Default Web Site" | Foreach-Object {$_.Applications} | Foreach-Object {$_.VirtualDirectories} | Foreach-Object {$_.PhysicalPath}

Alias version for slighty shorter code (Less readable, so not recommended)代码稍短的别名版本(可读性较差,因此不推荐)

$Directory = Get-IISSite "Default Web Site" | % {$_.Applications} | % {$_.VirtualDirectories} | % {$_.PhysicalPath}

This loops through IIS and returns the working directories.这遍历 IIS 并返回工作目录。 Be aware that you will get more results when you start using applications or virtual directories, so in that case you need to fiddle around with the foreach loops a bit.请注意,当您开始使用应用程序或虚拟目录时,您将获得更多结果,因此在这种情况下,您需要稍微摆弄一下 foreach 循环。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM