Is there any powershell script or any vbscript which can display all bindings of sites from IIS?
Try the Get-WebBinding cmdlet (IIS 7 and up):
Import-Module WebAdministration
Get-WebBinding
Try this:
Import-Module WebAdministration
$Websites = Get-ChildItem IIS:\Sites
$site = $websites
$site.bindings.Collection
Related
I'm setting up some virtual machines to run my service. There may be several, so I'm trying to automate the process. I've got a PowerShell script that successfully build the virtual machine, but now I want to install the dependent software that my .NET Core Web Application requires in the same script.
The first dependency I want to install is .NET 5.0 Runtime. I've done this many times from the browser, but now I want to commit this to a script that runs after the VM has been built.
Test locally or on a test VM by installing using the dotnet-install-script and finalize the parameters. Then use Set-AzVMExtension to install that script using custom script extension. The code would look like this (not tested)
$Command = "&powershell -NoProfile -ExecutionPolicy unrestricted -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; &([scriptblock]::Create((Invoke-WebRequest -UseBasicParsing 'https://dot.net/v1/dotnet-install.ps1'))) <additional install-script args>"
$Settings = #{"commandToExecute" = "Powershell $Command";};
Set-AzVMExtension `
-ResourceGroupName "ResourceGroupName" `
-Location "Location" `
-VMName "VirtualMachineName" `
-Name "ExtensionName" `
-Publisher "Contoso.Compute" `
-Type "CustomScriptExtension" `
-TypeHandlerVersion "1.1" `
-Settings $Settings
Full details and schema of settings custom-script-windows
You can also use Set-AzureVMCustomScriptExtension for running custom scripts.
As #amit_g recommended, you can use Azure VM run command functionality to run install .net with scripts by PowerShell directly to meet your requirement.
This seems to work pretty well:
Invoke-AzureRmVMRunCommand -ResourceGroupName "$resourceGroupName" -Name "$machineName" -CommandId "RunPowerShellScript" -ScriptPath "configureMachine.ps1" -Parameter #{"machineName" = "$machineName"}
The contents of the Powershell script look something like this:
# The name of the VM is passed in as the first parameter.
param ($machineName)
if ($machineName -eq $null)
{
Write-Host "Usage: configureMachine -machineName <machineName>";
Exit;
}
# Download the agent installation files.
$agentZip="agent.zip";
Invoke-WebRequest -Uri "https://vstsagentpackage.azureedge.net/agent/2.181.1/vsts-agent-win-x64-2.181.1.zip" -OutFile $agentZip
# Unpack them.
$agentDirectory="$env:SystemDrive\azagent";
Add-Type -AssemblyName System.IO.Compression.FileSystem;
[System.IO.Compression.ZipFile]::ExtractToDirectory($agentZip, $agentDirectory);
# Configure the machine to work as a DevOps Agent.
&"$agentDirectory\config.cmd" --unattended --deploymentgroup --deploymentgroupname "Production" --agent "$machineName" --runasservice --work "_work" --url "https://dev.azure.com/theta-rex/" --projectname "openbook" --auth PAT --token te64yuv36tina2rvc2lsvwcsvctpwomiewz5fxihcubbdzaasoka
# Remove the Agent Zip files when installation is complete.
Remove-Item $agentZip;
# Download and install .NET 5.0
Invoke-WebRequest -Uri "https://dot.net/v1/dotnet-install.ps1" -OutFile "dotnet-install.ps1"
&"./dotnet-install.ps1" -Channel 5.0 -Runtime aspnetcore -InstallDir "C:\Program Files\dotnet"
The end result is a machine configured to participate in Azure DevOps and ASP.NET 5.0.
i would like to install the software(.msi file) on a virtual machine using custom extension script.
Below is my powershell custom extension script.
$computername = 'testingpurpose'
$sourcefile = "//fossies.org/windows/misc/mysql-workbench-community-8.0.18-winx64.msi"
$destinationFolder = "\\$computername\C$\Temp"
Copy-Item -Path $sourcefile -Destination $destinationFolder
Invoke-Command -ComputerName $computername -ScriptBlock { Msiexec /i //fossies.org/windows/misc/mysql-workbench-community-8.0.18-winx64.msi /log C:\MSIInstall.log }
(or)
Start-Process -destinationFolder //fossies.org/windows/misc/mysql-workbench-community-8.0.18-winx64.msi -ArgumentList '/i',$destinationFolder,'/q' -Wait -PassThru -Verb "RunAs"
According to my research, we can use choco to install mysql-workbench on windows Vm. For more details, please refer to the blog.
My script is as below
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
choco feature enable -n=allowGlobalConfirmation
choco install mysql.workbench
I am using the PnP approach for getting the publishing site template and creating a new sitecollection and applying the template so that i get the replica of the source site.
I am getting the error- Scope of template does not match target while running
the below powershell script to apply the template -
$web="https://shareptdev.sharepoint.com/sites/newpub/replicasite
$templateFile = "E:\Path\template.xml";
Apply-PnPProvisioningTemplate -Web $web -Path $templateFile
The variable $web must be your site context must use the Get-PnPWeb on the connected site. Something like this:
$siteUrl = "https://shareptdev.sharepoint.com/sites/newpub/replicasite"
Connect-PnPOnline -Url $siteUrl -UseWebLogin
$web = Get-PnPWeb
$templateFile = "E:\Path\template.xml"
Apply-PnPProvisioningTemplate -Web $web -Path $templateFile
I wish to find the version of IIS using a powershell (or WMI) query.
The following is the query which I have used.
Get-WmiObject -namespace "root\microsoftiisv2" -query "select MajorIIsVersionNumber from IISWebInfo"
I tested this query using powershell console in a 'Windows 8' PC with 'IIS 8'. But the result is 7 , where the expected version Number is 8.
Can someone help me to solve this issue?.
You can try:
get-itemproperty HKLM:\SOFTWARE\Microsoft\InetStp\ | select setupstring,versionstring
Even though the thread is little old,this is the link I landed first. So letting you know what I found.
The below command helped me find the IIS version correctly on IIS 8.5 (Windows 2012 R2) and 7.5 Windows 7 SP1.
[System.Diagnostics.FileVersionInfo]::GetVersionInfo("$env:SystemRoot\system32\inetsrv\InetMgr.exe").ProductVersion
Reference:
https://forums.iis.net/p/1171695/1984536.aspx : Answer from f00_beard
If you want the decimal value for order comparison.
$iisInfo = Get-ItemProperty HKLM:\SOFTWARE\Microsoft\InetStp\
$version = [decimal]"$($iisInfo.MajorVersion).$($iisInfo.MinorVersion)"
Here's a little ScriptBlock function that I created based on the answer from #C.B. to get the IIS Version from a remote computer.
$pwd = convertto-securestring "yourstrongpasswordhere" -asplaintext -force
$cred=new-object -typename System.Management.Automation.PSCredential -argumentlist "machinenamehere\adminusernamehere",$pwd
$iisversion= Invoke-Command -ComputerName $machineName -ScriptBlock {
$(get-itemproperty HKLM:\SOFTWARE\Microsoft\InetStp\).setupstring
} -Credential $cred
Write-Host iisversion = $iisversion
If($iisversion -like '*IIS 6*'){
Write-Host This server uses IIS6
}
If($iisversion -like '*IIS 7*'){
Write-Host This server uses IIS7
}
For purely the version, I prefer checking the info on the w3wp executable.
Per the "how-to" article from MSFT:
If(Test-Path $w3wpPath) {
$productProperty = Get-ItemProperty -Path $w3wpPath
Write-Host $productProperty.VersionInfo.ProductVersion
}
Else {
Write-Host "Not find IIS."
}
I am trying to add an MSMQ binding for my IIS Web Site, correct binding should look like this:
So I am executing following line in PowerShell:
New-WebBinding -Name "My Site" -Protocol net.msmq -HostHeader "localhost"
and it creates the following binding:
prefixing it with *:80:, so my MSMQ messages don't get picked up by WCF service. Maybe I am doing it wrong? How to create a binding with Binding Information set to just "localhost" using this PowerShell comandlet?
Commandlet codumentaiton can be found here.
Looking at the decompiled code of the cmdlet, looks like it adding the IPAddress and Port information in the binding and there is no workaround to it.
Relevant sections from the code:
private string ipAddress = "*";
...
builder.Append(this.ipAddress);
...
builder.Append(":" + this.sitePort.ToString(CultureInfo.InvariantCulture) + ":");
But you can do what the cmdlet actually does ( below code from cmdlet):
new-itemproperty -path "IIS:\sites\test" -name bindings -value #{protocol="net.msmq"; bindingInformation="localhost"}
Give this a try:
New-ItemProperty "IIS:\sites\NameOfYourSite" -name bindings -value #{protocol="net.msmq";bindingInformation="localhost"}
If your are running PowerShell (Core), a.k.a PowerShell >v7.1.x, you will find yourself in trouble because...
WARNING: Module WebAdministration is loaded in Windows PowerShell using WinPSCompatSession remoting session;
please note that all input and output of commands from this module will be deserialized objects.
If you want to load this module into PowerShell please use 'Import-Module -SkipEditionCheck' syntax.
The IIS provider isn't available via remoting session.
The easiest trick is to redirect string via pipeline to Windows PowerShell.
"Import-Module WebAdministration;New-ItemProperty -Path `"IIS:\Sites\$($configuration.Website.Name)`" -Name Bindings -value #{protocol = `"net.msmq`"; bindingInformation = `"localhost`" }" | PowerShell
In this example, the website name is read from the configuration JSON. You can replace it by a hard-coded site name.