Тёмный

Export all Folders names using powershell script 

InfoAlias
Подписаться 1,9 тыс.
Просмотров 737
50% 1

The provided PowerShell script is designed to automate the process of copying the names of all folders within a specified directory to a text file. This can be particularly useful for maintaining a record or inventory of folder names in a specific location.
Here's a breakdown of how the script works:
Source Directory: Begin by setting the $sourceDirectory variable to the path of the directory from which you want to collect the folder names. This is the location where the script will search for folders.
Output Text File: Set the $outputFilePath variable to the desired path for the output text file. This is where the script will write the folder names.
Get Folders: The script uses the Get-ChildItem cmdlet with the -Directory parameter to retrieve a list of all folders (subdirectories) within the specified source directory.
Array for Folder Names: An empty array called $folderNames is initialized. This array will be used to store the names of the folders.
Loop through Folders: The script uses a foreach loop to iterate through each folder in the list obtained in step 3. For each folder, it extracts the folder name using the .Name property and adds it to the $folderNames array.
Write to Text File: Once all folder names have been collected, the script uses the Out-File cmdlet to write the contents of the $folderNames array to the output text file specified in the $outputFilePath variable.
Confirmation Message: Finally, the script displays a message in the PowerShell console indicating that the folder names have been successfully copied to the specified output file.
To use the script, you should customize the values of $sourceDirectory and $outputFilePath to match your specific use case. The script can be saved with a .ps1 extension and executed in a PowerShell environment. It's important to note that proper permissions may be required to run PowerShell scripts, and caution should be exercised when executing scripts obtained from untrusted sources.
#powershell
#powershellscripting
#powershelltraining
#windows

Опубликовано:

 

13 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 8   
@mayzter8765
@mayzter8765 4 месяца назад
Thanks a lot, mate:)
@dougydoe
@dougydoe 10 месяцев назад
Hey, Thanks so much for this. This is just what I was looking for .
@InfoAlias
@InfoAlias 10 месяцев назад
Glad to hear it! Pls share with others again thank u 👍
@dougydoe
@dougydoe 10 месяцев назад
@@InfoAlias Sorry, just a quick question. I'm testing my script and it seems the final output to the text file is not working for me. Everything thing seems to work alright as I tested by selecting each section and then running it separately. For that part, the Text file seems to be empty and there is no error in the code as well. Any thoughts why this might be happening? Execution Policy is unrestricted as well.
@dougydoe
@dougydoe 10 месяцев назад
@@InfoAlias Not to worry... I got it working now. Thanks again for sharing
@InfoAlias
@InfoAlias 10 месяцев назад
@@dougydoe may I know what was the issue for knowledge purpose only..
@dougydoe
@dougydoe 10 месяцев назад
@@InfoAlias Looked like I was running the script from OneDrive so I moved it to the C drive.
@joanharris3073
@joanharris3073 Год назад
*Promo SM* 😡
Далее
PowerShell Quick Tips : Get-ChildItem
19:46
Просмотров 4,6 тыс.
Quickly creating a list of files in a folder
3:44
Просмотров 356 тыс.
How to rename MULTIPLE files with Powershell
8:07
Просмотров 12 тыс.
Powershell Get ChildItem  - A Beginners lesson
5:32
Просмотров 8 тыс.
Copy, Move, Delete files with PowerShell
17:01
Просмотров 173 тыс.
Combine text files in Windows - 4 Methods
8:40
Просмотров 18 тыс.
The Unreasonable Effectiveness Of Plain Text
14:37
Просмотров 607 тыс.