# Call scripts from a folder from a script

**URL:** <https://forums.powershell.org/t/call-scripts-from-a-folder-from-a-script/16858>\
**Category:** PowerShell Help\
**Created:** [June 18, 2021, 1:53pm UTC](https://forums.powershell.org/t/call-scripts-from-a-folder-from-a-script/16858 "2021-06-18T13:53:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mhaisekar.sameer15](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/mhaisekar.sameer15/32/1405_2.png) [@mhaisekar.sameer15](https://forums.powershell.org/u/mhaisekar.sameer15)\
**Post date:** [June 18, 2021, 1:53pm UTC](https://forums.powershell.org/t/call-scripts-from-a-folder-from-a-script/16858/1 "2021-06-18T13:53:22Z")

</div>

So I’ve got a bunch of Posh scripts in a folder, I want to call them all from a “caller” script at once. Something like the below:

```auto
$folder = "C:\Users\SameerMhaisekar\OneDrive - SquaredUp\Documents\PowerShell\MyScripts"
$scripts = $folder | Get-ChildItem | select name
foreach ($script in $scripts){
$output = $PSScriptRoot+"\$script"
&$output
}

```

The error I get is

& : The term ‘@{Name=master.ps1}’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.  
At line:5 char:2

- &$output
- 

```auto
 + CategoryInfo : ObjectNotFound: (\@{Name=master.ps1}:String) [], CommandNotFoundException
 + FullyQualifiedErrorId : CommandNotFoundException
```

---

<div class="post-metadata">

**Author:** ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)\
**Post date:** [June 18, 2021, 2:10pm UTC](https://forums.powershell.org/t/call-scripts-from-a-folder-from-a-script/16858/2 "2021-06-18T14:10:04Z")

</div>

Its because `$scripts` is not a string array but an object array, its property name is `name` (header when seen in console as a table). So you will have to Expand it like `...| Select-Object -ExpandProperty FullName` to make it as a string.

I suggest to use full name as it will have full path.

other option is to use `$script.name` inside the loop like `"$PSScriptRoot + $($script.Name)"`.  
Proper way of joining path is using `Join-Path` cmdlet like

```auto
$ScriptPath = Join-Path -Path $PSScriptRoot -ChildPath $Script.Name
& $ScriptPath

```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:24pm UTC](https://forums.powershell.org/t/call-scripts-from-a-folder-from-a-script/16858/3 "2024-05-16T20:24:13Z")

</div>


