Quantcast
Channel: PowerShell
Viewing all 136 articles
Browse latest View live

Check if application pool is stopped and restart

$
0
0

Hello,
I'm try to create a powershell script for monitoring status of all application pools on my server, and if one is stopped, restart it.
The script is simple, but I try to stop one application pool (in IIS Manager this pool is stopped), but the script he sees it as started, no stopped :|

Can you help me ?

Import-Module WebAdministration
IIS:
Set-Location AppPools
$ApplicationPools = dir
foreach ($item in $ApplicationPools)
{
$ApplicationPoolName = $item.Name
$ApplicationPoolStatus = Get-WebAppPoolState $ApplicationPoolName
$ApplicationPoolStatusValue = $ApplicationPoolStatus.Value

#Write-Host "$ApplicationPoolName -> $ApplicationPoolStatusValue"

if($ApplicationPoolStatus.Value -ne "Started")
{
Write-Host "-----> $ApplicationPoolName found stopped."
Start-WebAppPool -Name $ApplicationPoolName
Write-Host "-----> $ApplicationPoolName started."
}
}


create virual directory, app pool using powershell

$
0
0

Hi,

  • Create website, app pool using power shell.
  • set created app pool to created web site.
  • Change the app pool managed pipe line mode to classic.

I need above 3 things using power shell.

Thanks.

Migrating a Web Server from IIS 6.0 to IIS 8 2012 R2 with Powershell?

$
0
0

Dear Professionals,

I am planning to move my 100 Websites from windows 2003 to windows 2012 R2 with powershell without troubles and problems?

anyone can tell me how???

I do not want to move one by one and manually, I want all to move once without changes in configuration with powershell -

if you have done it before please let me to know, I would be glad

thanksSmile

Appcmd export and import commands

$
0
0

Hi Everyone,

I have the requirement to move my site hosted in one web server to the azure VM. 

I know about appcmd export and import commands for moving to different servers.  But will these commands work for the different domains like my azure VM?

Please suggest the approach.

Get physical path from IIS using powershell script

$
0
0

Hey

I am Amrendra, I need to get the physical path of the websites present in the IIS using powershell script. When, I executed command "Get-Childitem IIS:\", I found an error

Get-ChildItem : Cannot find drive. A drive with the name 'IIS' does not exist.
At line:1 char:1
+ Get-ChildItem IIS:\
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (IIS:String) [Get-ChildItem], DriveNotF
oundException
+ FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.GetChildIte
mCommand

and when I executed "Import-Module WebAdministration", I found following error.

