powershell functions

Welcome Forums General PowerShell Q&A powershell functions

This topic contains 2 replies, has 3 voices, and was last updated by

 
Participant
3 years, 8 months ago.

  • Author
    Posts
  • #24155

    Participant
    Points: 0
    Rank: Member

    i have 5 functions copy-files, compare-files, alert-users, zip-files and remove-files.

    they look like this:
    function copy-file {
    param ($a,$b)
    copy-item $a $b
    }

    how do I create 1 script, that will go through the entire functionslist one after the other?

  • #24156

    Participant
    Points: 0
    Rank: Member

    You define functions in first place and then you call them 🙂
    Or I missed your point in question?

  • #24160

    Participant
    Points: 60
    Rank: Member

    Hey Sanjaya,

    You'd want to do something like this

    
    Param(
        [string]$a,
        [string]$b
    )
    
    function copy-file 
    {
        param ($a,$b)
        Copy-Item $a $b
    }
    
    #put your functions here e.g.
    
    function functionname
    {
        param ($a,$b)
        command $a $b
    }
    .
    .
    .
    #put your other commands here including the parameters, like :
    copy-file -a $a -b $b
    
    
    

The topic ‘powershell functions’ is closed to new replies.