I have this bellow command to check is folder contains name "AAA_*" in path "C:\Test" exist and if so - make from it name variable:
$DirPath = "C:\Test"
$DirName = "AAA"
If (Test-Path -Path ($DirPath + "\" + $DirName + "_*")) {
C:;cd\;cd ($DirPath + "\" + $DirName + "_*")
$NameFromDir = pwd | Select-Object | %{$_.ProviderPath.Split("\")[-1]}
cd $PSScriptRoot}
I have to double write it path, and also i need to go to inside of it to set is as variable.
Is this can be done in another shorten or easier way?