I'm using IIS 6.0 and looking for a way to stop/start the app pool. I know there is a stop-appPool for powershell in 7.0 but using 6.0. :-( So does anyone have a powershell script or another command line exe that will stop/start the app pool?
Thanks.
Ok here it is, I just add a switch to stop the app pool else it starts since no harm in starting an app pool that is already started:
param([string]$appPoolName, [switch]$stop)
$appPool = get-wmiobject -namespace "root\MicrosoftIISv2" -class "IIsApplicationPool" | where-object {$_.Name -eq "W3SVC/AppPools/$appPoolName"}
if($appPool)
{
if($stop)
{
$appPool.Stop()
}
else
{
$appPool.Start()
}
}
If anybody is looking for a purely command-line tool that does not require Powershell, I have created such a thing based on the information contained in these other answers. Since the original question is specifically looking for possible command-line alternatives, I thought I would share it here.
Usage is quite simple:
IIS6AppPool Start DefaultAppPool
IIS6AppPool Stop AppPool #1
IIS6AppPool Recycle Some other app pool
Source and binaries are available on bitbucket. May this save somebody else a few minutes of head scratching.
You might be interested in this Powershell library I started maintaining:
psDeploy : http://rprieto.github.com/psDeploy/
Among other things it has lots of cmdlets for IIS6 automation, for example Start-IIS6AppPool, New-IIS6Website...
I hope it helps!
If on Windows Server 2003 it is simpler to use the supplied script iisapp.vbs
CScript.exe C:\WINDOWS\system32\iisapp.vbs /?
CScript.exe C:\WINDOWS\system32\iisapp.vbs /a MyApp /r
Or depending on your setup (default to Cscript not WScript), simply
iisapp /a MyApp /r
And of course it is different in IIS7
If you wish to do this remotely, and / or on a machine without powershell you can modify the script posted here.
It uses WMI to access and recycle the app pool, from VBScript. It's a trivial change to make it stop / start pools instead of recycling them, you just need to call .Stop or .Start on the app pool in question.
The meat of the script is paraphrased below:
strServer = "LocalHost" 'Server name goes here
strAppPoolName = "MyAppPool" 'App pool name goes here
'Connect to the specified server using WMI
set Locator = CreateObject("WbemScripting.SWbemLocator")
Locator.Security_.AuthenticationLevel = 6
set Service = locator.connectserver(strServer,"root/MicrosoftIISv2")
'Get a collection of WMI apppools
set APCollection = Service.InstancesOf("IISApplicationPool")
For each APInstance in APCollection
If UCase(ApInstance.Name) = UCase("W3SVC/AppPools/" & strAppPoolName) Then
WScript.Echo "Recycling " & strServer & "/" & APInstance.Name
' You can do any of these things depending you what you want to do.
APInstance.Recycle
APInstance.Stop
APInstance.Start
End If
Next
If you have some kind of command line / batch toolchain which you want to integrate this into, you can execute a VBScript file in command line mode by calling:
CScript.exe \NoLogo MyScriptFile.vbs
The \NoLogo switch removes the VBScript interpreter startup messages and running it with CScript.exe means that calls to WScript.Echo go to the command line rather than a popup window.
You could create a function to stop or start the application pool remotely as below:
function StopOrStartAppPool($RemoteServerName, $AppPoolName, $commandWebPool)
{
if ($commandWebPool -eq "Stop")
{
$wmiprocess = [wmiclass]"\\$RemoteServerName\root\cimv2:win32_process"
$wmiprocess.create("cscript.exe C:\Inetpub\AdminScripts\adsutil.vbs STOP_SERVER W3SVC/AppPools/$AppPoolName -s:$RemoteServerName")
}
else
{
$wmiprocess = [wmiclass] "\\$RemoteServerName\root\cimv2:win32_process"
$wmiprocess.create("cscript.exe C:\Inetpub\AdminScripts\adsutil.vbs START_SERVER W3SVC/AppPools/$AppPoolName -s:$RemoteServerName")
}
}
Related
I would like to create a PowerShell script that can Start and Stop several IIS Applicationpools at once.
I already found a similar article about this: How to start and stop application pool in IIS using powershell script
But I would like to create a PowerShell script where I can define more than one IIS Application to stop them all at once through that script.
Thank you in advance for the help
The link you provided already has a solution very close to what you need; look for "Stop all application pools script".
If you want to start/stop only some AppPools, put them in an array: replace $AppPools=Get-ChildItem IIS:\AppPools | Where {$_.State -eq "Started"} with $AppPools=#('server1', 'server2', 'server3'):
$AppPools=#('server1', 'server2', 'server3')
ForEach($AppPool in $AppPools) {
Stop-WebAppPool -name $AppPool.name
}
When I am running commands or installing software remotely using PowerShell - Invoke-Command etc I would like sometimes to be able to show a message on the remote screen so the user knows something is happening, or when work done etc.
I would like to if possible make this message look as professional as possible, e.g. better than just a standard winform message box if it can be done? perhaps more the style of the Windows 10 ones with coloured background and use of image if possible.
Spent a while googling but most seem to relate to using obsolete methods such as net-send or using msg.exe.
Thanks
https://michlstechblog.info/blog/powershell-show-a-messagebox/
So the issue really isnt creating the messagebox itself, its having it show on the users session.
So when you run a command against a system, youre using your creds to run the command therefore it wont show in the users session. You can get around this by running it in the users context using a task scheduler. I have a script that does all this for you but, id hate to recreate the wheel and will have to wait till monday (when im at work) to post it here.
It accepts user input in your sessions that outputs it to a vbs, which then copies it over the message to the users machine, and a task schedule is set to run immediately for the user thats logged in.
edit: The script is this without the task scheduler. I just invoke gwmi win32_computersystem | Select -ExpandProperty username to get the current user logged in and add it to the task.
#Prompt for messge
$strMSG = Read-Host -Prompt "Enter message"
#deleting vbs if it exists
del C:\brief\test.vbs
#creating vbs from scratch so it doesnt override
New-Item C:\brief\test.vbs
#Appending each the values to a seperate line
Add-Content C:\brief\test.vbs 'Set objShell = Wscript.CreateObject("WScript.Shell")'
Add-Content C:\brief\test.vbs "strText = `"$strMSG`""
Add-Content C:\brief\test.vbs 'intButton = objShell.Popup(strText,0,"Computer Support",48)'
#calling on the script
& cscript C:\brief\test.vbs
Found a great solution here which appears on quick testing to work well for displaying a toast notification on a remote machine
https://smsagent.blog/2019/06/11/just-for-fun-send-a-remote-toast-notification/
Currently we are using the command repadmin /syncall /e [our dn] and repadmin /syncall /eP [our dn] to force replication betwen domain controllers. I am wanting to use powershell to sync the domain controllers but everything I see online indicates that I would have to simply call repadmin from within powershell, which to me seems hokey and like duct taping something instead of doing it right. Is there any PURE powershell equivelant of repadmin /syncall?
I wrote this pure powershell function/script back last year to do exactly this and it looks like maybe that's where the other posted PS snippet answer here came from (I'll take as compliment). The other post saying it is not possible is absolutely incorrect this ADSI call and my script does in fact force a full sync just like a Repadmin /syncall simply test it and you will see - I use it quite a bit. It also does debug output and proper error checking. Here's the link to the Pure Powershell script on the MSDN site:
http://bit.ly/SyncADDomain
and the github repo where I even have the pure powershell script packaged into a MSI installer for simple deployment as well:
https://github.com/CollinChaffin/SyncADDomain
If you find it helpful please mark as answer. Thanks!
AFIAK there's not a full replacement for repadmin. Sync-ADObject will let you replicate a single object, but won't let you do a full sync. Also, that cmdlet is Windows 8.1/Windows Server 2012 R2 only. I would expect more comprehensive AD replication support in Windows Server vNext.
Give this script a try:
[CmdletBinding()]
Param([switch]$AllPartitions)
$myDomain = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain();
ForEach ($dc in $myDomain.DomainControllers) {
$dcName = $dc.Name;
$partitions = #();
if ($AllPartitions) {
$partitions += $dc.Partitions;
} else {
$partitions += ([ADSI]"").distinguishedName;
}
ForEach ($part in $partitions) {
Write-Host "$dcName - Syncing replicas from all servers for partition '$part'"
$dc.SyncReplicaFromAllServers($part, 'CrossSite')
}
}
I am debugging PowerShell DSC resources that come with v4.0.
More specifically, I am testing MSFT_ProcessResource by adding a diagnostic log.
After I make change to the resource, and run my configuration that exercise the resource, I don't see the logging I just added. Eventually after several minutes, PowerShell seems to refresh whatever cache of resource it has.
I've tried
Get-DscResource, and
Import-Module MSFT_ProcessResource
None of which worked.
Is there a way to force re-loading the resource?
DSC engine caches resources to increase performance.
There are two ways to reload the resource:
1) Restart process hosting DSC engine (kill WMI Provider Host and re-run the configuration)
2) Use debug mode which will cause DSC to reload resources automatically (useful when developing resources, but not recommended for regular work):
LocalConfigurationManager
{
DebugMode = $true
}
You can read more about debug mode here:
http://blogs.msdn.com/b/powershell/archive/2014/04/22/debug-mode-in-desired-state-configuration.aspx
DSC has a caching model which frankly seems buggy and poorlyl designed as of Sep 2016
The blog entries indicating the mechanisms to get around the caching don't always work
In your configuration include the following configuration line
Also perform a full restart of the winmgt service. Simply killing the dsctimer process doesn't appear to always work.
{
LocalConfigurationManager
{
DebugMode = "All"
}
}
A PowerShell script to clear the cache is:
$dscProcessID = Get-WmiObject msft_providers |
Where-Object {$_.provider -like 'dsctimer'} |
Select-Object -ExpandProperty HostProcessIdentifier
if ($dscProcessID -eq $null) {
Write-Host "DSC timer is not running."
return
}
Write-Host "Process ID: $dscProcessID"
Get-Process -Id $dscProcessID | Stop-Process -Force
Restart-Service -Name winmgmt -Force -Verbose
This has now changed with WMF 5, instead of $true debug mode has the following options.
None - Signifies that DebugMode is False and not applicable.
ForceModuleImport - Enforce the resource module to be reloaded instead of using the cache. This is similar to "true" value in
previous versions.
ResourceScriptBrealAll - Helps in debugging DSC resources when Local configuration manager tries to execute their functions. More on
it in subsequent blog posts!
All - Signifies that debugging as well as reloading of modules are both enabled.
Using this in an example DSC config would look like this:
Configuration myChocoConfig2
{
Import-DscResource -Module cChoco
Node "localhost"
{
LocalConfigurationManager
{
DebugMode = 'All'
}
cChocoInstaller installChoco
{
InstallDir = "c:\choco"
}
cChocoPackageInstaller installChrome
{
Name = "sysinternals"
DependsOn = "[cChocoInstaller]installChoco"
}
}
}
https://techstronghold.com/blogs/scripting/how-to-setup-debug-mode-in-windows-powershell-desired-state-configuration-dsc
I have a set of scripts that load on start of PowerShell and I often needed the same. I would edit one of my scripts and need it to be updated in the current session.
Because I have these scripts loading via a series of scripts in the $profile I am able to use one command to refresh for any of the scripts that I load on init.
C:> powershell
This command will refresh your session and keep you in the same folder you are currently in. If you are not loading your module on startup, you will need to use the answer from Karol.
Ahh...so frustrated...hopefully someone here can help!
There is a software product called ScreenConnect that allows you to install it on your own server and through this install set up attended and unattended remote access sessions. I use this with a lot of my clients, but it's a lot easier to set up unattended installs on those client's machines that I'm going to be needing access to more than once. However, a few clients want to have control over when I can remote in and when I can't, and since the software product doesn't yet have this functionality built into it, I figured I'd just create two vbscript files on their desktops - one that turns off the service if it's on (and vice versa), and the other that changes the startup type of the service to automatic (if it's set to manual) and vice versa. I was able to pretty easily get the start/stop service vbscript file going:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colRunningServices = objWMIService.ExecQuery _
("select State from Win32_Service where Name LIKE '%ScreenConnect%'")
For Each objService in colRunningServices
Wscript.Echo "State: " & objService.State
If objService.State <> "Running" Then
errReturn = objService.StartService()
Wscript.Echo "FalconRemote Started"
Else
errReturn = objService.StopService()
Wscript.Echo "FalconRemote Stopped"
End If
Next
However, for the life of me, I can't get the automatic/manual start-up type vbscript working on Windows XP. If I simplify it down to the bones and just want to have the vbscript tell me the current status of the startup (i.e. manual, automatic, disabled), which is obviously necessary for the vbscript to know so it can determine what to do based on that information, then this is what I put together:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colRunningServices = objWMIService.ExecQuery _
("select StartMode from Win32_Service where Name LIKE '%ScreenConnect%'")
For Each objService in colRunningServices
Wscript.Echo "StartMode: " & objService.PathName
Next
And yet, that returns "Unknown" instead of an acceptable value like "Manual", "Disabled", or "Autoamtic" - I have no idea why it's returning "Unknown"!!!
I've tried changing the fifth line to this:
("select * from Win32_Service where Name LIKE '%ScreenConnect%'")
or this
("select StartMode from Win32_Service where DisplayName LIKE '%ScreenConnect%'")
but it seems to have no effect.
If I change out ScreenConnect in the above script for another service, like helpsvc (using Name) or Help and Support (using DisplayName), it works! And it works fine on a Windows 7 machine. Why does it not work on a Windows XP machine? Any ideas???? I tried installing Mozilla Firefox 20 (with the Mozilla Maintenance Service) and it works fine reading the startmode of that service (which isn't built into WinXP), so why won't it read the startmode of this service?
Any help is greatly appreciated!
Thanks.
Marc
I've just recently encountered this issue.
I'm not exactly sure how the windows service was put in this state, but it seems that the windows service is in an "Unknown" state.
For example, it could be that the executable no longer exists on the file system, but the windows service (registry) entry still (partially) exists.
In any case, simply deleting the windows service entry resolved the issue.
The windows service can be deleted using the following command line for example:
sc delete "ScreenConnect service name"