Get the name or location of current script and parent path
#full name
$Myinvocation.invocationname
#path
$myinvocation.InvocationName | split-path -parent
#filename
$myinvocation.mycommand.Name
#MyInvocation.InvocationName doesn't work for PowerGUI, use this instead to get path of current running script
Split-Path $script:MyInvocation.MyCommand.Path
#Get current script File Name
$thisFileName = $script:MyInvocation.MyCommand.Name
#Get parent folder of the path
$location="c:\temp\CodeBackup\"
$location
$path=split-path -parent $location
$path
#or
(get-item $location).parent.FullName
(get-item $location).parent.parent.FullName
Output:
c:\temp\CodeBackup\
c:\temp
C:\temp
C:\