Method 1:
1 $ Username = " Administrator " 2 $ Serverpass = " Pass " 3 $ Server =" 10.4.19.60 " 4 $ Password = Convertid-securestring $ Serverpass - Asplaintext-Force 5 $ Cred = New-Object System. Management. Automation. pscredential ( $ Username , $ Password ) 6 7 Invoke-command-computername$ Server -Scriptblock {iisreset}-credential $ Cred
Method 2:
Iisreset.exe remotename/restart
# IIS components must be installed on both the local and remote computers. If IIS is not installed, the iisreset.exe command cannot be used.
Method 3:
1 (get-wmiobject win32_service-computername servername-filter "name = 'isadmin '"). invokemethod ("stopservice", $ null) 2 start-sleep-seconds 53 (get-wmiobject win32_service-computername servername-filter "name = 'isadmin '"). invokemethod ("startservice", $ null)
In addition, the WWW Service must be restarted and not tested.
Method 4:
For IIS v6
$ SRV = "server name or IP address"
$ APP = "Name of APP pool"
$ X = Get-wmiobject-namespace "Root \ microsoftiisv2"-class "iisapplicationpool"-computername $ SRV-Authentication packetprivacy | where-object {$ _. name-EQ "w3svc/apppools/$ app "}
$ X. Stop ()
$ X. Start ()
For IIS V7
$ SRV = "server name or IP address"
$ APP = "Name of APP pool"
$ X = Get-wmiobject-namespace "Root \ webadministration"-class "applicationpool"-computername $ SRV-Authentication packetprivacy | where-object {$ _. Name-EQ $ app}
$ X. Stop ()
$ X. Start ()