Skip to main content
InSource KnowledgeCenter

TN WW126 An introduction to Windows Powershell

insource logo large.jpg

 

Description

A basic primer to Windows Powershell as a tool to maintain and troubleshoot Wonderware products.

 

  • Author: Peter Farrell
  • Published: 09/29/2015
  • Applies to: Windows Powershell all versions

 

 

Details

Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to COM and WMI, enabling administrators to perform administrative tasks on both local and remote Windows systems.  It is useful for writing new scripts and replacing old VBscripts, and it is a powerful tool that can be helpful when installing, maintaining, and troubleshooting issues involving Wonderware products.

 

WARNING -  PowerShell can easily cause significant configuration changes, positive or negative — so it is recommended that you establish a test environment for your learning experiences. Also consider using the "-confirm" parameter to test configurations before execution for certain commands.

 

In PowerShell, administrative tasks are generally performed by cmdlets (pronounced command-lets), which are specialized .NET classes implementing a particular operation. Sets of cmdlets may be combined into scripts, executables (which are standalone applications), or by instantiating regular .NET classes (or WMI/COM Objects).[2][3] These work by accessing data in different data stores, like the file system or registry, which are made available to the PowerShell runtime via Windows PowerShell providers.

 

Windows PowerShell can execute four kinds of named commands:

 

cmdlets, which are .NET programs designed to interact with PowerShell

PowerShell scripts (files suffixed by .ps1)

PowerShell functions

standalone executable programs

 

Follow is a small sample of cmdlets available in Windows Powershell

 

PowerShell (Cmdlet) Description
get-process Returns all currently running processes
   
Stop-Process -Name notepad
Stop-Process -ID 2668
Stops a running process
systeminfo Presents system information including hot fixes that have been applied
Get-ChildItem List all files / directories in the (current) directory
Get-Content Get the content of a file
Get-Command List available commands
Get-Help Help on commands
Clear-Host Clear the screen
Copy-Item Copy one or several files / a whole directory tree
Move-Item Move a file / a directory to a new location
Remove-Item Delete a file / a directory
Rename-Item Rename a file / a directory
Get-Location Display the current directory/present working directory.
Pop-Location Change the current directory to the directory most recently pushed onto the stack
Push-Location Push the current directory onto the stack
Set-Location Change the current directory
Tee-Object Pipe input to a file or variable, then pass the input along the pipeline
Write-Output Print strings, variables etc. to standard output
Get-Process List all currently running processes
Stop-Process Stop a running process
Select-String Print lines matching a pattern
Set-Variable Set the value of a variable / create a variable