Awab Eldaw
Awab Eldaw

Reputation: 23

Built-in function or Cmdlets to store all folders names in an array in PowerShell

I have found an answer of how to store the folders names of the current folder in an array. by @Shay Levy - The Solution - Storing Directory Folder Names Into Array Powershell. So is there anything built-in within PowerShell that do this process. as the variable will be used in another function later.

The solution I found:

$arr = Get-ChildItem \\QNAP\wpbackup | Where-Object {$_.PSIsContainer} | Foreach-Object {$_.Name}

Upvotes: 0

Views: 148

Answers (1)

MikroT
MikroT

Reputation: 81

I think you want to use every single element in array for other scopes:

$wDir = '\\QNAP\wpbackup'
$arr = Get-ChildItem -Directory -Name -Path $wDir

Another solution:

$wDir = '\\QNAP\wpbackup'
$arr = @(Get-ChildItem -Directory -Name -Path $wDir)

Upvotes: 1

Related Questions