"Mark Line" <Mark Line@xxxxxx> wrote in message
news:07CECB51-D69C-4C53-8DA1-60EDDBAE3E07@xxxxxx
> Hi,
> I was wondering if anyone could help me,
> I’m trying to get a folder name into a variable so I will be able to copy
> the folder to another location.
>
> I want the newest folder in a certain directory, the following commands
> returns the correct information:
>
> $newestDir = ls | ?{$_.psiscontainer} | sort creationtime | select -last 1
> |
> select name
>
> However $newestDir now contains “@{Name=FolderName}”
>
> I only want the name of the folder so I can append it to a path for
> copying
> Any help would be fantastic?
> Thanks
> Mark
> Keep in mind that Select <propertyName> is like a SQL select I.e. it
projects the selected columns (properties in PowerShell) onto a new table
(PSCustomObject in PowerShell). That custom object has properties named the
same as the properties "selected" into that projection (like the column
names in SQL). If you really only want the path (unadorned) then try this:
$newestDir = ls | ?{$_.psiscontainer} | sort creationtime -desc |
select -first 1 | foreach{$_.Name}
--
Keith