How can I check if there a folder is converted to Application or not in IIS through Powershell on remote servers? - powershell

I want to check if folders/virtual folders in the IIS are converted to Application or not through Powershell on multiple remote servers. I tried using Get-WebVirtualDirectory but I'm getting an empty response.
I've my site structure like this : IIS:\Sites\Default Web Site\Services\Folder\V4\Task\SomeService and in this, the SomeService is in folder format on some of the remote servers. I need to check on all the servers if it is still in folder format and later on convert it Application. But Get-WebVirtualDirectory is not giving any errors or results.
I was using this query to get the virtual directory : Get-WebVirtualDirectory -site 'Default Web Site' -Application Task

This is a late answer but it may help someone.
Use Get-WebApplication function instead of Get-WebVirtualDirectory.
Example :
Get-WebApplication -site "Default Web Site" -Name "ApplicationName"
In your case :
if((Get-WebApplication -site "Default Web Site" -Name "Services/Folder/V4/Task/SomeService").Count -gt 0) {
some stuff...
}

Related

How to set applicationDefaults.preloadEnabled to True on a IIS WebApplication (instead of WebSite) with Powershell?

I'm including a Powershell script in my WixToolset installer to do various tasks in IIS, and I can't figure out one thing.
My Site in IIS is structured like this:
Sites
Default Web Site
WebApp1
WebApp2
Identity
I am able to set applicationDefaults.preloadEnabled to true on Default Web Site, but I only want to set preloadEnabled on my Identity WebApplication.
With limited Powershell knowledge, I've tried:
Import-Module WebAdministration
Get-WebApplication
Get-WebApplication "Identity"
The code above lists the Identity WebApplication correctly.
cd C:\inetpub\wwwroot
Set-ItemProperty "Identity" -Name applicationDefaults.preloadEnabled -Value True
The code above gives the error:
The property string applicationDefaults.preloadEnabled=True does not exist or was not found.
At line:1 char:1
I've also tried preloadEnabled instead of applicationDefaults.preloadEnabled, same result.
figured it out thanks to the comment from #guiwhatsthat and some extra searching. This is what worked.
Set-ItemProperty "IIS:\Sites\Default Web Site\Identity" -Name preloadEnabled -Value True

Want to stop a specific IIS Site with powershell

Using get-website and save to csv fil. But how to use that data to a list so I can stop a specific IIS site if I got many sites running on same server?
ex a list like this of running websites!
abc.com
def.com
ghi.com
and then run Stop-IISSite -Name $website
Br
Hans
I only no how Get-website to a csv to run!

New-WebApplication fails using network path in physicalpath parameter in powershell

We are trying to create list of applications in a particular site,
For this we have a csv which contains required information for site creation. Below is the format:
Below is the script which we are using to create application in IIS:
foreach($app in $apps){
$appname = $app.path.TrimStart("/")
New-WebApplication -Name $appname -Site $app.Site -PhysicalPath $app.PhysicalPath -ApplicationPool $app.applicationPool -Verbose
}
Problem is application whose code is stored on some network path like \\network\Webapps\appname are giving below error:
New-WebApplication : A parameter cannot be found that matches parameter name 'physicalPath'.
whereas application folder located on same server are being created without any issue,
Have also done test-path \\network\webapps\appname it results in true
What is the issue and how to rectify it?
Issue got resolved, I didn't got what was the exact reason behind that, Have updated my script, basically have assigned values to specific variable than was able to create application.
Updated Script
foreach($app in $apps){
$appname = $app.path.TrimStart("/")
$appSite = $app.Site
$appPath = $app.PhysicalPath
$appPool = $app.applicationPool
New-WebApplication -Name $appname -Site $appSite -PhysicalPath $appPath -ApplicationPool $appPool -Verbose
}
Thanks
First of all, you have to make sure that powershell has permission to access the server corresponding to the network path when creating the site.
When using powershell to create a site, if the physical path of the site is a file in the local disk, you can use New-WebApplication, if it is a UNC path, you should use New-Item.
Under normal circumstances, the UNC path will not be used as the physical path of the main site, but will be added as a virtual directory. Because the domain name of the main site points to the local machine and the UNC points to the remote IP address, the two will conflict because a server error occurred when I created the site through IIS Manager.
$siteName = 'Default Web Site'
$virtualDirectoryName = 'Test'
$physicalPath = '\\UNC-path'
## Init
$virtualDirectoryPath = "IIS:\Sites\$siteName\$virtualDirectoryName"
## Create Virtual Directory where physicalpath is an UNC-path (New-WebVirtualDirectory
wont do)
New-Item $virtualDirectoryPath -type VirtualDirectory -physicalPath $physicalPath
Any chance it's this? That error sounds like it's an issue with the cmdlet and not the data you're feeding it.
https://social.msdn.microsoft.com/Forums/en-US/3e0cb076-6ad4-4b03-bb59-c912174266b0/container-with-iis-cant-create-application-using-powershell-physicalpath-parameter-not-found?forum=windowscontainers
specifically:
You need to import the WebAdministration module. If you're in the container through docker exec simply use:
Import-Module WebAdministration

