nwly
nwly

Reputation: 1511

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:

Function dothis($in) 
{
  Write-Host "Check $in"
}

Now, I call this in the regular powershell window (not ISE):

.\dothis.ps1 test

However, nothing is being printed to the screen. What noob mistake am I making?

Upvotes: 0

Views: 63

Answers (1)

user2555451
user2555451

Reputation:

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:

# This is how languages such as C, Java, Python, etc. call functions
dothis()
dothis('hello')

For more information on PowerShell functions, see here.

Upvotes: 3

Related Questions