In PowerShell, how do I define a function in a file and call it from the PowerShell commandline?

前端 未结 7 1398
悲&欢浪女
悲&欢浪女 2020-12-12 08:29

I have a .ps1 file in which I want to define custom functions.

Imagine the file is called MyFunctions.ps1, and the content is as follows:

Write-Host          


        
7条回答
  •  盖世英雄少女心
    2020-12-12 09:04

    You certainly can define functions in script files (I then tend to load them through my Powershell profile on load).

    First you need to check to make sure the function is loaded by running:

    ls function:\ | where { $_.Name -eq "A1"  }
    

    And check that it appears in the list (should be a list of 1!), then let us know what output you get!

提交回复
热议问题