Powershell script does not execute in Linux

I have installed powershell for Unix and am trying to run my script: Check-Folder.ps1

function Check_Folder([string]$path, [switch]$create){
$exists = Test-Path $path
if (!$exists -and $create) {
mkdir $path
$exists = Test-Path $path
}
return $exists
}

In the unix command prompt, I run:
> powershell -File ./Check-Folder.ps1 “/usr/bin”
It returns without any output.
Why?

You’ve enclosed your code in a function. In order to execute the function, the script must call it at the end, or you need to ‘import’ the function from the file using dot-sourcing:

. './Check-Folder.ps1'
Check_Folder -Path '/usr/bin'

I would generally recommend you use hyphens rather than underscores in function names, but it’s up to you really. :slight_smile:

You can do it this way. If you make a directory though, it will return the directory as well.

param([string]$path,[switch]$create)

$exists = Test-Path $path
if (!$exists -and $create) {
  mkdir $path
  $exists = Test-Path $path
}
return $exists