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

Application pool has not set in new web site after IIS migration from IIS 6 to IIS 8.5 using power shell script

$
0
0

I need to migrate a .NET website from IIS 6 on Server 2003 to IIS 8.5 on Server 2012 R2.

I used below script for this migration

Migrate-WebSite [[-WebSite] ] [-ComputerName]  [-AdminName]  [[-PwdFile] ] [-WebRoot]  [[-AppPool] ] 

Migrate-WebSite -WebSite http://test.com –ComputerName NYOSHEWSDEV01 -AdminName v-nnarayanasamy -WebRoot E:\Data\BSW -AppPool TestAppPool

After run the above script, web site is getting migrated successfully. I mentioned AppPool parameter is "TestAppPool" in the above script. A new app pool "TestAppPool" is getting created successfully.

But this new app pool has not been set in the new migrated site. Default application pool ".NET v2.0 Classic" has been set after migration.

I want to set the new application pool which I mentioned in parameter. Can anyone please help 

Thanks,

Ram


IIS/Powershell/SQL Junior Interview

$
0
0

Hi all,

I wonder if anyone can help
Recently I applied for the job role of an IT Support Engineer (Junior Graduate)
I have tech experience but it's not really related to Powershell and IIS troubleshooting. My experience is more command line Unix based and Oracle/Excel based so I was surprised when I got the call for the interview

I will be given a 2 hour test on the day and the only information I have been given is the following

'Formal technical interview – it will consist of questions around our core technologies; PowerShell, IIS (Windows webhosting and troubleshooting) and SQL Server. The session will last for 2 hours and is not a designed as a direct test of knowledge, but a test of problem solving in a technical environment.'

As a beginner what should I prepare for or the type of questions do you think may come up?

Calling PowerShell from ASP.Net Application on IIS

$
0
0

I am currently developing an application (written in vb.net) to assist authorized users manage DHCP servers in our organisation.  The application does this be calling powershell scripts to query and configure the DHCP servers.

The configuration of our environment is:

- IIS 8.5 running on Windows Server 2012r2

- Windows Authentication

- Application Pool is running as a domain account in Integrated Pipeline mode.  The domain account has been configured for constrained delegation to the DHCP servers.

- The application pool identity and site users have been given "full control" to the application and scripts directories for testing.

- the authenticated user is impersonated programmatically before calling the powershell script using the following code:

Dim winID As System.Security.Principal.WindowsIdentity = CType(HttpContext.Current.User.Identity, System.Security.Principal.WindowsIdentity)
Dim ctx As System.Security.Principal.WindowsImpersonationContext = Nothing
ctx = winID.Impersonate()

Dim rs As Runspace = RunspaceFactory.CreateRunspace()
rs.Open()

Dim rsPipeline As Pipeline = rs.CreatePipeline()
rsPipeline.Commands.AddScript(strScript)

objResults = rsPipeline.Invoke()

rs.Close()
ctx.Undo()

Everything is working as expected BUT only if the user is a member of the "Administrators" group on the IIS server.  If they are not a member of the local administrators then the following exception is thrown when they click on the button that calls the above code:

Access denied
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: Microsoft.Management.Infrastructure.CimException: Access denied

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[CimException: Access denied ]
   Microsoft.Management.Infrastructure.Internal.Operations.CimSyncEnumeratorBase`1.MoveNext() +556
   System.Linq.Enumerable.SingleOrDefault(IEnumerable`1 source) +121
   Microsoft.Management.Infrastructure.CimSession.TestConnection(CimInstance& instance, CimException& exception) +184

[CimJobException: Cannot connect to CIM server. Access denied ]
   System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord) +7810839

[CmdletInvocationException: Cannot connect to CIM server. Access denied ]
   System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input) +14654780
   System.Management.Automation.Runspaces.Pipeline.Invoke() +14
   xxxxxxxxxxx.PowershellUtilities.PowershellUtilites.ExecutePSScript() +146
   xxxxxxxxxxx.DHCP.GetDHCPScopeInfo() +128

The powershell script being run is a simple one line script:

Get-DhcpServerv4Scope -ComputerName servername.mydomain

If a user logs in to the IIS server they can run the script without any problems.  While logged in to the server if they open a browser and enter the URL "http://localhost/sitename" the site and scripts function as expected.  However if they enter the URL"http://fqdn_of_server/sitename" the above error is displayed.

