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)

PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Biography of Daniel Podor.pdf
Daniel Podor
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Biography of Daniel Podor.pdf
Daniel Podor
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 

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.