Register
: :
Login
Home
News
Forums
Scripts
User Groups
Resources
About
Forums
Search
Members
Unanswered
Active Topics
Forums
>
Using PowerShell
>
General PowerShell
Passing Directory list into an Array
Last Post 08 Feb 2010 02:10 PM by
Shay Levy
. 3 Replies.
Sort:
Oldest First
Most Recent First
Prev
Next
You are not authorized to post a reply.
Author
Messages
Bobdee
Basic Member
Posts:130
08 Feb 2010 07:50 AM
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.
George Howarth
Basic Member
Posts:360
08 Feb 2010 08:20 AM
Try this:
$dirs = dir | where {$_.PsIsContainer}
foreach ($dir in $dirs)
{
Set-Location $dir.fullname
New-Item "robbie.txt" -type file
}
Bobdee
Basic Member
Posts:130
08 Feb 2010 08:46 AM
Brilliant - thanks
Shay Levy
PowerShell MVP, Admin
Veteran Member
Posts:1362
08 Feb 2010 02: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://PowerShay.com
PowerShell Community Toolbar
Twitter:
@ShayLevy
You are not authorized to post a reply.
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
PowerShellCommunity.org
--Community Announcements and Assistance
--Completely Unrelated
--User Groups
--Community Business
----Suggestion Box
Forums
>
Using PowerShell
>
General PowerShell
Active Forums 4.3
Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2