Import-Module : The specified module 'WebAdministration' was not loaded because no
valid module file was found in any module directory.
At line:1 char:1
+ Import-Module WebAdministration
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (WebAdministration:String) [Import
-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.Im
portModuleCommand

Exchange report email

$
0
0

Hi,

Not sure if this is the right place to discuss this, but I'm trying to create a report with mount point free space on two servers and DAG whitespace.

For mount points I have this script:

$servernames = servername

Get-WmiObject -computer $servernames win32_volume|where-object {$_.caption -ne $null -and $_.label -ne “System Reserved” -and $_.drivetype -eq 3}|select-object __SERVER,Name,

@{Name="Capacity(GB)";expression={[math]::round(($_.Capacity/ 1073741824),2)}},

@{Name="FreeSpace(GB)";expression={[math]::round(($_.FreeSpace / 1073741824),2)}},

@{Name="Free(%)";expression={[math]::round(((($_.FreeSpace / 1073741824)/($_.Capacity / 1073741824)) * 100),0)}}

and for exchange dag information I use this

Get-MailboxDatabase -Status dag01* | select name,@{Name="InUse";Expression={$_.DatabaseSize- $_.AvailableNewMailboxSpace }} | select name,{$_.InUse.toGB()} | sort-object name

First question is how do I report the mount points script to two servers, I've tried adding two names to $servernames but that doesnt work.

Second question is how do I add both together so I can email the script out.

Thanks for looking and sorry again if on the wrong forum!

Setting and Getting Server Config with WMI

$
0
0

Hello, I'm familiar with performing apphostconfig changes using appcmd or Microsoft.Web.Administration. However I'm now limited to a ruby solution which fortunately has access to WMI through its win32ole class.

So far I can do simple apphost updates that do not require me to drill down into a particular element:

$IIS_Server = Get-WMIObject -Namespace ROOT/WebAdministration -Class Server

$IIS_Server.GetAttribute('system.webServer/httpCompression', 'NoCompressionForHttp10')

ReturnValue      : true

$IIS_Server.SetAttribute('system.webServer/httpCompression', 'NoCompressionForHttp10', $null, $null, $false)

$IIS_Server.GetAttribute('system.webServer/httpCompression', 'NoCompressionForHttp10')

ReturnValue      : false

Where I'm having difficulties is specifying an element like the gzip HttpCompressionSchemeElement to access its DynamicCompressionLevel attribute value.

Thinking something like this would work with no luck:


$IIS_Server.GetAttribute("system.webServer/httpCompression -[name='gzip']", 'DynamicCompressionLevel')

$IIS_Server.GetAttribute("system.webServer/httpCompression", 'DynamicCompressionLevel', "HttpCompressionSchemeElement.Name='gzip'")

Hoping someone here has experience implementing this particular wmi class method to set me straight.

PSEXEC for loading a webpage on a remote server


Using powershell to configure FTPS

$
0
0

Hello all --

I have a network of 700 POS machines, running Windows 7 Embedded, with IIS installed.  I use the IIS only for FTP functionality to send and receive files from my POS.

I am now looking to make this FTP over SSL, rather than plain text FTP.  I successfully set this up in my lab, manually.  Now that I am looking to deploy it to the rest of the fleet, I would love to automate it via powershell.  I am pretty good with automating processes with powershell already, but I don't have much experience with the IIS side of things.

Currently I have a script that looks like this:

# path to certificate$certPath = 'C:\Upgrades\cert\retail.mydomain.local.pfx'

# import the pfx certificate into the personal store
certutil.exe -importPFX $certPath

# add the web administration module
Import-Module -Name webadministration

$defaultFTP = 'IIS:\Sites\Default FTP Site'

# set the properties to require FTP over SSL
Set-ItemProperty -Path $defaultFTP -Name ftpServer.security.ssl.controlChannelPolicy -Value 1
Set-ItemProperty -Path $defaultFTP -Name ftpServer.security.ssl.dataChannelPolicy -Value 1

This imports my cert into the personal store, and requires SSL over FTP (both data channel and control).  

I am thinking that now I need to be able to tell the FTP site to use the certificate in my personal store, and set the port for the data channel (I picked 5001) in the FTP Firewall Support section.

I haven't really been able to find what I am looking for via searching - I am hoping someone here can help point me in the right direction.

Thanks

sb

turn on IIS features automatically

$
0
0

how do i create a setup file that can automatically turn on IIS features

resource cannot be found. only default page shows

$
0
0

Please I keep getting a "resource not found" error when i deploy/install a web application/setup to IIS. Only the default page shows. Any time I try to navigate to a page from the default page I get the stated error. hope you can help me resolve it.

regards

Francis

iis: Creating virtual folder using powershell that points to an unc location

$
0
0

Hi,

I have been trying to use powershell to create a virtual folder under one website and that virtual folder is physically located in a share....

I was able to create such virtual folder in the IIS manager, but getting error using powershell...

PS IIS:\> New-WebVirtualDirectory -name docs2 -site dev85 -physicalpath "\\dev85\docs\drawings"
New-WebVirtualDirectory : A parameter cannot be found that matches parameter name 'physicalPath'.
At line:1 char:1
+ New-WebVirtualDirectory -name docs2 -site dev85 -physicalpath "\\dev85\docs\drawings"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [New-WebVirtualDirectory], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.IIs.PowerShell.Provider.NewVirtualDirectoryCommand

help!

Changing properties for ManagedPipelineMode and ManagedRuntimeVersion

$
0
0

Hi All,

I have created a new application pool using the following PS code: 

New-Item IIS:\AppPools\AppTest
Set-ItemProperty IIS:\AppPools\AppTest -name processModel -value @{userName="Test\test1";password="123456";identitytype=3}
Set-ItemProperty IIS:\AppPools\AppTest -name ManagedRuntimeVersion -value "v2.0"
Set-ItemProperty IIS:\AppPools\AppTest -name ManagedPipelineMode -value "1"

The application pool is created but the Pip line is set to "Integrated" instead of "Classic" and the Runtime Version is v4.0 instead of the required v2.0. there was no any kind of error or event during the execution of the commands.

I have other, working,  application pools on this server that are already using the parameters I am trying to set.

I can change those parameters manually using the IIS UI and it's working, but I need a working script.

Thank you in advance,

Uri

File Copy Issue - PrecompiledApp.config In Use - How to Combat?

$
0
0

Hi there,

Here's a brief overview of what I'm trying to do.  Our build process currently copies needed files to a network location via a Post-Build script in TFS.  These files are then copied to a website on a different machine.  What happens is that I get a successful build, but when I immediately fire off another build for testing, I get an error that the file PrecompiledApp.config cannot be copied as it is in use.  This is during a Robocopy opearation, called from the script.

I've seen posts that copying the files from network shares to website servers isn't the best way to go.  Others say this is fine.  Those opposed to it offer that the files should be zipped, the .zip file copied, then extracted.  I'm wondering, if the above mentioned file is actually tied up, if the zip method would have any different effect.

I'm running some remote powershell stuff on the site server and I was wondering if there was something I could do to halt IIS, copy the files, then start back up.  I've tried stop/start-website, iisrestart, etc, but nothing seemed to help.  I'm running IIS 8.5 and I ran across start-webcommitdelay so I thought I would give that a try.  I'm not even sure if it applies, but I'm running out of ideas.  So, the start-webcommitdelay seemed to fire from the script.  The copy seemed to go OK, but the stop-webcommitdelay errored - something like couldn't execute due to condition of the object.

It doesn't seem that these cmdlets will help anyway.  I commented them from the post-build script, ran the start-webcommitdelay on the site server then ran my build = same issue.

This may not and probably isn't the best forum for this, but I'm wondering what I can do with PowerShell to completely shut down IIS on the remote machine, then the files would be copied, then I would like to start IIS backup.

Any ideas would be greatly appreciated!!

Unable to run Power shell scripts inside asp.net mvc-5 web application deployed under IIS-8

$
0
0

I am working on an asp.net MVC-5 web application which is deployed under IIS8. Inside my web application i have the following method which will run some power cli scripts and save the returned results inside our Database :-

 var shell = PowerShell.Create();
                        var shell2 = PowerShell.Create();
                        var shell3 = PowerShell.Create();

                        string PsCmd = "add-pssnapin VMware.VimAutomation.Core; $vCenterServer = '" + vCenterName + "';$vCenterAdmin = '" + vCenterUsername + "' ;$vCenterPassword = '" + vCenterPassword + "';" + System.Environment.NewLine;



                        PsCmd = PsCmd + "$VIServer = Connect-VIServer -Server $vCenterServer -User $vCenterAdmin -Password $vCenterPassword;" + System.Environment.NewLine;



                        PsCmd = PsCmd + "Get-VMHost " + System.Environment.NewLine;

                        //Powercli script to the the hypervisor network info
                        string PsCmd2 = "add-pssnapin VMware.VimAutomation.Core; $vCenterServer = '" + vCenterName + "';$vCenterAdmin = '" + vCenterUsername + "' ;$vCenterPassword = '" + vCenterPassword + "';" + System.Environment.NewLine;



                        PsCmd2 = PsCmd2 + "$VIServer = Connect-VIServer -Server $vCenterServer -User $vCenterAdmin -Password $vCenterPassword;" + System.Environment.NewLine;



                        PsCmd2 = PsCmd2 + " Get-VMHost " + vCenterName + "| Get-VMHostNetworkAdapter -VMKernel" + System.Environment.NewLine;



                        shell.Commands.AddScript(PsCmd);
                        shell2.Commands.AddScript(PsCmd2);

                        dynamic results = shell.Invoke(); // execute the first powercli script
                        dynamic results2 = shell2.Invoke();//execute the second powercli script

                        if (results != null && results.Count > 0 && results[0].BaseObject != null) // the powercli executed successfully

now when i deploy this web application on our test server which is (Windows Server 2008 R2 + IIS-7) the application will run the above code without any problems.

But on our production environment the method will fail to run the powershell scripts and the powershell results will be null. now on production we have (Windows Server 2012 R2+ IIS-8) unlike our test server which is (Windows Server 2008 +IIS7).

Finally I already did these setting inside the production environment:-

  1. I define a domain user inside the DefaultAppPool:-

enter image description here

  1. i add the above domain user to the local administration group inside the host machine:-

enter image description here

  1. i enable anonymous authentication and i define the IUSR as follow, i also try changing this to "Application Pool Identity" but will not work also:-

enter image description here

Final note when i tried to manually run the above scripts directly inside the powercli window on the production environments, the scripts will work well...

so can anyone advice what is causing the powershell scripts to stop working inside my asp.net mvc web application which is deployed under IIS-8 ?

Thanks


Isapi and cgi restrictions, change restriction via powershell

$
0
0

Hello

On IIS I already have two "ISAPI and CGI Restrictions" listed.

Both listed are named "ASP.NET v4.0.30319" and pointing to different paths

How can I change the restriction to Allowed on both of them?

I can add new ones with the below code, but cant seem to change on already existing ones.

Add-WebConfiguration -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.webServer/security/isapiCgiRestriction" -value @{description='somedescription';path='C:\Path\to\dlls';allowed='True'}

Manged Folders

$
0
0

Why would you create a cmdlet to get a list of websites, a list of Applications, a list of Virtual Directories, but not one to get a list of Managed Folders?  I don't understand why you would stop short like this?  I have websites with a great many folders, that have distinct configurations, that I need to access programmatically.

PowerShell version 3 or 5 Installation error

$
0
0

I tried installed Windows PowerShell v3 , v5 or Azure Powershell to prepare working with Azure.  However, all failed on my Windows 7 Sp1 machine.   Azure Storage Command line, Azure Storage Emulator and Azure Compute Emulator were installed successfully. The log of V5 says I need v3. I then install v3 but the log shows. I checked the Program that .Net Framework 4.5.2 was installed with other Azure tool. 

Is it because of Windows 7 sp1  no longer supported?  

DownloadManager Error: 0 : WinInet download error. Uri: http://i.expression.microsoft.com/cc265059.100web(en-us,MSDN.10).png, Error: System.Net.WebException: Url 'http://i.expression.microsoft.com/cc265059.100web(en-us,MSDN.10).png' returned HTTP status code: 404    at Microsoft.Web.PlatformInstaller.ManagedWinInet.OpenUrlAndFollowRedirects(Uri& uri, IntPtr& hInetFile)    at Microsoft.Web.PlatformInstaller.ManagedWinInet.DownloadFile(Uri uri, String fileName, String& contentDispositionFileName)    at Microsoft.Web.PlatformInstaller.UI.DownloadServiceImplementation.DownloadFile(Uri uri, String filePath) DownloadManager Information: 0 : http://i.expression.microsoft.com/cc265059.100web(en-us,MSDN.10).png responded with 404 DownloadManager Information: 0 : Response headers: HTTP/1.1 404 Not Found Content-Type: text/html Server: Microsoft-IIS/7.5 P3P: CP="ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI" X-Powered-By: ASP.NET Date: Fri, 06 Nov 2015 04:21:38 GMT Cteonnt-Length: 1245 Content-Encoding: gzip Content-Length:        795

DownloadManager Error: 0 : WinInet download error. Uri: http://i.expression.microsoft.com/cc265059.100web(en-us,MSDN.10).png, Error: System.Net.WebException: Url 'http://i.expression.microsoft.com/cc265059.100web(en-us,MSDN.10).png' returned HTTP status code: 404    at Microsoft.Web.PlatformInstaller.ManagedWinInet.OpenUrlAndFollowRedirects(Uri& uri, IntPtr& hInetFile)    at Microsoft.Web.PlatformInstaller.ManagedWinInet.DownloadFile(Uri uri, String fileName, String& contentDispositionFileName)    at Microsoft.Web.PlatformInstaller.UI.DownloadServiceImplementation.DownloadFile(Uri uri, String filePath) DownloadManager Information: 0 : Adding product Windows PowerShell 3.0 (PowerShell4) to cart DownloadManager Information: 0 : Adding product 'PowerShell4' DownloadManager Information: 0 : Setting current install to 1 DownloadManager Information: 0 : Starting install sequence DownloadManager Information: 0 : Starting EXE command for product 'Windows PowerShell 3.0'. Commandline is: 'C:\Windows\sysnative\dism.exe /online /enable-feature /featureName:MicrosoftWindowsPowerShell /all'. Process Id: 3964 DownloadManager Information: 0 : Install exit code for product 'Windows PowerShell 3.0' is '87'

DownloadManager Error: 0 : Install return code for product 'Windows PowerShell 3.0' is Failure DownloadManager Information: 0 : Product Windows PowerShell 3.0 done install completed DownloadManager Information: 0 : Increasing current install to 2 DownloadManager Information: 0 : Product: PowerShell4, Install Status: InstallCompleted-Failure, Install Time: 00:00:02.5920049

shows

Not able to get the virtual directories in a web site.

$
0
0

I am using below line of code to retrieve all the virtual directories 

Get-WebVirtualDirectory -site 'Default Web Site' -Application "AppName"

but it gives me below error. 

get-webconfiguration : Retrieving the COM class factory for component with CLSID

{688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed due to the following error: 80040154 Class not registered (Exception

from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

At line:1 char:1

+ Get-WebVirtualDirectory -site 'Default Web Site' -Application "ehrms"

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Get-WebConfiguration], COMException

    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.IIs.PowerShell.Provider.GetConfigu

Can somebody help. i am running this command on windows server 2012

Thanks

Powershell script to export IIS website details

$
0
0
<div class="post-text" itemprop="text">

Hi,

I need to extract all the website details created in our IIS server with the following details. As we have more than 80 sites created in our IIS server, I am searching for an easier way to export these details.

details required :

  • Website Name
  • Bindings
  • State
  • DB Server name [mapped in connection string]
  • DB Name [mapped in connection string]

I am able to extract all the details except DB related available in connection strings using get-website cmdlet. Requesting your help if you know any better way to extract all the information under single file.

Thanks,

Raghavendra.

</div>
Viewing all 136 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>