Questions tagged [get-childitem]
Get-ChildItem is a powershell cmdlet that gets the items and child items in one or more specified locations.
460
questions
0
votes
0
answers
32
views
ForEach-Object Delete & Out-File
I'm having trouble with one of my file deletion scripts on my directories.
I use Get-ChildItem to get the different files I want and I delete them with a del.
I would then like to keep logs of the ...
1
vote
2
answers
63
views
Using get-childitem -Exclude to avoid recycle bin, windows, program files
I am trying to exclude the "recycle bin", "Windows", and "Program Files" folders in my recursive call to Get-ChildItem.
I figured it would just be -Exclude '$Recycle.Bin',...
1
vote
1
answer
53
views
Searching for only folders that contain a certain folder using powershell
I am trying to use powershell to update some programs for my company. I am writing a script to do so (as instructed). When I install the new version of the program on the machines, it also requires me ...
0
votes
0
answers
24
views
Using GCI with Where-Object doesn't return all files
I'm creating a PowerShell script that searches for files on a server via UNC path but it doesn't return all the files. With -Match $clientName it finds exactly what I enter (ex. Lastname,Firstname) ...
1
vote
1
answer
32
views
How to delete files from multiple folders excluding couple of folders?
We have a situation where the cp.exe and cp.dll are getting copied in build artifacts of all the folders and we want them only to be part of PS.Manager.Service and PS.A.Service folder/Artifacts.
From ...
0
votes
1
answer
29
views
Errors with Get-ChildItem and ChDir if the path contains "["
I am a Powershell newbie, trying to run Get-FileHash over a specific folder. I planned to navigate to the folder first but got an error:
PS C:\Users\pjmmc\Documents\Genealogy\Family Tree Files> cd &...
0
votes
0
answers
11
views
not able to apply all filters with get-childitem and where-object
I am attempting to apply multiple filters to a get-childitem and where-object statement, but continue to get errors no matter how I structure the statement. As far as I'm aware, I have to use the ...
0
votes
0
answers
36
views
Script to copy files not ending
I have a script that will copy files from a set of folder(s) which match a specific string to a location. The script runs fine for the first server, but on the second it just never ends. I have a ...
1
vote
1
answer
37
views
Powershell: Converting Headers from .msg file to .txt - Current directory doesn't pull header information, but specific directory does
So I am trying to make a script to take a batch of .msg files, pull their header information and then throw that header information into a .txt file. This is all working totally fine when I use this ...
1
vote
1
answer
274
views
Using an Index with foreach-object in powershell
I have this code:
Get-ChildItem FOLDERNAMEHERE *.png| ForEach-Object { $_.Name } > fileNames.txt
It prints off a list of file Names, and I want to change it to out just print out an index of ...
0
votes
2
answers
100
views
I need my Get-ChildItem string search command print file names along with their Date Modified values, sorted
I spent quite some time searching for the solution of my problem, but found nothing. I have one single folder with mostly .html files, and I frequently need to search to find the files that contain ...
1
vote
1
answer
47
views
Recursive Get-ChildItem and merging files within the same directory
I am trying to perform a recursive search that will merge files together into a single file within the directory the file was found. Find files named Dexis_Conflit_(*).dat and merge, or create into a ...
1
vote
2
answers
131
views
How can i search for multiple string patterns in text files within a directory
I have a textbox that takes an input and searches a drive.
Drive for example is C:/users/me
let's say I have multiple files and subdirectories in there and I would like to search if the following ...
-1
votes
1
answer
174
views
Get-ChildItem Confusing Results
I'm running Get-ChildItem but its returning TWO results which is confusing me ... why ?
Get-ChildItem "$env:ProgramFiles\Google\Drive File Stream\" -Filter 'GoogleDriveFS.exe' -Recurse
here'...
2
votes
4
answers
197
views
Create file list in every subfolder using PowerShell
I'm very new to PowerShell and have basically zero knowledge about PowerShell scripting, which is why I need some help.
I have folder structure with subfolders (as shown below) for which I want to ...
0
votes
3
answers
55
views
Powershell send directory contents to a program
My goal is to translate .wav files in a directory using an executable which converts them to the proper audio format. Once these files are created, I then need to move everything out of the directory ...
0
votes
1
answer
58
views
Powershell ps1 Get Children Copy command basic
I'm not a coder. I have a Powershell script .ps1 that goes into all subfolders of "db" and deletes the files I want to delete in all of them. It works for what I need. The following code:
...
0
votes
0
answers
62
views
Why is Get-ChildItem inside a Function Access denied after correct New-PSDrive? (It works outside of the function scope.)
This doesnt work
function ImportProcess{
param(
[Parameter()]
[string]$XMLPath
)
$sourcePath = $XMLPath
$DestPath = split-path "$sourcePath" -Parent #this ...
1
vote
1
answer
68
views
Iterate through JSON files and obtain specific data
I'm trying to filter through some sign in log data in JSON format within files.
I've got a directory containing the files here:
Inside these files, is data looking like this:
What I need to do is go ...
0
votes
2
answers
59
views
Powershell create a sort of hash table of the contents of text files and their corresponding file names
I am trying to get the content of text files containing md5 check sums and their corresponding file names.
Example:
file1.iso.md5 contains the checksum "g3d8d3d128200fa20a07e81c90f5f367"
...
0
votes
2
answers
108
views
How can I get a count of directories and files in a base directory and each descendant directory?
I am counting files and folders inside a path, which has several files as well as folders.
I am using this:
dir -recurse | ?{ $_.PSIsContainer } | %{ Write-Host $_.FullName (dir $_.FullName | Measure-...
0
votes
1
answer
112
views
Get-ChildItem into Powershell ListBox GUI
I am trying to find out how I can put the output of an Get-ChildItem into a ListBox.
My idea is, that I want to list the contents of one folder as an Drop-Down Menu within a small Powershell Window. ...
0
votes
0
answers
202
views
Get Child Item where $_.Name matches Variable
I am pulling information from a query and piping it into a data table. From there I am trying to take each item in my data table and run a Get-ChildItem to find the directory location inside a ...
1
vote
1
answer
156
views
PowerShell: Error while using Get-ChildItem with '-Filter'
The following code is part of my script to filter txt files > 0 KB and send them by e-mail as attachments.
$file_path = "\\path\to\my\files"
$file = Get-ChildItem -Path $file_path -Filter ...
0
votes
0
answers
118
views
Powershell - Sort Get-ChildItem in variable Array?
I have a issue where i wan't to create a function for getting certain information on computers through a list.txt of objects in our environment. Foreach $Computer in $Computers. Pipe it into an Array ...
0
votes
1
answer
47
views
How to write the if clause when iterating through a treeview?
I have a function that checks if a barcode is known to the warehouse. If so, the function grabs the row from the dataframe (occupied by an imported excel file) and will be inserted into a treeview ...
2
votes
1
answer
49
views
Copy select items from one folder to a new folder
I am getting all wav files in the past 24 hours from one folder and putting them in another folder. I swear this worked for me a bit ago and wanted to add in some more conditional statements but now ...
2
votes
2
answers
131
views
Powershell find string that matches multiple criteria from an arraylist
Fairly new to PowerShell and am looking to figure out how to find a name of a directory that matches multiple criteria from an array list.
The below code is what has been developed so far:
$...
-1
votes
1
answer
389
views
Posh-SSH PowerShell How to get filename and status, and add line to log file
Im trying copy file to SFTP server i use posh shh and if it was successfully moved then I get the filename and add new line in Log file, otherwise i add line that file wasnt move or file not in source ...
0
votes
1
answer
259
views
Archiving files according to date in file name. Powershell script
I am trying to make simple powershell script that is archiving files coming in daily. Every file has date at the beggining of its name, for example: 20211220_Something.csv, 20211220_SomethingElse.txt, ...
2
votes
1
answer
39
views
PowerShell script to combine CSVs and add root directory as an additional column
I'm trying to write my first PowerShell script and I'm struggling to get my head around the object orientation and piping approach. So I've got a directory structure like this (Google Takeout Nest ...
2
votes
3
answers
220
views
How can I improve the speed and memory usage of calculating the size of the N largest files?
I am getting the total number of bytes of the 32 largest files in the folder:
$big32 = Get-ChildItem c:\\temp -recurse |
Sort-Object length -descending |
select-object -first 32 |
measure-...
0
votes
0
answers
15
views
Pester test fails in pipeline but not locally with get-childitem
As the test says i want to test if folders contains either a subfolder or an rbac.jsonc file. The Test under here is working fine when I run it locally but when I commit it the pipeline fails because ...
1
vote
1
answer
131
views
POWERSHELL script to move only files with numeric digits (within the filename) in common
I was helped in the past few days to find a POWERSHELL script that would help me move only files that had the first 8 characters in common.
The script is the one below and it works perfectly
$...
0
votes
1
answer
44
views
get-childitem either subfolder or a "rbac.jsonc" file
I want to check if all folders contains either a subfolder or an rbac.jsonc file.
I want to iterate through a list of folder $topMgFolderPath being the root folder.
I want to go all the way down the ...
1
vote
0
answers
27
views
Rename files & append Number in Powershell [duplicate]
I'm trying to write a powershell script to rename several files. Their file names are originally long alphanumeric strings that I'm hoping to rename to something more generic and add number to the end....
0
votes
2
answers
196
views
get-childitem find files in folders with same names
I need to check that all files in folders with the naming ".policy" is ether 'azureDeploy.parameters.json' or 'azureDeploy.json'
if i only want it to check one folder i just give the full ...
0
votes
1
answer
40
views
Get-ChildItem path without specifying the full path
So i am trying to get-childItem of a specific path.
my command look like this
(Get-ChildItem -Path fes\.policy -Recurse -Directory -Exclude ".*")
and the fullpath is something like this:
...
-2
votes
1
answer
211
views
Powershell search for text in files
I have a problem. I'm going to search files on my computer for keywords in the files. The keyword is for example "C:\Project".
I get error when running this script below. But when i'm ...
1
vote
1
answer
159
views
powershell loop trough files and execute command against it
I'm figuring out how to loop trough a set of files and execute a program against these files, that outputs a log and tar file as it scans a hyper-v virtual hard disk.
What I already figured out is the ...
1
vote
1
answer
447
views
Using PowerShell to pass all files of a folder as arguments to a command line program
I'm trying to create a file listing of a folder for a secure file transfer tool. This is what I do:
Get-ChildItem c:\files | % {$_.FullName} > c:\temp\list1.csv
$csv = Import-Csv C:\TEMP\list1.csv -...
1
vote
0
answers
44
views
PowerShell: search for a file path in the top level of a folder; warn the user if it's not found and proceed to search recursively
I am writing an auto-grading script that warns the user if the student has/has not followed the directory requirements: specifically, a single file, main.cpp in a folder, named appropriately. If that ...
2
votes
1
answer
245
views
Get-ChildItem return access denied error when run as "SYSTEM"
I'm trying to create a script to get content of a folder across the network. I noticed that Get-Childitem throw "Access Denied" error on every other IP addresses in the list.
For example i ...
0
votes
1
answer
99
views
Powershell GetChildItem no path listed
I have a PowerShell script to scan entire shared drives to create a records retention inventory. However, when I run the code, I get several rows back where there is a file name but no directory name....
0
votes
1
answer
93
views
Query a bigger file server for files and folders with get-childitem
I have a big file server more than 15 TB of files and folders, and I need to get all full names whith get-childitem, I am doing that:
$FSData = Get-ChildItem -Path C:\FS01 -Filter * -Recurse -Force
...
2
votes
1
answer
357
views
Get-ChildItem different commands
What is the difference between the following commands in PowerShell?
Get-ChildItem C:\Users -Directory
Get-ChildItem C:\Users | Where-Object {$_.PSIsContainer -eq $true}
They both seem to give the ...
0
votes
1
answer
42
views
Powershell compare command for 2 folders having corrupt folders
I am using the command below to compare 2 paths and I get an error msg. when it gets to a folder that ends with a period in the name ie "Folder123."
When I manually try to open those folders ...
0
votes
2
answers
143
views
How to make Powershell to output the result to a csv
I am trying to output to a csv file the result that I am getting from "Get-ChildItem"
I need to save only the LastWriteTime and the Name.
This is the Get-ChildItem output
I am trying ...
3
votes
1
answer
446
views
Exclude one folder and a filetype from Get-childitem
I have a website that needs frequent backup hence I would like to write a script to compress all the files in the screenshot. Except:
All the contents in the image folder (See Highlighted)
Any *.log ...
2
votes
2
answers
364
views
Get-ChildItem registry key, extract key name only
I can get a key in the Uninstalls key of the registry, for a specific installed program, like this...
$displayName = 'Parallels Tools'
$key = 'Registry::HKLM\Software\Microsoft\Windows\CurrentVersion\...