Reputation: 29
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:\inetpub\wwwroot" in a variable like $Directory in the following lines?
$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
Upvotes: 2
Views: 1268
Reputation: 5242
To make the code from Pba even shorter you can use the "dot notation" to expand the attributes you're after:
$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.
Upvotes: 2
Reputation: 918
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. 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.
Upvotes: 0