I would like to include script files with such pseudo syntax:
Include '.\scripA.ps1'
But the only thing I have found is some thing like this:
$thisScript = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent . ($thisScript + '.\scriptA.ps1')
that is ugly.
Is there some nice way to include scripts with relative paths?
-LiteralPath. Specifies the path to be resolved. The value of the LiteralPath parameter is used exactly as typed. No characters are interpreted as wildcard characters. If the path includes escape characters, enclose it in single quotation marks ( ' ).
Use the Get-ChildItem cmdlet in PowerShell to get the full path of the file in the current directory. Get-ChildItem returns one or more items from the specified location and using the file FullName property, it gets the full path of the file.
The Split-Path cmdlet returns only the specified part of a path, such as the parent folder, a subfolder, or a file name. It can also get items that are referenced by the split path and tell whether the path is relative or absolute. You can use this cmdlet to get or submit only a selected part of a path.
You can utilize the $PSScriptRoot parameter like this:
. "$PSScriptRoot\script.ps1"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With