0

I am trying to rename the file export.csv to the $name but with a .csv extension instead of .file. The output is still $name.file.

Import-Module ActiveDirectory
$name = Read-Host "Enter Group Name"
Get-ADGroupMember -identity "$name" -Recursive |select name, SamAccountName| export-csv -path C:\export.csv -NoTypeInformation

get-childItem *.file | Rename-Item -newname {$name.name -replace '\.file', '.csv'}

So I did this and it works:

Import-Module ActiveDirectory
$name = Read-Host "Enter Group Name"
Get-ADGroupMember -identity "$name" -Recursive |select name, SamAccountName| export-csv -path h:\groups\export.csv -NoTypeInformation
rename-item "h:\groups\export.csv" $name
Dir h:\groups\ | Rename-Item -newname {$_.name + '.csv'}

But how do I get it to rename the file as I run the command instead of doing it for the whole directory every time? What keeps adding .csv?

slybloty
  • 443
  • 2
  • 9
  • 30
sur4
  • 1
  • 2
  • Do you get any errors? – EliadTech Jun 26 '14 at 20:08
  • No it runs and exports the file and adds the .csv to the end but it dows it for the whole folder so when i start doing multiple groups i get file names like group3-name.csv, group2-name.csv.csv, group1name-.csv.csv.csv – sur4 Jun 26 '14 at 20:48
  • Do you mean (export-csv -path "h:\groups\$Name.csv" -NoTypeInformation) ? – EliadTech Jun 26 '14 at 20:54
  • Import-Module ActiveDirectory $name = Read-Host "Enter Group Name" Get-ADGroupMember -identity "$name" -Recursive |select name, SamAccountName| export-csv -path h:\groups\$Name.csv -NoTypeInformation this worked – sur4 Jun 26 '14 at 21:02
  • Thank you I thought i had tried that, but I guess not. – sur4 Jun 26 '14 at 21:03

1 Answers1

0

The solution is to change this line: export-csv -path h:\groups\export.csv -NoTypeInformation to this: export-csv -path "h:\groups\$Name.csv" -NoTypeInformation

EliadTech
  • 1,230
  • 9
  • 14