EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login

WinRM PowerShell

By Priya PedamkarPriya Pedamkar

Secondary Sidebar
PowerShell Tutorial
  • cmdlet
    • PowerShell Wait
    • PowerShell Match
    • cmdlets in PowerShell
    • Start PowerShell from cmd
    • Add-Content in PowerShell
    • Get Help in PowerShell
    • PowerShell Copy-Item
    • PowerShell Remove-Item
    • PowerShell Move-Item
    • Get Command in PowerShell
    • PowerShell Run Command
    • Windows PowerShell ISE
    • Windows Powershell Commands
    • WinRM PowerShell
    • PowerShell Date
    • Powershell Write-Host
    • PowerShell Get-ChildItem
    • PowerShell Sort-Object
    • PowerShell Where Object
    • PowerShell Set-Content
    • PowerShell Set-Location
    • PowerShell Invoke-Command
    • PowerShell Invoke-Webrequest
    • PowerShell Get-Location
    • PowerShell Get-Date
    • PowerShell Get-Service
    • PowerShell Test-Path
    • Powershell Module Path
    • PowerShell Out-File
    • PowerShell if File Exists
    • Powershell Copy File
    • PowerShell Delete File
    • PowerShell New-Item
    • PowerShell Rename-Item
    • PowerShell ComputerName
    • PowerShell Get-Content
    • PowerShell Get-Item
    • PowerShell Get-ADUser
    • PowerShell Grep
    • PowerShell Concatenate String
    • PowerShell Get-Process
    • PowerShell Count
    • PowerShell pause
  • Basics
    • PowerShell Restart Service
    • PowerShell comment
    • PowerShell Map Network Drive
    • PowerShell Append to File
    • PowerShell print
    • What is PowerShell
    • Uses Of Powershell
    • PowerShell Empire
    • PowerShell Parameter
    • PowerShell Stop Service
    • PowerShell Versions
    • How To Install PowerShell
    • PowerShell uninstall module
    • How to Use PowerShell?
    • PowerShell Logging
    • PowerShell Tools
    • PowerShell Commands
    • PowerShell Version Command
    • PowerShell Administrator
    • PowerShell Modules
    • PowerShell Registry
    • PowerShell block Comment
    • PowerShell Verbs
    • PowerShell list
    • PowerShell add user to group
    • PowerShell Write to Console
    • Variable in PowerShell
    • PowerShell New Line
    • PowerShell prompt for input
    • PowerShell File Extension
    • Powershell Remotesigned
    • PowerShell Write to File
    • PowerShell Ping
    • PowerShell wget
    • PowerShell Global variable
    • PowerShell Get-ADGroup
    • Array in PowerShell
    • PowerShell Multidimensional Array
    • PowerShell Array of Strings
    • PowerShell? join array
    • Useful PowerShell Scripts
    • String in PowerShell
    • PowerShell Switch Statement
    • PowerShell Function Parameters
    • PowerShell vs PowerShell ISE
    • PowerShell test-connection
    • PowerShell Test-NetConnection
    • PowerShell GUI
    • PowerShell Variable in String
    • PowerShell Active Directory
  • Variables
    • PowerShell Variables
    • PowerShell Environment Variables
    • PowerShell set environment variable
    • Hashtable in PowerShell
    • Set Variable in PowerShell
  • Operators
    • PowerShell Operators
    • Comparison Operators in PowerShell
    • Logical Operators in PowerShell
    • PowerShell Boolean
    • PowerShell Like Operator
  • Control Statements
    • If Statement in PowerShell
    • If Else in PowerShell
    • Else If in PowerShell
    • Loops in PowerShell
    • For loop in PowerShell
    • PowerShell While Loop
    • PowerShell do while
    • PowerShell Loop through Array
    • PowerShell add to array
    • PowerShell ForEach Loop
    • PowerShell Break
    • PowerShell Continue
    • Switch Case in PowerShell
    • PowerShell If-Not
    • Try-catch in PowerShell
  • Functions
    • PowerShell Functions
    • PowerShell String Functions
    • powershell nslookup
    • PowerShell here string
    • PowerShell Wildcards
    • Regex in PowerShell
    • PowerShell not like
    • PowerShell Filter
    • PowerShell Sleep
    • PowerShell where
    • PowerShell join string
    • PowerShell Exit
    • PowerShell null
    • PowerShell Dictionary
    • PowerShell Location
    • PowerShell Start-Service
    • PowerShell is not digitally signed
    • PowerShell Uptime
    • PowerShell Create Directory
    • PowerShell Trim
    • PowerShell Join-Path
    • PowerShell Execution Policy
    • PowerShell SubString
    • PowerShell Format Table
    • PowerShell Import Module
    • PowerShell ForEach Object
    • PowerShell Alias
    • PowerShell Scheduled Task
    • PowerShell Convert String to Date
    • PowerShell Split String
    • PowerShell Multiline String
    • PowerShell MultiLine Comment
    • PowerShell Rename Folder
    • PowerShell Delete Folder
    • PowerShell String Replace
    • PowerShell join
    • PowerShell xcopy
    • PowerShell Base64
    • PowerShell Tail
    • PowerShell User List
    • PowerShell remove User from group
    • PowerShell JSON Format
    • PowerShell Send Mail
    • PowerShell Convert to String
    • PowerShell Start-Process
    • PowerShell change directory
    • PowerShell Open File
    • PowerShell Batch File
    • PowerShell ZIP
    • PowerShell unzip
    • PowerShell XML
    • PowerShell XML Parsing
    • Remote PowerShell
    • PowerShell Escape Character
    • PowerShell scriptblock
    • PowerShell Executable Location
    • PowerShell Import-CSV?
    • PowerShell Export CSV
  • Interview Questions
    • PowerShell Interview Questions

