I have been writing a powershell script to solve a problem, the utility of the script may baffle some but I have a use in mind.
The aim of the script is to create a new directory in the temp folder that mirrors the name of the folder in the parent folder but with the script as it is the newly created folder names in the temp folder have the following text around them @{Name=FOLDERNAME} how can I edit the script just to get FOLDERNAME?
$dirs = @(Get-ChildItem -Path C:\Users\LTGoldman\Desktop\keys -Recurse -Directory -Force -ErrorAction SilentlyContinue | Select-Object Name)
for($i=0; $i -lt $dirs.length;$i++)
{
New-Item -Path "C:\Users\LTGoldman\Desktop\keys\temp" -Name $dirs[$i] -ItemType "directory"
Move-Item -Path .\*.tar.gz -Destination C:\Users\LTGoldman\Desktop\keys\temp\$dirs[$i]
}
Changed to:
$dirs = @(Get-ChildItem -Path C:\Users\LTGoldman\Desktop\keys -Recurse -Directory -Force -ErrorAction SilentlyContinue | Select-Object Name)
for($i=0; $i -lt $dirs.length;$i++)
{
New-Item -Path "C:\Users\LTGoldman\Desktop\newkeys" -Name $dirs[$i].Name -ItemType "directory"
Move-Item -Path "C:\Users\LTGoldman\Desktop\keys\"+$dirs[$i]+"\*.tar.gz" -Destination C:\Users\LTGoldman\Desktop\newkeys\$dirs[$i].Name
}
I am not sure how to concatenate the Move-Item line properly?
$dirs[$i].Name(on both lines) or just doSelect-Object -ExpandProperty NameMove-Item -Path .\*.tar.gz, which files are these? The ones that are in each$dirs[$i]?