I want to list (in Powershell) all the websites from IIS that have a name containing the keyword "UK". And then, I want to replace the physical path of the returned site with another one, for example "C:\Sites\Sitex".
What am I doing wrong here?
So far, I've tried this:
get-website | select name,physicalpath | where { $_.name -like "*UK*" }
which works fine to display all the sites in my IIS that have a name containing the keyword "UK".
However, when I do this:
get-website | select physicalpath | where { $_.name -like "*UK*" }
it displays nothing!
I imagine it may be because I can't have in my "where" clause a field which is not present in my select! (in SQL this would work though). So, I would try to wrap up the initial query into a table and then select only a column from that table. Do nested queries as such exist in Powershell? Please help with syntax. Other solutions are also welcome.
I would then do something like
foreach ($site in $sites) {
Set-ItemProperty ???? -name physicalpath -value "C:\Sites\Sitex"
}
Any help with the syntax please and what parameter should be written after Set-ItemProperty. Many thanks in advance!
================= Also trying something like this in parallel:
Import-Module WebAdministration
dir IIS:\Sites # lists all sites
dir IIS:\Sites | ForEach-Object {
# web site name $_Name
if($_.Name -like "*UK*") {
$_.Name
$_.PhysicalPath = "C:\Inetpub"
}
}
No errors and it doesn't seem to work either.
if($_.Name -like "*UK*")
does not behave as expected as it outputs other sites that don't contain UK in their name.
By the way, I am using Powershell_ISE.exe.