Related Courses

Shell Scripting Course

All in One Data Science Courses

Data Visualization Courses

Home Data Science Data Science Tutorials PowerShell Tutorial WinRM PowerShell

WinRM PowerShell

Introduction to WinRM PowerShell

WinRm stands for Windows Remote Management protocol. This protocol is used for establishing a connection between computers so that remote operations can be performed. To enable PowerShell remoting first the Enable-PSRemoting cmdlet must be run on both the source and the destination computers. This will start the WinRM service and creates a firewall rule so that requests can be sent and received on computers to perform remote operations. Once the service is started listeners must be created.

All in One Data Science Bundle(360+ Courses, 50+ projects)
Python TutorialMachine LearningAWSArtificial Intelligence
TableauR ProgrammingPowerBIDeep Learning
Price
View Courses
360+ Online Courses | 50+ projects | 1500+ Hours | Verifiable Certificates | Lifetime Access
4.7 (85,938 ratings)

Syntax:

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

The WinRM service is started by running the following cmdlet

Enable-PSRemoting

It is available in the namespace Microsoft.WsMan.Management and the corresponding assembly is System.Management.Automation. There are many cmdlets available related to WInRM management.

Various Classes of WinRm in PowerShell

This article will cover detail about the WinRM in Powershell along with the various classes that are implemented by PowerShell.

1. Connect-WSMan

This cmdlet establishes a connection to the WinRM service in the remote computer. If the client and server are present in different domain credentials must be provided explicitly. This establishes a persistent connection. This is generally used when a WSMan provider is used for establishing a connection to a remote computer.

Syntax:

Connect-WSMan [[-ComputerName] <string>] [-ApplicationName <string>] [-OptionSet <hashtable>] [-Port <int>] [-SessionOption <SessionOption>] [-UseSSL] [-Credential <pscredential>] [-Authentication {None | Default | Digest | Negotiate | Basic | Kerberos | ClientCertificate | Credssp}] [-CertificateThumbprint
<string>]  [<CommonParameters>] Connect-WSMan [-ConnectionURI <uri>] [-OptionSet <hashtable>] [-Port <int>] [-SessionOption <SessionOption>] [-Credential <pscredential>] [-Authentication
{None | Default | Digest | Negotiate | Basic | Kerberos | ClientCertificate | Credssp}] [-CertificateThumbprint <string>]  [<CommonParameters>]

Example:

Connect-WSMan -ComputerName "testserver01"

2. Disconnect-WSMan

This cmdlet is used to disconnect the WinRm service on the remote system. If the session is stored in a variable, only the state of the WS-Management session is closed.

Syntax:

