SlideShare a Scribd company logo
Windows PowerShell Basics – Functions
i | P a g e
Table of Contents
Overview.......................................................................................................................................................1
Applies To..................................................................................................................................................1
Pre-Requisites ...........................................................................................................................................1
PowerShell Script – Function ........................................................................................................................1
Code Snippet.............................................................................................................................................1
Invoke Function.........................................................................................................................................2
PowerShell Output....................................................................................................................................2
Windows PowerShell Basics – Functions
1 | P a g e
Overview
PowerShell functions are helpful in saving time when you have repetitive task(s) to be executed.
Applies To
Tested on Windows 10, Windows 2008 R2 and Windows 2012.
Pre-Requisites
Launch PowerShell Command Console or PowerShell ISE.
To run this script, Execution Policy should be set to either of these “AllSigned” or “RemoteSigned” or
“Unrestricted”, you can get current execution policy by running the command; “Get-ExecutionPolicy”.
Each Policy type and its purpose is shown in the below table.
Policy Type Purpose
Restricted No scripts can be run. Windows PowerShell can be used only in interactive mode.
AllSigned Only scripts signed by a trusted publisher can be run.
RemoteSigned Downloaded scripts must be signed by a trusted publisher before they can be run.
Unrestricted No restrictions; all Windows PowerShell scripts can be run.
PowerShell Script – Function
This PowerShell script call function without any function arguments / parameters.
Code Snippet
#
# Simple Function
#
Function Call_Function_Write_Welcome_Message
{
Clear-Host
Write-Host "`nListing Function information that was created`n"
dir function: | Where-Object Name -Like "Call_function_Write_Welcome_Message"
Write-Host "`n__________________________________________"
Write-Host "`nPurpose of Function printing Hello Message"
Write-Host "__________________________________________"
Write-Host "`nHello – PowerShell Script"
[console]::beep(500,300)
}
Windows PowerShell Basics – Functions
2 | P a g e
Invoke Function
To invoke /call the function, simply call the function name from the PowerShell CLI or PowerShell ISE.
Call_Function_Write_Welcome_Message
PowerShell Output
When the function is called / executed; below output will be displayed.

More Related Content

What's hot (20)

PDF
How To Connect Amazon AWS EC2 with Key Pair – Linux
VCP Muthukrishna
 
PDF
How To View Current Execution Policy PowerShell
VCP Muthukrishna
 
PDF
Install and Configure RSyslog – CentOS 7 / RHEL 7
VCP Muthukrishna
 
PDF
Nginx bind() to 0.0.0.0:9080 failed
VCP Muthukrishna
 
PDF
Windows PowerShell Basics - How To List PSDrive Info
VCP Muthukrishna
 
PDF
How To Configure Amazon EC2 Security Groups
VCP Muthukrishna
 
DOCX
How to Configure Amazon AWS EC2 Elastic IP Address
VCP Muthukrishna
 
PDF
Bash Script - How To Monitor Application Error Logs and Send Notification
VCP Muthukrishna
 
PDF
How to Change Hostname in CentOS 7 or RHEL 7
VCP Muthukrishna
 
PDF
VMWare Tools Installation and Troubleshooting Guide
VCP Muthukrishna
 
PDF
How To Configure SNMP Logging on RHEL 7
VCP Muthukrishna
 
PDF
How to Fix Duplicate Packages in YUM on CentOS 7
VCP Muthukrishna
 
PDF
How To Install and Configure Open SSH Server on Ubuntu
VCP Muthukrishna
 
PDF
How To Check file exists and Delete PowerShell
VCP Muthukrishna
 
PDF
Windows PowerShell Basics – How To Create powershell for loop
VCP Muthukrishna
 
PDF
How to Troubleshoot SELinux Audit2Allow unable to open (null)
VCP Muthukrishna
 
PDF
How To Install and Configure Screen on CentOS 7
VCP Muthukrishna
 
