Перейти к содержимому

IIS

Как поменять сертификаты на iis для всех сайтов с помощью powershell.

Задача переставить сертификат на всех сайтах так как заканчивается срок.

Экспортируем сертификат в IIS.

Как поменять сертификаты на iis для всех сайтов с помощью powershell.

После этого получаем хеш сертификата

Get-ChildItem -path cert:\LocalMachine\My

Как поменять сертификаты на iis для всех сайтов с помощью powershell.

$OLDCertificateThumbprint = "вставляем Thumbprint " # старый сертификат
$NEWCertificateThumbprint = "вставляем Thumbprint " # новый сертификат

#Show bindings where the old certificate is in use
Get-WebBinding | Where-Object { $_.certificateHash -eq $OLDCertificateThumbprint} | Format-Table

#Select bindings where the old certificate is in use and attach the new certificate
Get-WebBinding | Where-Object { $_.certificateHash -eq $OLDCertificateThumbprint} | ForEach-Object {
        Write-Host "Working on"  $_ 
        $_.RemoveSslCertificate()
        $_.AddSslCertificate($NEWCertificateThumbprint, 'My')
        }

#Show bindings where the new certificate is in use
Get-WebBinding | Where-Object 
Читать далее

Как удалить site и pools из windows iis с помощью powershell.Deleting sites and application pools from Microsoft IIS using PowerShell

Удалить po0ls

#Deleting Sites and app pools in IIS 7 with PowerShell
$appCmd = "C:\windows\system32\inetsrv\appcmd.exe"

#lists all the sites
#& $appcmd list site 
#deletes a specific site
#& $appcmd delete site "Name of site"
#lists all the sites
#& $appcmd list apppool 
#deletes a specific application pool
#& $appcmd delete apppool "Name of app pool"
#delete any app pools that use a certain username (in the identity column of the GUI)
#$account = "TheDomain\TheAccount"
$AppPools = & $appcmd list apppool 
foreach ($pool in $AppPools){
    $pool = $pool.split(" ")[1] #get the name only
    & $appcmd delete apppool $pool
}
#delete all 
Читать далее

Как остановить и запустить все пулы iis через Powershell

Остановить pools iis через Powershell

Import-Module WebAdministration

if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit }

$AppPools=Get-ChildItem IIS:\AppPools | Where {$_.State -eq "Started"}

ForEach($AppPool in $AppPools)
{
 Stop-WebAppPool -name $AppPool.name
# Write-Output ('Stopping Application Pool: {0}' -f $AppPool.name)
}

Запустить pools iis через Powershell

Import-Module WebAdministration

   if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit }

   $AppPools=Get-ChildItem IIS:\AppPools | Where {$_.State -eq "Stopped"}
   ForEach($AppPool in $AppPools)
   {
    Start-WebAppPool -name $AppPool.name
   # Write-Output ('Starting Application Pool: {0}' -f $AppPool.name)
   }

 

Как перенести пулы и сайты с iis с одного сервера на другой.

Задача объединить два сервера в один. На одном сервер IIS находятся одни сайты на другом другие.

Выполним команду на сервере с которого будем переносить пулы и сайты

%windir%\system32\inetsrv\appcmd list site /config /xml > c:\sites.xml
%windir%\system32\inetsrv\appcmd list apppool /config /xml > c:\apppools.xml

Копируем файлы на другой сервер. Дальше надо поправить id в xml sites.xml что бы id не совпадали. Я префикс увеличил на 20 через notepad

Как перенести пулы и сайты с iis с одного сервера на другой.

Id поменяются у всех в данном xml

После этого можно сделать импорт

%windir%\system32\inetsrv\appcmd add apppool /in < c:\apppools.xml
%windir%\system32\inetsrv\appcmd add site /in < c:\sites.xml

 

ПотоКак перенести пулы и сайты с iis с одного сервера на другой.

Потом скопировал каталог с настройками в туже папку как … Читать далее