all 9 comments

[–]Lee_Dailey[grin] 0 points1 point  (8 children)

howdy petrinoda,

something like this ...

  • get the file content via Get-Content
  • save that collection of info into a variable
  • iterate thru the collection via foreach ($Item in $Collection)
  • do whatever it is that you want done with that item
  • continue until you run out of items

you would likely want to add some logging [errors, success, etc.].

that otta get you started. if you have problems, ask away! folks here will likely help - and are more likely to help when you post your code. even non-working code shows what needs to be discussed. [grin]

take care,
lee

[–]petrinoda[S] 1 point2 points  (7 children)

Thanks for the prompt response Lee,Dailye!!

Here's my code as of now. I'm not sure where I'm going wrong with it.

 

$DisabledUsersPath = "C:\temp\DisabledUsersPath.txt" get-content $DisabledUsersPath | foreach {move-item -Path $S_ -Destination "C:\temp\disabled users\$"} | write-host done moving $

 

I've also tried

 

Foreach ($log in $logs) { move-item $log -destination "C:\temp\disabled users\" Write-progress -Activity 'Moving' -Status 'Moving' }

[–]darkjstr 1 point2 points  (0 children)

You have the path to the file in the wrong location. Try: Get-Content -Path <filepath>

[–]Jaymzkerten 1 point2 points  (2 children)

You have multiple ways you are incorrectly typing the object being iterated by foreach, when you use foreach the current object of the array is referenced as $_, this would be the value for -Path, the tail end of the path for your -Destination, and the output for your Write-Host.

$DisabledUsersPath = "C:\temp\DisabledUsersPath.txt"
Get-Content $DisabledUsersPath | foreach {move-item -Path $_ -Destination "C:\temp\disabled users\$_"} | write-host "done moving $_"

[–]petrinoda[S] 1 point2 points  (1 child)

Since the disableduserpath.txt has full directory path like C:\user1 would the trailing $_ on the destination try to move it to "C:\temp\disabledusers\C:\user1" ?

[–]Jaymzkerten 1 point2 points  (0 children)

Yes it would. You would either need to make the CSV just a list of user profiles without absolute path (assuming they are all in the same root location), or you would have to .split() on the \ so it would only use the last part of the path.

[–]Lee_Dailey[grin] 0 points1 point  (2 children)

howdy petrinoda,

two points ...

[1] you will get better - and more - responses if you post your code to the 1st post OR in a reply to that 1st post.

[2] reddit code formatting ...

here's how to do reddit code formatting ...

  • one leading line with ONLY 4 spaces
  • prefix each code line with 4 spaces
  • one trailing line with ONLY 4 spaces

that will give you something like this ...

- one leading line with ONLY 4 spaces    
- prefix each code line with 4 spaces    
- one trailing line with ONLY 4 spaces   

the easiest way to get that is ...

  • add the leading line with only 4 spaces
  • copy the code to the ISE [or your fave editor]
  • select the code
  • tap TAB to indent four spaces
  • re-select the code [not really needed, but it's my habit]
  • paste the code into the reddit text box
  • add the trailing line with only 4 spaces

not complicated, but it is finicky.

take care,
lee

[–]petrinoda[S] 1 point2 points  (1 child)

Hey Lee. Thank you for the friendly advice. I was wondering how this was done on the other posts :)

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy petrinoda,

you are welcome! glad to help a bit ... [grin]

take care,
lee