get-childitem

Determine recursively both COUNT and SUM of all extensions in a folder

会有一股神秘感。 提交于 2019-12-18 06:57:21
问题 I would like to be able to select a remote folder and scan it recursively for all file extensions. For each extension discovered, I would need a total count and well as the sum for individual file types. I've found a script here that works for a single file extension using the -include switch, but rather than running the script scores of times, it would be nice to simply run once and collect all extensions. $hostname=hostname $directory = "D:\foo" $FolderItems = Get-ChildItem $directory

How to write a list sorted lexicographically in a grid listed by column?

不羁岁月 提交于 2019-12-17 19:25:36
问题 I have the result of Get-ChildItem , and I want to iterate over these, and display their names. By default if I simply use Write-Host then I get it listed out along the row like this: PerfLogs Program Files Program Files (x86) Python31 Temp Users Windows However, say that I know I want it split into x columns, I want the output like this instead: PerfLogs Python31 Windows Program Files Temp Program Files (x86) Users As you can see, it lists it down the columns first, and then across. Any idea

Get-ChildItem and Copy-Item explanation

梦想的初衷 提交于 2019-12-14 03:45:53
问题 Why does gci $from -Recurse | copy-item -Destination $to -Recurse -Force -Container not behave in the same way as copy-item $from $to -Recurse -Force ? I think it should be the same, but somehow it's not. Why? 回答1: You are not looping over each item in the collection of files/folders, but passing the last value to the pipe. You need to use Foreach-item or % to the Copy-Item command. From there, you also do not need the second -recurse switch as you already have every item in the GCI. try this

Is it possible to filter using Get-ChildItem -Name?

痞子三分冷 提交于 2019-12-12 23:54:01
问题 In one of the questions I answered recently I found interesting answer which shouldn't be working but still was. The question was about how to find specific folder recursively by its name and cd to it. The answer proposed by A guest who's called Redd was: Get-ChildItem -Path .\ -Name Folder -Recurse -Depth 10 As per the documentation of Get-ChildItem, -Name parameter is supposed to be SwitchParameter type and is responsible for returning only name ( System.String ), instead of System.Object .

Get Child Activity Subtree

时光怂恿深爱的人放手 提交于 2019-12-11 09:57:59
问题 I'm converting a legacy workflow system to WF4 so I have to jump through a couple hoops to make it match up with the api of our application. So I'll try to keep the problem explination as simple as possible. :) I have a custom activity that takes a sequence as an argument and then executes it. Prior to executing it, the custom activity needs to traverse the sequence (and it's branches etc) looking for specific types of child activities - then it does some reporting on these specific child

Powershell Copy-Item caching

瘦欲@ 提交于 2019-12-11 09:27:01
问题 I am having an issue with Powershell not copying the latest files across servers when using the below code. $dir="\\MyServer\SQLBackups\SQL Backup*.bak" $FileLocation = "E:\SQLRestore\SQL Backup Latest.bak" If (Test-Path $FileLocation){ Remove-Item $FileLocation } If (Test-Path $dir){ $latest = Get-ChildItem -Path $dir | Sort-Object CreationTime -Descending | Select-Object -First 1 Copy-Item -Path "$latest" -Destination $FileLocation } The code should locate the latest .bak file with the

Excluding multiple folders when copying using powershell

不羁岁月 提交于 2019-12-11 06:52:25
问题 The objective is to copy folders and files from a path to another path using PowerShell. However, I want to exclude certain files and folders from getting copied. I was able to exclude multiple files by adding them to the exclude list Get-ChildItem -Path $source -Recurse -Exclude "web.config","body.css","Thumbs.db" For excluding folders I added $directory = @("Bin") ?{$_.fullname -notmatch $directory} and the final copy script looks like Get-ChildItem -Path $source -Recurse -Exclude "Web

Passing Powershell Get-ChildItem filter parameter through a string variable is not working

岁酱吖の 提交于 2019-12-11 06:15:31
问题 In my script I have below function that returns a string as "*.csproj", "*.vbproj", "*.sln". Assuming I always pass a string such as "csproj, vbproj, sln" to $filter parameter: Function Create-Filter($filter) { $str = $filter.Split(',') | ForEach-Object {"""*.$($_.Trim())"""} $str = $str -join ', ' [string]$str return } Later in my script I perform: $filter = Create-Filter($filter) $myFiles = Get-ChildItem $source -Include $filter -Recurse But $myFiles is empty, Get-ChildItem is not returning

Output sub-folder with the latest write access

笑着哭i 提交于 2019-12-11 05:06:19
问题 I have the following powershell command get-childitem $FilePath | select {$_.Fullname} This will output the name of ALL subfolders in $FilePath. How do I output the subfolder with the latest write time? 回答1: I believe this is what you are after: Get-ChildItem $FilePath | Sort {$_.LastWriteTime} -Descending | Select {$_.FullName} -First 1 If you want to see the last write time too, you can use this: Get-ChildItem $FilePath | Sort {$_.LastWriteTime} -Descending | Select {$_.FullName, $_

How do I merge two “lists” in PowerShell when one list might be just one item from Get-Item?

巧了我就是萌 提交于 2019-12-10 17:42:56
问题 I am using Get-ChildItem to fetch locally installed certs. Then I'd like to delete these certs from my local certificate store. If I execute the script below it will work when there is more than one item returned in both the Get-ChildItem queries. But if only one item is returned in either of the queries the addition of the two collections will fail. Simply because with only one object returned the implementation only returns one instance and not a collection of one. What is the right