Greetings all. I’m a novice scripter needing a little help. I created the script below, which extracts names and emails from an AD group and names the file with currentdateAB.csv. However, I’d like to name the file using the group name entered by the user. I thought I could output (instead of Export) to $group ( Out-File “$group$_.csv”) but the script fails.<\/p>\n
$scriptFolder = $MyInvocation.MyCommand.Path | Split-PAth -Parent
\n$group = Read-Host -Prompt “Enter AD Group” | Get-ADGroupMember | Get-aduser -properties Mail | Select surname, givenname, mail | export-csv $scriptFolder-$((Get-date).Tostring(‘MM-dd-yyyy’))AB.csv -Notypeinformation -append<\/p>\n
Question: What is the best way to use the entered group to parse and use as the file name for output?<\/p>\n
ex. I enter group1 (when prompted) and the data extracted is placed in a file called group.csv<\/p>","upvoteCount":8,"answerCount":8,"datePublished":"2022-08-19T15:28:04.000Z","author":{"@type":"Person","name":"allspice-777","url":"https://community.spiceworks.com/u/allspice-777"},"suggestedAnswer":[{"@type":"Answer","text":"
Greetings all. I’m a novice scripter needing a little help. I created the script below, which extracts names and emails from an AD group and names the file with currentdateAB.csv. However, I’d like to name the file using the group name entered by the user. I thought I could output (instead of Export) to $group ( Out-File “$group$_.csv”) but the script fails.<\/p>\n
$scriptFolder = $MyInvocation.MyCommand.Path | Split-PAth -Parent
\n$group = Read-Host -Prompt “Enter AD Group” | Get-ADGroupMember | Get-aduser -properties Mail | Select surname, givenname, mail | export-csv $scriptFolder-$((Get-date).Tostring(‘MM-dd-yyyy’))AB.csv -Notypeinformation -append<\/p>\n
Question: What is the best way to use the entered group to parse and use as the file name for output?<\/p>\n
ex. I enter group1 (when prompted) and the data extracted is placed in a file called group.csv<\/p>","upvoteCount":8,"datePublished":"2022-08-19T15:28:05.000Z","url":"https://community.spiceworks.com/t/filename-creation/934031/1","author":{"@type":"Person","name":"allspice-777","url":"https://community.spiceworks.com/u/allspice-777"}},{"@type":"Answer","text":"
Welcome<\/p>\n
If you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>\n