Version for a directory
get-item is your friendly helping hand here.
(get-item $scriptPath ).parent.parent
If you Want the string only
(get-item $scriptPath ).parent.parent.FullName
Version for a file
$scriptPath points to a file then you have to call
Directory property on it first, so the call would look like this
This will only work if
$scriptPath exists. Otherwise you have to use
- How to redirect the output of a PowerShell to a file during its execution
- How to count objects in PowerShell?
- How to get disk capacity and free space of remote computer
- PowerShell Script to Find and Replace for all Files with a Specific Extension
- Getting the path of %AppData% in PowerShell
- How do I create a custom type in PowerShell for my scripts to use?
- How to Remove ReadOnly Attribute on File Using PowerShell?
- How to use a config file (ini, conf,…) with a PowerShell Script?
- PowerShell prompt to continue execution of code
- How to get started with PowerShell? [closed]
- PowerShell script to check an application that’s locking a file?
- Powershell window disappears before I can read the error message
- How do I assign a null value to a variable in PowerShell?
- Reload the path in PowerShell
- Is there a way to make a PowerShell script work by double clicking a .ps1 file?
- PowerShell: How do I convert an array object to a string in PowerShell?
- Visual studio code cmd error: Cannot be loaded because running scripts is disabled on this system
- Read file line by line in PowerShell
- Capturing standard out and error with Start-Process
- The term ‘Get-ADUser’ is not recognized as the name of a cmdlet
- Obtaining ExitCode using Start-Process and WaitForExit instead of -Wait
- Powershell web request without throwing exception on 4xx/5xx
- Powershell test if folder empty
- What’s in your PowerShell `profile.ps1` file? [closed]
- Need to add a “Wait” command to a Powershell script
- PowerShell script, showing commands run
- Run remote powershell as administrator
- Writing a powershell script to copy files with certain extension from one folder to another
- Powershell module ‘servermanager’ not found on Windows 10
- Configure Hyper-V VM powershell
- Scheduled restart of a service with powerhshell as non-admin service account
- How to properly -filter multiple strings in a PowerShell copy script
- Running PowerShell as another user, and launching a script
- How do I add a newline to command output in PowerShell?
- How to pass a switch parameter to another PowerShell script?
- VSCode is suddenly defaulting to powershell for integrated terminal and tasks
- Get relative path of files in sub-folders from the current directory
- How can I get the file system location of a PowerShell script?
- How do I encode Unicode character codes in a PowerShell string literal?
- Connecting to a network folder with username/password in Powershell
- PowerShell is missing the terminator: “
- Setting Inheritance and Propagation flags with set-acl and powershell
- Extract only the first 10 lines of a csv file in powershell
- How do I replace spaces with %20 in PowerShell?
- Create an array, hashtable and dictionary?
- Can I use a single quote in a PowerShell ‘string’?
- How to activate conda environment from powershell?
- Visual Studio Code is suddenly defaulting to PowerShell for integrated terminal and tasks
- Equivalent of “cd %programfiles%” in PowerShell?
- How Can I “Update-Package” to a Previous Version in the Package Manager Console?