How can I take the name of the current folder and put into a variable in powerShell?
Thanks.
How can I take the name of the current folder and put into a variable in powerShell?
Thanks.
you can get the current working directory with
pwd
(pwd is an alias for Get-Location)
if you then select this as an object you can get the path
pwd | Select-Object | %{$_.ProviderPath}
you can split this
pwd | Select-Object | %{$_.ProviderPath.Split("\")}
Then take the last - which is you folder name
pwd | Select-Object | %{$_.ProviderPath.Split("\")[-1]}
to assign to a variable
$folderName = pwd | Select-Object | %{$_.ProviderPath.Split("\")[-1]}