PDF
How To Manage Services on RHEL 7 or CentOS 7
VCP Muthukrishna
 
PDF
Install VMWare Tools CentOS 7
VCP Muthukrishna
 
PDF
How to Upgrade Openfire on CentOS 7
VCP Muthukrishna
 
How To Connect Amazon AWS EC2 with Key Pair – Linux
VCP Muthukrishna
 
How To View Current Execution Policy PowerShell
VCP Muthukrishna
 
Install and Configure RSyslog – CentOS 7 / RHEL 7
VCP Muthukrishna
 
Nginx bind() to 0.0.0.0:9080 failed
VCP Muthukrishna
 
Windows PowerShell Basics - How To List PSDrive Info
VCP Muthukrishna
 
How To Configure Amazon EC2 Security Groups
VCP Muthukrishna
 
How to Configure Amazon AWS EC2 Elastic IP Address
VCP Muthukrishna
 
Bash Script - How To Monitor Application Error Logs and Send Notification
VCP Muthukrishna
 
How to Change Hostname in CentOS 7 or RHEL 7
VCP Muthukrishna
 
VMWare Tools Installation and Troubleshooting Guide
VCP Muthukrishna
 
How To Configure SNMP Logging on RHEL 7
VCP Muthukrishna
 
How to Fix Duplicate Packages in YUM on CentOS 7
VCP Muthukrishna
 
How To Install and Configure Open SSH Server on Ubuntu
VCP Muthukrishna
 
How To Check file exists and Delete PowerShell
VCP Muthukrishna
 
Windows PowerShell Basics – How To Create powershell for loop
VCP Muthukrishna
 
How to Troubleshoot SELinux Audit2Allow unable to open (null)
VCP Muthukrishna
 
How To Install and Configure Screen on CentOS 7
VCP Muthukrishna
 
How To Manage Services on RHEL 7 or CentOS 7
VCP Muthukrishna
 
Install VMWare Tools CentOS 7
VCP Muthukrishna
 
How to Upgrade Openfire on CentOS 7
VCP Muthukrishna
 

Similar to How To Create PowerShell Function (20)

PPTX
Power shell training
David Brabant
 
PPTX
Introduction to windows power shell in sharepoint 2010
Binh Nguyen
 
PDF
How To Create PowerShell Function Mandatory Parameter and Optional Parameter
VCP Muthukrishna
 
PDF
Powershell notes
Carlos Amorim
 
PDF
How To List Files on Remote Server - PowerShell
VCP Muthukrishna
 
PPTX
Powershell Demo Presentation
Avik Bhattacharyya
 
PPTX
Power shell basics day 2
Ashish Raj
 
PDF
Learn Powershell Scripting Tutorial Full Course 1dollarcart.com.pdf
ClapperboardCinemaPV
 
PPTX
Powershell Tech Ed2009
rsnarayanan
 
PDF
Practical PowerShell Programming for Professional People
Ben Ten (0xA)
 
PDF
How To Create Power Shell Function Mandatory Parameter Value
VCP Muthukrishna
 
PPTX
Getting Started With PowerShell Scripting
Ravikanth Chaganti
 
PDF
powershell.pdf
Saurabh846965
 
PDF
Windows Powershell Step By Step 3rd Edition Wilson Ed
forsenqenan
 
PDF
How To Construct IF and Else Conditional Statements
VCP Muthukrishna
 
PPTX
Powershell_Basics_Robin
Robin Aggarwal
 
PPTX
Introduction To Power Shell
Ivan Suhinin
 
PPTX
PowerShell-1
Saravanan G
 
PDF
Introduction to PowerShell
Boulos Dib
 
PDF
PowerShell_LangRef_v3 (1).pdf
outcast96
 
Power shell training
David Brabant
 
Introduction to windows power shell in sharepoint 2010
Binh Nguyen
 
