PowerShell Logo Small

Invoke-WSManAction



This is the built-in help made by Microsoft for the command 'Invoke-WSManAction', in PowerShell version 5 - as retrieved from Windows version 'Microsoft Windows Server 2012 R2 Standard' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Invokes an action on the object that is specified by the Resource URI and by the selectors.

SYNTAX


Invoke-WSManAction [-ResourceURI] <Uri> [-Action] <String> [[-SelectorSet] <Hashtable>] [-Authentication <AuthenticationMechanism>] [-CertificateThumbprint <String>]
[-ConnectionURI <Uri>] [-Credential <PSCredential>] [-FilePath <String>] [-OptionSet <Hashtable>] [-SessionOption <SessionOption>] [-ValueSet <Hashtable>]
[<CommonParameters>]
Invoke-WSManAction [-ResourceURI] <Uri> [-Action] <String> [[-SelectorSet] <Hashtable>] [-ApplicationName <String>] [-Authentication <AuthenticationMechanism>]
[-CertificateThumbprint <String>] [-ComputerName <String>] [-Credential <PSCredential>] [-FilePath <String>] [-OptionSet <Hashtable>] [-Port <Int32>] [-SessionOption
<SessionOption>] [-UseSSL] [-ValueSet <Hashtable>] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


The Invoke-WSManAction runs an action on the object that is specified by RESOURCE_URI, where parameters are specified by key value pairs.


This cmdlet uses the WSMan connection/transport layer to run the action.



<

RELATED LINKS

Online Version: http://go.microsoft.com/fwlink/p/?linkid=294040
Invoke-WmiMethod
Connect-WSMan
Disable-WSManCredSSP
Disconnect-WSMan
Enable-WSManCredSSP
Get-WSManCredSSP
Get-WSManInstance
New-WSManInstance
New-WSManSessionOption
Remove-WSManInstance
Set-WSManInstance
Set-WSManQuickConfig
Test-WSMan

REMARKS

<

Examples


-------------------------- EXAMPLE 1 --------------------------

PS C:\>invoke-wsmanaction -action startservice -resourceuri wmicimv2/win32_service -selectorset @{name="spooler"} -authentication default

xsi : http://www.w3.org/2001/XMLSchema-instance
p : http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/Win32_Service
cim : http://schemas.dmtf.org/wbem/wscim/1/common
lang : en-US
ReturnValue : 0



This command calls the StartService method of the Win32_Service WMI class instance that corresponds to the Spooler service.

The return value indicates whether the action was successful. In this case, a return value of 0 indicates success. A return value of 5 indicates that the service is already
started.










-------------------------- EXAMPLE 2 --------------------------

PS C:\>invoke-wsmanaction -action stopservice -resourceuri wmicimv2/Win32_Service -SelectorSet @{Name="spooler"} -FilePath:input.xml -authentication default

xsi : http://www.w3.org/2001/XMLSchema-instance
p : http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/Win32_Service
cim : http://schemas.dmtf.org/wbem/wscim/1/common
lang : en-US
ReturnValue : 0



This command calls the StopService method on the Spooler service by using input from a file. The file, Input.xml, contains the following content:

<p:StopService_INPUT xmlns:p="http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/Win32_Service"/>

The return value indicates whether the action was successful. In this case, a return value of 0 indicates success. A return value of 5 indicates that the service is already
started.










-------------------------- EXAMPLE 3 --------------------------

PS C:\>invoke-wsmanaction -action create -resourceuri wmicimv2/win32_process -valueset @{commandline="notepad.exe";currentdirectory="C:\"}
xsi : http://www.w3.org/2001/XMLSchema-instance
p : http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/Win32_Process
cim : http://schemas.dmtf.org/wbem/wscim/1/common
lang : en-US
ProcessId : 6356
ReturnValue : 0



This command calls the Create method of the Win32_Process class. It passes the method two parameter values, Notepad.exe and "C:\". As a result, a new process is created to
run Notepad, and the current directory of the new process is set to "C:\".










-------------------------- EXAMPLE 4 --------------------------

PS C:\>invoke-wsmanaction -action startservice -resourceuri wmicimv2/win32_service -selectorset @{name="spooler"} -computername server01 -authentication default

xsi : http://www.w3.org/2001/XMLSchema-instance
p : http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/Win32_Service
cim : http://schemas.dmtf.org/wbem/wscim/1/common
lang : en-US
ReturnValue : 0



This command calls the StartService method of the Win32_Service WMI class instance that corresponds to the Spooler service. Because the ComputerName parameter is specified,
the command runs against the remote server01 computer.

The return value indicates whether the action was successful. In this case, a return value of 0 indicates success. A return value of 5 indicates that the service is already
started.