Hi folks, I’m trying to run the following commands and, by golly, I’m missing something because my variable is returning NULL. Thanks for any guidance you can provide!
$scriptpath = $MyInvocation.MyCommand.Path write-host ("Script Path is: " + $scriptpath) $dir = Split-Path $scriptpath write-host ("Dir is: " + $dir)
This is what I see in the console:
PS C:\Coding\PowerShell> $scriptpath = $MyInvocation.MyCommand.Path
PS C:\Coding\PowerShell> write-host ("Script Path is: " + $scriptpath)
Script Path is:
PS C:\Coding\PowerShell> $dir = Split-Path $scriptpath
Split-Path : Cannot bind argument to parameter ‘Path’ because it is null.
At line:1 char:19
- $dir = Split-Path $scriptpath
-
- CategoryInfo : InvalidData: ( [Split-Path], ParameterBindingValidationException
- FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.SplitPat
hCommand