Register
: :
Login
Home
Forums
Blogs
Podcast
Directories
Scripts
Downloads
Community
User Group Support
Learning Resources
We have a new sponsor! Introducting
Pragma Systems
. See the home page for details.
Unanswered
Active Topics
Forums
Search
Members
Forums
>
Using PowerShell
>
General PowerShell
Passing Directory list into an Array
Last Post 08 Feb 2010 10:10 PM by
Shay
. 3 Replies.
Sort:
Oldest First
Most Recent First
Prev
Next
You are not authorized to post a reply.
Author
Messages
bobdee1980
New Member
Posts:63
08 Feb 2010 03:50 PM
Can anyone help??
I'm trying to pass all the subfolders in a directory in an array, then (for example) create a file in each of the directories.
Unfortunately, rather than doing this the set-location is falling over as the array is passing more than i anticipated into it. So I recieve an error "Cannot find path '......\@{Name=RobLog}' because it does not exist"
Can anyone tell me how to pass an array into a set-location. Here's what I am using.
$dirs = dir | where {$_.PsIsContainer} | select name
foreach ($dir in $dirs) {
Set-Location $dir
New-Item "robbie.txt" -type file
}
Thanks.
Rob.
GWHowarth88
Basic Member
Posts:348
08 Feb 2010 04:20 PM
Try this:
$dirs = dir | where {$_.PsIsContainer}
foreach ($dir in $dirs)
{
Set-Location $dir.fullname
New-Item "robbie.txt" -type file
}
bobdee1980
New Member
Posts:63
08 Feb 2010 04:46 PM
Brilliant - thanks
Shay
Veteran Member
Posts:1136
08 Feb 2010 10:10 PM
You an cretae tefile without setting location:
dir | where {$_.PsIsContainer} | new-item -type file -path {$_.fullname} -name robbie.txt
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Community Toolbar
Twitter:
@ShayLevy
You are not authorized to post a reply.
PowerShellCommunity.org
--Community Announcements and Assistance
--Completely Unrelated
--User Groups
--Community Business
----Suggestion Box
Using PowerShell
--General PowerShell
--Books, Tools, and Videos
--Exchange Server
--Active Directory
--System Center Family
--Non-Microsoft Products
--SharePoint
--SQL Server
--Working with .NET
--Peer Review
--Testing, Testing...
PowerShell Development
--Cmdlet Development
--PSDrive Provider Development
--Hosting the Shell
Looking Ahead
--Using PowerShell v2.0
--Developing for PowerShell v2.0
Forums
>
Using PowerShell
>
General PowerShell
Active Forums 4.1
Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008