I have a script that is generating multiple CSV files with the time stamp and group name as part of the file name. Right now the script outputs the CSV files into the directory the script is run from.
I would like to have the CSV files output to a sub directory. Whenever I include a path in my Export-Csv
command, I get an error.
Here is what I have:
#This array lists the names of the AD groups that the script will query to enumerate membership.
$aGroups = @("Group1", "Group2")
#Create a log file to verify that the script did not have any errors.
$strTimestamp = [string](Get-Date -Format "yyyy-MM-dd_hh-mm")
Start-Transcript ADGroupScriptLog-$strTimestamp.txt
Write "Enumerating group membership. This may take some time..."
#Loop through each group in the array and output to CSV each member in the group.
foreach ($group in $aGroups) {
Get-QADGroupMember $group -Indirect -Type 'user' -ShowProgress -ProgressThreshold 0 -Sizelimit '0' |
Select-Object Name, SAMAccountName, givenName, sn, title, manager, Description |
Export-Csv ($strTimestamp + "_" + $group + ".csv") -NoType
}
Write "Execution Complete"
Get-Date -format s
Stop-Transcript
I have tried:
Export-Csv \\Server\Share\File.csv ($strTimestamp + "_" + $group + ".csv") -NoType
********************** Windows PowerShell transcript start Start time: 20180207113151 Username : Machine : (Microsoft Windows NT 6.1.7601 Service Pack 1) ********************** Transcript started, output file is OneSourceUsers-2018-02-07_11-31.txt Enumerating group membership. This may take some time... Export-Csv : Cannot bind parameter 'Delimiter'. Cannot convert value "2018-02-07_11-31_OneSrce_BI_Browser.csv" to type "System.Char". Error: "String must be exactly one character long." At E:\OneSource\get_OneSourceUsers.ps1:19 char:215 + ... neSource\Output($strTimestamp + "_" + $group + ".csv") -NoType + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Export-Csv], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ExportCsvCommand Export-Csv : Cannot bind parameter 'Delimiter'. Cannot convert value "2018-02-07_11-31_OneSrce_BI_Admin.csv" to type "System.Char". Error: "String must be exactly one character long." At E:\OneSource\get_OneSourceUsers.ps1:19 char:215 + ... neSource\Output($strTimestamp + "_" + $group + ".csv") -NoType + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Export-Csv], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ExportCsvCommand Export-Csv : Cannot bind parameter 'Delimiter'. Cannot convert value "2018-02-07_11-31_OneSource MSSQL POC.csv" to type "System.Char". Error: "String must be exactly one character long." At E:\OneSource\get_OneSourceUsers.ps1:19 char:215 + ... neSource\Output($strTimestamp + "_" + $group + ".csv") -NoType + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Export-Csv], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ExportCsvCommand Export-Csv : Cannot bind parameter 'Delimiter'. Cannot convert value "2018-02-07_11-31_One Source Reporting Alert.csv" to type "System.Char". Error: "String must be exactly one character long." At E:\OneSource\get_OneSourceUsers.ps1:19 char:215 + ... neSource\Output($strTimestamp + "_" + $group + ".csv") -NoType + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Export-Csv], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ExportCsvCommand Export-Csv : Cannot bind parameter 'Delimiter'. Cannot convert value "2018-02-07_11-31_One Source Loads.csv" to type "System.Char". Error: "String must be exactly one character long." At E:\OneSource\get_OneSourceUsers.ps1:19 char:215 + ... neSource\Output($strTimestamp + "_" + $group + ".csv") -NoType + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Export-Csv], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ExportCsvCommand Export-Csv : Cannot bind parameter 'Delimiter'. Cannot convert value "2018-02-07_11-31_One Sales Team.csv" to type "System.Char". Error: "String must be exactly one character long." At E:\OneSource\get_OneSourceUsers.ps1:19 char:215 + ... neSource\Output($strTimestamp + "_" + $group + ".csv") -NoType + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Export-Csv], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ExportCsvCommand Export-Csv : Cannot bind parameter 'Delimiter'. Cannot convert value "2018-02-07_11-31_OneSrce_BI_Contributor.csv" to type "System.Char". Error: "String must be exactly one character long." At E:\OneSource\get_OneSourceUsers.ps1:19 char:215 + ... neSource\Output($strTimestamp + "_" + $group + ".csv") -NoType + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Export-Csv], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ExportCsvCommand Execution Complete 2018-02-07T11:31:51 ********************** Windows PowerShell transcript end End time: 20180207113151 **********************