[英]Printing to Powershell screen from within script function
Not sure what's going on. 不知道发生了什么。 I have a PS script file called
dothis.ps1
with the following code: 我有一个名为
dothis.ps1
的PS脚本文件, dothis.ps1
包含以下代码:
Function dothis($in)
{
Write-Host "Check $in"
}
Now, I call this in the regular powershell window (not ISE): 现在,我在常规的powershell窗口(不是ISE)中称其为:
.\dothis.ps1 test
However, nothing is being printed to the screen. 但是,没有任何内容被打印到屏幕上。 What noob mistake am I making?
我在犯什么新手错误?
It looks like you are forgetting to call the function: 您似乎忘记了调用该函数:
Function dothis($in)
{
Write-Host "Check $in"
}
dothis # Call function dothis
dothis 'hello' # Call function dothis with an argument
Note too that PoweShell is not like a lot of programming languages which call functions like this: 还要注意,PoweShell不像许多编程语言那样调用如下函数:
# This is how languages such as C, Java, Python, etc. call functions
dothis()
dothis('hello')
For more information on PowerShell functions, see here . 有关PowerShell函数的更多信息,请参见此处 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.