Disconnect-WSMan [[-ComputerName] <String>  [<CommonParameters>]

Example:

Disconnect-WSMan -computer testserver01

3. Enable-WSManCredSSP

This cmdlet is used to enable the Credssp authentication mechanism on the desired system. This is used when the cmdlets run creates a remote session from another session. When this mechanism is used, the user credentials are used for authentication. Whenever a background job needs to be run, this cmdlet can be used.

Syntax:

Enable-WSManCredSSP  [-Role] <String> [[-DelegateComputer] <String[]>] [-Force] [<CommonParameters>]

Example:

Enable-WSManCredSSP -Role "Client" -DelegateComputer "testServer02.test.com"

4. Disable-WSManCredSSP

This cmdlet is used to disable the Credssp authentication mechanism on the desired system. When this mechanism is used, the user credentials are used for authentication. Whenever a background job needs to be run, this cmdlet can be used. To disable on the client, specify role as a client to disable on server specify role as a server.

Syntax:

Disable-WSManCredSSP  [-Role] <String>[<CommonParameters>]

Example:

Disable-WSManCredSSP -Role Client

The above cmdlet disables the credssp on the client machine

Disable-WSManCredSSP -Role Client

The above cmdlet disables the credssp on the server machine.

5. Get-WSManCredSSP

This cmdlet is used to get the credential security support provider that is present in the client computer or the server. The output denotes whether the authentication is enabled or disabled. This also displays information about allow fresh credentials.

Syntax:

Get-WSManCredSSP []

Example:

Get-WSManCredSSP

If the credssp is not enabled, a message saying the machine is not configured will be displayed.

6. Get-WSManInstance

This cmdlet is used to find out the management resource that is defined by a uniform resource identifier. The output is either in the form of a complex xml or an object. It uses a connection or transport layer of WS- Management connection to retrieve the information.

Syntax:

Get-WSManInstanc[-ApplicationName <String>][-BasePropertiesOnly]   [-ComputerName <String>]   [-ConnectionURI <Uri>]   [-Dialect <Uri>]   [-Enumerate]   [-Filter <String>]   [-OptionSet <Hashtable>]   [-Port <Int32>]   [-Associations]   [-ResourceURI] <Uri>   [-ReturnType <String>]   [-SessionOption <SessionOption>]   [-Shallow]   [-UseSSL]   [-Credential <PSCredential>]   [-Authentication <AuthenticationMechanism>   [-CertificateThumbprint <String> [<CommonParameters>]

Example:

Get-WSManInstance -ResourceURI wmicimv2/win32_service -SelectorSet @{name="winrm"} -ComputerName "testServer01"

7. Invoke-WSManAction

This provokes an action on an object that is denoted by uri. The parameters are supplied as key value pairs. It uses the transport layer to perform the action.

Syntax:

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

Example:

Invoke-WSManAction -Action startservice -ResourceURI wmicimv2/win32_service  -SelectorSet @{name="spooler"} -Authentication default

8. New-WSManInstance

This cmdlet creates a new management resource’s instance. It uses a resource uri along with input file to create a new resource.

Syntax:

New-WSManInstance   [-ConnectionURI <Uri>]   [-FilePath <String>]   [-OptionSet <Hashtable>]   [-ResourceURI] <Uri>   [-SelectorSet] <Hashtable>   [-SessionOption <SessionOption>]   [-ValueSet <Hashtable>]   [-Credential <PSCredential>]   [-Authentication <AuthenticationMechanism>]   [-CertificateThumbprint <String>][<CommonParameters>]

9. Ws-Management Enumerations

The following are the enumerations that are implemented in PowerShell. These are present in the software development kit.

10. New-WSManSessionOption

This creates a new hash table session option to be used as input for WS-Management cmdlets. These can be passed to as input to the following cmdlets.

  • Get-WSManInstance
  • Set-WSManInstance
  • Invoke-WSManAction
  • Connect-WSMan

Syntax:

New-WSManSessionOption   [-ProxyAccessType <ProxyAccessType>]   [-ProxyAuthentication <ProxyAuthentication>]   [-ProxyCredential <PSCredential>]   [-SkipCACheck]   [-SkipCNCheck]   [-SkipRevocationCheck]   [-SPNPort <Int32>]   [-OperationTimeout <Int32>]   [-NoEncryption]   [-UseUTF16][<CommonParameters>]

The proxy access type specifies the mechanism that is used to locate the server. Some of its values are ProxyIEConfig, ProxywinHttpConfig, ProxyAutoDetect and ProxyNoProxyServer. ProxyIeConfig is the default value.

The Proxy authentication parameter denotes the authentication mechanism that is used. The values to this parameter are Basic, Digest, and Negotiate. Negotiate is the default value.

Example:

$sess = New-WSManSessionOption -OperationTimeout 10000
Connect-WSMan -ComputerName "server01" -SessionOption $sess

Input:

Write-Host "Welcome to the WinRM demo"
Enable-PSRemoting
Write-Host "The winrm service is started" -ForegroundColor Green
Write-Host "Verify the listeners"
Get-WSManInstance -ResourceURI winrm/config/listener -SelectorSet @{Address="*";Transport="http"}
write-host "True"
Write-Host "Connecting to wim service in remote"
Connect-WSMan -ComputerName "testserver1"
Write-Host "Connected to the remote server"
Write-Host "Passing credentials to be used in remote server"
Enable-WSManCredSSP -Role "Client" -DelegateComputer "test.test.com"
Write-Host "disconnecting the session"
Disconnect-WSMan -computer testserver1
Write-Host "Session disconnected"

Output:

WinRM PowerShell -1.1

Conclusion

Thus, the article covered and explained in detail about the WinRM in PowerShell. It explained the various cmdlets that are available in the WinRM class and explained each of them with their appropriate syntax and examples. The article also showed on how to use various cmdlets to connect to the remote computer using the WinRM mechanism. To learn more in details it is advisable to write and practice sample programs.

Recommended Articles

This is a guide to WinRM PowerShell. Here we also discuss the introduction and various classes of WinRM in PowerShell along with different examples and its code implementation. You may also have a look at the following articles to learn more –

  1. PowerShell Get-Service
  2. PowerShell Invoke-Command
  3. Windows PowerShell ISE
  4. PowerShell Functions
Popular Course in this category
PowerShell Training (2 Courses, 1 Project)
  2 Online Courses |  1 Hands-on Project |   4+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

Shell Scripting Training (4 Courses, 1 Project)4.9
All in One Data Science Bundle (360+ Courses, 50+ projects)4.8
Data Visualization Training (15 Courses, 5+ Projects)4.7
1 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

SPSS, Data visualization with Python, Matplotlib Library, Seaborn Package

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

Special Offer - PowerShell Training (2 Courses) Learn More