How To Create PowerShell Function Mandatory Parameter and Optional Parameter
VCP Muthukrishna
 
Powershell notes
Carlos Amorim
 
How To List Files on Remote Server - PowerShell
VCP Muthukrishna
 
Powershell Demo Presentation
Avik Bhattacharyya
 
Power shell basics day 2
Ashish Raj
 
Learn Powershell Scripting Tutorial Full Course 1dollarcart.com.pdf
ClapperboardCinemaPV
 
Powershell Tech Ed2009
rsnarayanan
 
Practical PowerShell Programming for Professional People
Ben Ten (0xA)
 
How To Create Power Shell Function Mandatory Parameter Value
VCP Muthukrishna
 
Getting Started With PowerShell Scripting
Ravikanth Chaganti
 
powershell.pdf
Saurabh846965
 
Windows Powershell Step By Step 3rd Edition Wilson Ed
forsenqenan
 
How To Construct IF and Else Conditional Statements
VCP Muthukrishna
 
Powershell_Basics_Robin
Robin Aggarwal
 
Introduction To Power Shell
Ivan Suhinin
 
PowerShell-1
Saravanan G
 
Introduction to PowerShell
Boulos Dib
 
PowerShell_LangRef_v3 (1).pdf
outcast96
 
Ad

More from VCP Muthukrishna (13)

PDF
How To Install and Configure GNome on CentOS 7
VCP Muthukrishna
 
PDF
How To Connect to Active Directory User Validation
VCP Muthukrishna
 
PDF
How To Connect To Active Directory PowerShell
VCP Muthukrishna
 
PDF
How To List Files and Display In HTML Format
VCP Muthukrishna
 
PDF
How To Check and Delete a File via PowerShell
VCP Muthukrishna
 
PDF
Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...
VCP Muthukrishna
 
PDF
How To Setup SSH Keys on CentOS 7
VCP Muthukrishna
 
PDF
How To Configure Nginx Load Balancer on CentOS 7
VCP Muthukrishna
 
PDF
How To Install and Configure Salt Master on Ubuntu
VCP Muthukrishna
 
PDF
How To Protect SSH Access with Fail2Ban on RHEL 7
VCP Muthukrishna
 
PDF
How To Find Package Installation Date on RHEL 7
VCP Muthukrishna
 
PDF
How To Reset root Password on CentOS 7
VCP Muthukrishna
 
PDF
How To Install and Use ABRT CLI on RHEL 7
VCP Muthukrishna
 
How To Install and Configure GNome on CentOS 7
VCP Muthukrishna
 
How To Connect to Active Directory User Validation
VCP Muthukrishna
 
How To Connect To Active Directory PowerShell
VCP Muthukrishna
 
How To List Files and Display In HTML Format
VCP Muthukrishna
 
How To Check and Delete a File via PowerShell
VCP Muthukrishna
 
Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...
VCP Muthukrishna
 
How To Setup SSH Keys on CentOS 7
VCP Muthukrishna
 
How To Configure Nginx Load Balancer on CentOS 7
VCP Muthukrishna
 
How To Install and Configure Salt Master on Ubuntu
VCP Muthukrishna
 
How To Protect SSH Access with Fail2Ban on RHEL 7
VCP Muthukrishna
 
How To Find Package Installation Date on RHEL 7
VCP Muthukrishna
 
How To Reset root Password on CentOS 7
VCP Muthukrishna
 
How To Install and Use ABRT CLI on RHEL 7
VCP Muthukrishna
 
Ad

Recently uploaded (20)

PPTX
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
PDF
Kubernetes - Architecture & Components.pdf
geethak285
 
PDF
Bridging CAD, IBM TRIRIGA & GIS with FME: The Portland Public Schools Case
Safe Software
 
PDF
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
PDF
Proactive Server and System Monitoring with FME: Using HTTP and System Caller...
Safe Software
 
PPTX
2025 HackRedCon Cyber Career Paths.pptx Scott Stanton
Scott Stanton
 
