get-childitem

PowerShell script to copy files but not subfolders to SFTP and move to subfolder once done

筅森魡賤 提交于 2021-02-08 02:12:25
问题 I am using the following script to copy files from my local folder to SFTP. Once I upload the file I then want to move the file to a subfolder. I want to upload only files in the C:\Users\Administrator\Desktop\ftp folder, and not files in the other subfolders. param ( $backupPath = "C:\Users\Administrator\Desktop\ftp\moved" ) # Load the Assembly and setup the session properties try { # Load WinSCP .NET assembly Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll" $session = New-Object

PowerShell script to copy files but not subfolders to SFTP and move to subfolder once done

穿精又带淫゛_ 提交于 2021-02-08 02:11:23
问题 I am using the following script to copy files from my local folder to SFTP. Once I upload the file I then want to move the file to a subfolder. I want to upload only files in the C:\Users\Administrator\Desktop\ftp folder, and not files in the other subfolders. param ( $backupPath = "C:\Users\Administrator\Desktop\ftp\moved" ) # Load the Assembly and setup the session properties try { # Load WinSCP .NET assembly Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll" $session = New-Object

Catching paths of inaccessible folders from Get-Childitem

删除回忆录丶 提交于 2021-01-29 08:51:47
问题 I am working on small script to capture file hashes on a running system. I only have Powershell available. This is the active part of the code: get-childitem -path $path -filter $filename -Recurse -Force | Select FullName | foreach-object { get-filehash $_.fullname | select * } this is the command I am testing with: ./Get-FileHashesRecursive.ps1 -path c:\ -filename *.txt When running the script I get a series of errors because certain folders are inaccessible. I'd like to record the paths of

Powershell - using wildcards to search for filename

瘦欲@ 提交于 2021-01-22 04:58:25
问题 I am trying to make a PowerShell script that will search a folder for a filename that contains a certain file-mask. All files in the folder will have format like *yyyyMd*.txt . I have made a script: [String]$date = $(get-date -format yyyyMd) $date1 = $date.ToString Get-ChildItem C:\Users\pelam\Desktop\DOM | Where-Object {$_.Name -like '*$date1*'} But this does not seem to work.. Can anyone help? It seems the problem is that the date variable is not correct because when I hard code something

use get-childitem -recurse in powershell but get each full path on a separate line (without extra directory lines)

流过昼夜 提交于 2020-08-23 09:22:29
问题 If I execute, e.g. Get-ChildItem *.ext -recurse the output consists of a series of Directory: entries followed by one entry for each each matching file. That's useful for many purposes, but today I'd like a result (analogous to the Unix find command) in which each matching file appears on a line by itself and shows its full relative path (and no other lines appear). I've searched a bit but haven't found a solution. 回答1: Get-Childitem by default outputs a view for format-table defined in a

Extract lines matching a pattern from all text files in a folder to a single output file

拈花ヽ惹草 提交于 2020-06-10 15:25:53
问题 I am trying to extract each line starting with "%%" in all files in a folder and then copy those lines to a separate text file. Currently using this code in PowerShell code, but I am not getting any results. $files = Get-ChildItem "folder" -Filter *.txt foreach ($file in $files) { if ($_ -like "*%%*") { Set-Content "Output.txt" } } 回答1: I think that mklement0's suggestion to use Select-String is the way to go. Adding to his answer, you can pipe the output of Get-ChildItem into the Select

Extract lines matching a pattern from all text files in a folder to a single output file

做~自己de王妃 提交于 2020-06-10 15:24:51
问题 I am trying to extract each line starting with "%%" in all files in a folder and then copy those lines to a separate text file. Currently using this code in PowerShell code, but I am not getting any results. $files = Get-ChildItem "folder" -Filter *.txt foreach ($file in $files) { if ($_ -like "*%%*") { Set-Content "Output.txt" } } 回答1: I think that mklement0's suggestion to use Select-String is the way to go. Adding to his answer, you can pipe the output of Get-ChildItem into the Select

Get-ChildItem and non-breaking space

扶醉桌前 提交于 2020-01-24 02:01:28
问题 While working on my file servers, I have noticed one strange folder that broke my script. Folder has name consisting of only one character with ascii value 160 (non-breaking space, NBSP). Visually that name is the same as space character. Briefly, I have Get-ChildItem being executed on this folder and it is entering endless loop. Command is in reality executed against parent folder and it returns again problematic folder, so my script got into endless loop. You can easily simulate this on

is get-childItem's new -file parameter fast like -filter or slow like -include?

一曲冷凌霜 提交于 2020-01-11 13:22:08
问题 EDIT Hoping here to clarify my convoluted and misleading question... based on my mistaken assumption that -file accepts inputs. Thanks for setting me straight and pointing out that it's just a switch parameter; the inputs in my example actually get passed to -path. Sounds like that may be the fastest purely powershell way to search for multiple file types, since -filter accepts only a single input and -include is slower. The get-childItem documentation says "Filters are more efficient than

PathTooLong error with Get-ChildItem in PowerShell v3, but not v2

时间秒杀一切 提交于 2020-01-04 01:55:15
问题 On a Windows Server 2008 R2 VM, I upgraded PowerShell to v3 hoping to take advantage of the Get-ChildItem (gci) performance improvement. This line ran without error in v2: $search = gci $dir -recurse -exclude "*.mdf" | where {$_.length -gt 100mb} After upgrading to v3, why does the same line give this error? The $dir value is unchanged. gci : The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less