Remove multiple website from IIS 7.5

I have a web server for shared webhosting purpose based on windows server 2008 R2 and IIS 7.5.
There are currently 450 websites in it IIS server. I want to remove all of the website from the server because this server has been gone out of production.
Is there any script in powershel to automate the deletion of 450 websites or I have to remove them one by one manually.
The Web Server (IIS) Administration Cmdlets in Windows PowerShell will help you here.
The following will remove all websites:
Import-Module WebAdministration
Get-Website | Remove-Website
This won't remove any files so that should be done separately.
Big Thanks to David Martin, but here is what I needed to do in order for it to install and work.
# Get WebAdminstration module
Add-PSSnapin WebAdministration -ErrorAction SilentlyContinue
# Import module in order to run it
Import-Module WebAdministration
# Remove All Websites from IIS
Remove-Website -Name *
I hope this helps others.
Works with IIS 8.5 (Windows Server 2012 R2)
When installed on IIS 7.0 or later Web Deploy adds a context menu item to IIS manager called Deploy.
There are multiple actions available here one of which is the Delete action. There are two options depending on what node you have selected in IIS manager:
Web site : Deploy >> Delete Web Site and Content
Application: Deploy >> Delete Application and Content
For more details...please check below link
http://blogs.iis.net/richma/archive/2010/07/03/deleting-iis-web-sites-applications-and-their-content-with-web-deploy.aspx
This should remove all websites and then remove all webapp pools
Import-Module WebAdministration
Get-Website | Remove-Website
Get-ChildItem IIS:\AppPools\ | Select-Object Name | Foreach-Object {Remove-WebAppPool $_}
If you would like to remove web sites using appcmd , use the following script :
$appCmd = "C:\windows\system32\inetsrv\appcmd.exe"
$sites = & $appcmd list site /text:name | where {$_ -eq "SITENAME"}
$sites | %{ & $appCmd delete site $_}

How to determine if a website is installed in IIS7 with Powershell?

I'm pretty new to powershell, and I'm trying to automate the removal of a prior version of a website and addition of the newer version as a part of a TFS 2010 Build Template (Windows Workflow 4.0). Is it possible to see if a website or web app pool exists in IIS7 with powershell? I've tried running the following command:
import-module WebAdministration
Get-Website -Name "Default Web Site"
The output lists all of the websites installed on the box, not just the default web site.
Name ID State Physical Path Bindings
-------------------------------------------------------------------------
Default Web Site 1 Started %SystemDrive%\inetpub\wwwroot http *:80:
net.tcp 808:*
net.pipe *
net.msmq localhost
msmq.formatname localhost
MyWebsite1 2 Started C:\inetpub\MyWebsite1 http *:80:mywebsite1.com
MyWebsite2 3 Started C:\inetpub\MyWebsite2 http *:80:mywebsite2.com
If I try to run the command without the "-Name" parameter, the result is exactly the same.
You can use Test-Path for both checking web sites & application pools:
Import-Module webadministration
$alias = "MyWebSite1"
$IISPath = "IIS:\Sites\Default Web Site\$alias"
if (Test-Path $IISPath) { Write-Host "$alias exists." }
$IISPath = "IIS:\AppPools"
cd $IISPath
if (Test-Path ".\MyAppPool") { Write-Host "MyAppPool exists." }
I just noticed the same behavior. Seems like its not working as expected. However, you can roll your own:
get-website | where-object { $_.name -eq 'MyWebsite1' }
That just pipes the list returned by get-website to the where-object cmdlet and just return that single object.
If your new to PowerShell, I can't recommend Master PowerShell enough.