PDF
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
PDF
Simplify Your FME Flow Setup: Fault-Tolerant Deployment Made Easy with Packer...
Safe Software
 
PDF
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
PPTX
Smart Factory Monitoring IIoT in Machine and Production Operations.pptx
Rejig Digital
 
PDF
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
PPSX
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
PDF
Why aren't you using FME Flow's CPU Time?
Safe Software
 
PDF
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
PDF
How to Visualize the ​Spatio-Temporal Data Using CesiumJS​
SANGHEE SHIN
 
PPTX
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
PDF
Next level data operations using Power Automate magic
Andries den Haan
 
PDF
DoS Attack vs DDoS Attack_ The Silent Wars of the Internet.pdf
CyberPro Magazine
 
PDF
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
Kubernetes - Architecture & Components.pdf
geethak285
 
Bridging CAD, IBM TRIRIGA & GIS with FME: The Portland Public Schools Case
Safe Software
 
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
Proactive Server and System Monitoring with FME: Using HTTP and System Caller...
Safe Software
 
2025 HackRedCon Cyber Career Paths.pptx Scott Stanton
Scott Stanton
 
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
Simplify Your FME Flow Setup: Fault-Tolerant Deployment Made Easy with Packer...
Safe Software
 
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
Smart Factory Monitoring IIoT in Machine and Production Operations.pptx
Rejig Digital
 
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
Why aren't you using FME Flow's CPU Time?
Safe Software
 
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
How to Visualize the ​Spatio-Temporal Data Using CesiumJS​
SANGHEE SHIN
 
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
Next level data operations using Power Automate magic
Andries den Haan
 
DoS Attack vs DDoS Attack_ The Silent Wars of the Internet.pdf
CyberPro Magazine
 
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 

How To Create PowerShell Function

  • 1. Windows PowerShell Basics – Functions i | P a g e Table of Contents Overview.......................................................................................................................................................1 Applies To..................................................................................................................................................1 Pre-Requisites ...........................................................................................................................................1 PowerShell Script – Function ........................................................................................................................1 Code Snippet.............................................................................................................................................1 Invoke Function.........................................................................................................................................2 PowerShell Output....................................................................................................................................2
  • 2. Windows PowerShell Basics – Functions 1 | P a g e Overview PowerShell functions are helpful in saving time when you have repetitive task(s) to be executed. Applies To Tested on Windows 10, Windows 2008 R2 and Windows 2012. Pre-Requisites Launch PowerShell Command Console or PowerShell ISE. To run this script, Execution Policy should be set to either of these “AllSigned” or “RemoteSigned” or “Unrestricted”, you can get current execution policy by running the command; “Get-ExecutionPolicy”. Each Policy type and its purpose is shown in the below table. Policy Type Purpose Restricted No scripts can be run. Windows PowerShell can be used only in interactive mode. AllSigned Only scripts signed by a trusted publisher can be run. RemoteSigned Downloaded scripts must be signed by a trusted publisher before they can be run. Unrestricted No restrictions; all Windows PowerShell scripts can be run. PowerShell Script – Function This PowerShell script call function without any function arguments / parameters. Code Snippet # # Simple Function # Function Call_Function_Write_Welcome_Message { Clear-Host Write-Host "`nListing Function information that was created`n" dir function: | Where-Object Name -Like "Call_function_Write_Welcome_Message" Write-Host "`n__________________________________________" Write-Host "`nPurpose of Function printing Hello Message" Write-Host "__________________________________________" Write-Host "`nHello – PowerShell Script" [console]::beep(500,300) }
  • 3. Windows PowerShell Basics – Functions 2 | P a g e Invoke Function To invoke /call the function, simply call the function name from the PowerShell CLI or PowerShell ISE. Call_Function_Write_Welcome_Message PowerShell Output When the function is called / executed; below output will be displayed.