I am thinking this is most likely an IIS configuration issue, but any suggestions or advice would be appreciated.

How to create virtual directory for all the website in my IIS with powershell script?

$
0
0

Hi, I'd like to create several virtual directory with same name under all the IIS site. So how could I achieve this using powershell script? Any suggestion will be appreciate. 

How to change the application pool advanced setting via powershell?

$
0
0

Hi, I can't change the setting via application pool advanced setting like orphanWorkerProcess via IIS application pool user interface for some reason. So is there any way else to change the value like powershell script? Beisdes, How could I change the error page for mutiple website at the same time? Any suggestion will be appreciate. Thanks.

IIS 8.5 Self Signed Certificate on Windows Server 2012 R2

$
0
0

I want to write a powershell script using new-selfsignedcertificate command and using -notafter parameter for 20 years. The script is for IIS 8.5 running on Windows Server 2012 R2. It seems this only works for Windows Server 2016. The error I am receiving on every parameter I use is "a parameter cannot be recognized." 

Powershell script working on Console app but not working on ASP.NET

$
0
0

Hi All,

I Have a powershell script to connect on Skypo for Business Online and it is working on powershell execution also on Console application but when I call from ASP.NET not working:

           string command = @"$PlainPassword ='****';$UserName = '****';$SecurePassword = $PlainPassword | ConvertTo - SecureString - AsPlainText - Force;$SkypeOnlineCred = New - Object - TypeName System.Management.Automation.PSCredential - ArgumentList $UserName, $SecurePassword;
                                Remove - Variable - Name PlainPassword;
                                Remove - Variable - Name SecurePassword;
                                Remove - Variable - Name UserName;
                                try
                                {$SkypeOnlineSession = New - CsOnlineSession - Credential $SkypeOnlineCred;
                                     Import - PSSession - Session $SkypeOnlineSession | Out - Null;
                                }catch { Throw $_ }";



            var initial = InitialSessionState.CreateDefault();
            initial.ImportPSModule(new string[] {
                "C:\\Program Files\\Common Files\\Skype for Business Online\\Modules\\SkypeOnlineConnector\\SkypeOnlineConnectorStartup.psm1"
}); using (Runspace runspace = RunspaceFactory.CreateRunspace(initial)) { // Open runspace runspace.Open(); // Initialize PowerShell engine using (PowerShell shell = PowerShell.Create()) { shell.Runspace = runspace; // Add the script to the PowerShell object shell.Commands.AddScript(command); try { // Execute the script var results = shell.Invoke(); if (shell.Streams.Error.Count > 0) { throw new Exception(shell.Streams.Error[0].Exception.Message); } // display results, with BaseObject converted to string // Note : use |out-string for console-like output return results; } catch (Exception e) { throw new Exception("On Invoke" + e.Message); } } }



IIS 10 Powershell Cmdlets


How to create Multiple sites using Powershell

$
0
0

Hi All,

I have been handed a project.

I need to create a PowerShell script to create 60  websites on my IIS.

They all will be using http and port 80 and the application pools will have same name as site.

ISitename Mytest            applicationPool MyTest          Port 80 HTTP

Does anyone have a sample script or point me in the right direction.

Thanks

Mark

W3WP process stopped by Terminal Server

$
0
0

Hi all: I'm accessing an Windows Server 2012 using a Terminal Server Session. The server has a set of DCOM classes that are served by IIS and when we finish inspecting the server andclose the TS session, we get the web server down and all the DCOM objects stop functioning. Can anybody tell me how do we get the problem fixed. Thank you.

IIS 8.5 Logging to Event Tracing using PowerShell

$
0
0
So, my main goal is to be able to change the defaulted 'Log Event Destination' in IIS 8.5 'Logging' to the value 'Both Log File and ETW Event' using PowerShell in order to change this attribute across multiple Web Servers.

(InetMgr.exe >> Logging >> Log Event Destination >> Both Log File and ETW Event radial button)

Now, when I make this change using the UI, the change in system.applicationHost is it adds logTargetW3C="File, ETW" at the location "Sites/SiteDefaults/logFile."

So, to me that means that:

$Computers = "Host1","Host2","Host3"
$Session = New-PSSession -ComputerName $Computers
Invoke-Command -Session $Session {
Set-WebConfigurationProperty -Filter System.Applicationhost/Sites/SiteDefaults/logfile -Name logTargetW3C -Value "File, ETW"}

Should give me the desired effect. The command runs without errors, but nothing changes in the system.applicationHost file. Even InetMgr is still defaulted to 'Log File Only.'

This is because the 'logTargetW3C' Property doesn't exist yet..

I then run the same command with

Add-WebConfigurationProperty
instead of

Set-WebConfigurationProperty
and then PowerShell errors out.

What am I doing wrong here?

Change application identity in IIS

$
0
0

Hi

Is there a way to change identities of all applications that begin with 'MSExchange' to LocalSystrem, within IIS application pool?

Thanks

Regards

How to create the virtual directory for all the IIS sits with powershell

$
0
0

Hi,

I'd like to know how could I use virtual directory for all IIS sites? In addition, what if I want to create mutiple virtual directory for the sam site?

Any suggestions will be appreciated.

Convert mutipart/form-data curl into powershell Invoke-WebRequest

$
0
0

I am trying to convert two curl commands into powershell using Invoke-WebRequest. I got the first curl command converted and it does the handshake. For the second one I got a 404 error. I have trouble with formating the parameters for –form file1=@%TSV_UPLOAD_FILE% –form format="XYZ User License Upload"...

Here are the curl commands.

curl –verbose –insecure –cookie-jar %OUTPUT_FOLDER%\cookiejar.txt –cookie I2KBRCK=1 –data login=email@gmail.com –data password=pass –dump-header %OUTPUT_FOLDER%\headers_received_1.txt –output %OUTPUT_FOLDER%\curl_output_1.html –location https://website.org/action/doLogin > %OUTPUT_FOLDER%\curl_verbose_output.txt 2>&1



curl –verbose –insecure –cookie %OUTPUT_FOLDER%\cookiejar.txt –form file1=@%TSV_UPLOAD_FILE% –form format="XYZ User License Upload" –form email=email@gmail.com –dump-header %OUTPUT_FOLDER%\headers_received_2.txt –output %OUTPUT_FOLDER%\curl_output_2.html https://website.org/action/directSubscriptionUpload >> %OUTPUT_FOLDER%\curl_verbose_output.txt 2>&1



Here is the powershell code:

$FullPathTSVToSend = 'C:\file.tsv'$outFilePath = 'C:\curl_output_1.html'$outFilePathVerbose = 'C:\curl_verbose_output.txt'$secpasswd = ConvertTo-SecureString "pass" -AsPlainText -Force$mycreds = New-Object System.Management.Automation.PSCredential ("email@gmail.com", $secpasswd)$boundary = [System.Guid]::NewGuid().ToString()$LF = "`n"$bodyLines = ("–$boundary",
'Content-Disposition: form-data; name="file1"',","$FullPathTSVToSend","–$boundary",
'Content-Disposition: form-data; name="format"',","XYZ User License Upload","–$boundary"
) -join $LF$url = "https://website.org/action/directSubscriptionUpload"

Invoke-WebRequest -Uri "https://website.org/action/doLogin" -Credential $mycreds -Verbose -SessionVariable myWebSession -Method Post -OutFile $outFilePath
Invoke-WebRequest $url `
-Method Post `
-ContentType "multipart/form-data; boundary=$boundary"`
-Body $bodylines `
-Credential $mycreds `
-Verbose `
-WebSession $myWebSession `
-OutFile $outFilePath



IIS in Docker: Unable to remove Default SSL-Binding Certificate for Remote Management

$
0
0

Hello all,

hope this is the correct place for my question. I am trying to set up an IIS server in Docker, derived from a standard windows server core installation. Trying to remove the standard self-signed ssl certificate in order to replace it with a custom certificate fails in my setup.

<div class="cooked">

After creating an IIS Server in Docker based on the windows core server image, I seem to be running into issues when trying to install a custom certificate for remove management.

The following minimal example Dockerfile can serve to show the issue. For everyone not using docker, an 'untouched' windows server core edition is downloaded and every RUN command executed in order:

FROM microsoft/windowsservercore
SHELL [“powershell”, “-command”]
#! Install IIS Management Service
RUN Install-WindowsFeature -name Web-Server -IncludeManagementTools
RUN Dism /online /enable-feature /featurename:IIS-ManagementService /all
#!Remove SSL Certificate for Remote Management: Option 1
RUN Import-Module WebAdministration;Remove-Item -Path IIS:\SslBindings\0.0.0.0!8172
#!Remove SSL Certificate for Remote Management: Option 2
RUN netsh http delete sslcert ipport=0.0.0.0:8172

When trying to remove the existing binding with certificate in order to install a custom certificate, the first option that should normally be available, for example according to This Link,fails with the following error:

grafik

The second option, propagated for instance by This Site fails with the following output:

SSL Certificate deletion failed, Error: 1
Incorrect function.

What would be a proper way to replace the existing ssl binding?

Thank you for your help!

</div>

How could I create the custom error page for all sites

$
0
0

Hi,

I have fix the iis installation issue but all the defualt error page missing. I'm not sure why I got this issue. So I decide to create the error page manually. How could I create the error page for all sites at the same time? Thanks in advance.

PowerShell Just Enough Administration - WebAdministration cmdlets fail when parameters are added

$
0
0

I’m trying to configure PowerShell Just Enough Administration to allow developers to start and stop specific IIS application pools.  If I allow the stop-webapppool and start-webapppool cmdlets with no parameters, everything works fine through JEA.  If you add any parameters to them, to restrict developers to managing only their own application pools, the commands fail.

In the role capabilities file, the following VisibleCmdlets section works with no errors:

VisibleCmdlets='Stop-WebAppPool','Start-WebAppPool'

After adding parameters, the VisibleCmdlets section looks like this:

VisibleCmdlets=@{Name='Stop-WebAppPool';Parameters=@{Name='NAME';ValidateSet='Pool1','Pool2'} },
@{Name ='Start-WebAppPool'; Parameters=@{Name='NAME'; ValidateSet='Pool1','Pool2'}}

With parameters, the commands fail with the error: 

The term 'Stop-WebAppPool' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

    + CategoryInfo          : ObjectNotFound: (Stop-WebAppPool:String) [], CommandNotFoundException

    + FullyQualifiedErrorId : CommandNotFoundException

I’m only running into this problem with WebAdministration cmdlets.  If anyone can suggest a workaround, it would be appreciated.  I've reached the end of the Internet looking for an answer.

IIS in Docker: Set up shared configuration by native powershell script

$
0
0

Hi all,

I am trying to set up several IIS server instances in Docker. I figured, a shared configuration placed in a docker share would be the best way to go about that.

This article here: IIS shared configuration setup explains how the server can be setup programmatically to be pointed to a shared configuration using this script:

try
{
    var config = WScript.CreateObject( "Microsoft.ApplicationHost.WritableAdminManager" );
  config.CommitPath = "MACHINE/REDIRECTION";
    var section = config.GetAdminSection( "configurationRedirection","MACHINE/REDIRECTION" );
  section.Properties.Item( "enabled" ).Value = true;
  section.Properties.Item( "path" ).Value = "\\\\somemachine\\sharefile://folder/";
  section.Properties.Item( "userName" ).Value = "testuser";
  section.Properties.Item( "password" ).Value = "testuser";
  config.CommitChanges();
}
catch(e)
{
  WScript.Echo(e.number);
  WScript.Echo(e.description);
}

My problem is that this script seems to be written in node.js. I am a bit reluctant to install java on the docker container just to be able to execute that script. Would there be a way to run this or an equivalent script in native powershell?

Thank you for your hints!

How to use powershell script to modify the URL rewite rule?

$
0
0

Hi,

I would like to use powershell script to modify the specific attribute or parameter for specific URL rewirte rule. So how could I acehive this? Thanks in advance.  Besides, What script should I use if I wan't to remote manage the URL rewrite rule in remote server? Thanks in advance.

Extract return code from IIS powershell command

$
0
0

Hi,

let's say I run this command :

Set-WebConfigurationProperty system.web/sessionState -pspath MACHINE/WEBROOT -name regenerateExpiredSessionID -value WrongValue


I will get the following error :

Set-WebConfigurationProperty : String was not recognized as a valid Boolean.
At line:1 char:1+ Set-WebConfigurationProperty system.web/sessionState -pspath MACHINE/WEBROOT -na ...+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo          : NotSpecified: (:) [Set-WebConfigurationProperty], FormatException+ FullyQualifiedErrorId : System.FormatException,Microsoft.IIs.PowerShell.Provider.SetConfigurationPropertyCommand

but $lastExitCode returns 0.

Is there any way to extract more informative return code to ensure that operation succeed/failed? 

and if failed, to get the exact return code? (as appcmd with the same command return 13,which is ERROR_INVALID_DATA)

Thanks.

Viewing all 136 articles
Browse latest View live


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