Output string value from Get-ChildItem
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I got the following string from Output sub-folder with the latest write access , try this: Get-ChildItem $filepath | ? { $_.PsIsContainer} | Sort LastWriteTime -Descending | Select -expa Name -First 1
|
How to use output of get-childitem command
Date : March 29 2020, 07:55 AM
With these it helps There is something missing from your code. As it stands this contains no information about zipping a directory. The root of the issue with the code you are showing is you are asking Invoke-Expression to run a folder name. Your $command is returning an object that contains one folder. Was that what you wanted? You then take that folder object and put it into Invoke-Expression. $file = means that you mean to put the results of Invoke-Expression into $file. I also notice you have the command in single quotes which would mean Invoke-Expression would attempt to expand it. More testing is required. I would take a guess that you want to change this up a little. $folder = Get-ChildItem -Path E:\test | Where-Object {$_.PSIsContainer} | Sort-Object LastWriteTime -Descending | Select-Object -First 1 -ExpandProperty FullName
$folder = Get-ChildItem -Path E:\test | Where-Object {$_.PSIsContainer} | Sort-Object LastWriteTime -Descending | Select-Object -First 1 -ExpandProperty FullName
$destination = "e:\test\myZip.zip"
[Reflection.Assembly]::LoadWithPartialName( "System.IO.Compression.FileSystem" )
[System.IO.Compression.ZipFile]::CreateFromDirectory($folder, $destination)
Get-ChildItem -Path E:\test | Where-Object {$_.PSIsContainer} | Sort-Object LastWriteTime -Descending | Select-Object -First 1 | Write-Zip -IncludeEmptyDirectories -OutputPath E:\Test\MyZip.zip
|
Capture Get-ChildItem results into string array for HTML output
Date : March 29 2020, 07:55 AM
seems to work fine The only reason I can think you want to split is to get an array of filenames. If that's the case, you can do: $list = (Get-ChildItem -Force "C:\Users\Someuser\Downloads").FullName
createHTML($listDownloads -join "`n")
|
Get-ChildItem Zero Results Output
Date : March 29 2020, 07:55 AM
around this issue You are using the wrong variable in the Get-Content cmdlet ($Files instead of $File). Also You can simplify your script: $Directory = "L:\Controls\BCR\"
$variable = "-"
$suffix = ".tmp"
Get-ChildItem $Directory -Filter '*cash*csv' |
ForEach-Object {
(Get-Content $_ -Raw) -replace $variable |
Set-Content {$_.BaseName + $suffix}
}
|
powershell performance: Get-ChildItem -Include vs. Get-ChildItem | Where-Object
Date : March 29 2020, 07:55 AM
it should still fix some issue Get-ChildItem is a provider cmdlet - that means that a bulk of its actual work is offloaded to an underlying provider, likely the FileSystem provider in your case. The provider itself doesn't actually support the -Include/-Exclude parameters, that's one of the few things that the cmdlet takes care off - and for the file system provider this is ultra heavy double-work, because the cmdlet needs to recurse down through the file system hierarchy to figure out whether it needs to apply an exclusion or an inclusion based on a parent directory name, you can see how this is implemented here.
|