我有一个脚本正在生成多个 CSV 文件,其中时间戳和组名作为文件名的一部分。现在脚本将 CSV 文件输出到运行脚本的目录中。
我希望将 CSV 文件输出到子目录。每当我在
这是我所拥有的:
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | $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 |
我试过了:
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | 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 ********************** |
当你运行类似
的东西时
PowerShell 将
要从多个变量创建路径字符串,只需使用带有嵌套变量的字符串:
我正在使用ruby1.9解析以下带有MacRoman字符的csv文件#encoding:ISO-8859-1#csv_parse.csvName,main-dialogue"Marceu","Giveittohimóhe,hiswife."我做了以下解析。require'csv'input_string=File.read("../csv_parse.rb").force_encoding("ISO-8859-1").encode("UTF-8")#=>"Name,main-dialogue\r\n\"Marceu\",\"Giveittohim\x97he,hiswife.\"\
查看Ruby的CSV库的文档,我非常确定这是可能且简单的。我只需要使用Ruby删除CSV文件的前三列,但我没有成功运行它。 最佳答案 csv_table=CSV.read(file_path_in,:headers=>true)csv_table.delete("header_name")csv_table.to_csv#=>ThenewCSVinstringformat检查CSV::Table文档:http://ruby-doc.org/stdlib-1.9.2/libdoc/csv/rdoc/CSV/Table.html
我正在使用active_admin,我在Rails3应用程序的应用程序中有一个目录管理,其中包含模型和页面的声明。时不时地我也有一个类,当那个类有一个常量时,就像这样:classFooBAR="bar"end然后,我在每个必须在我的Rails应用程序中重新加载一些代码的请求中收到此警告:/Users/pupeno/helloworld/app/admin/billing.rb:12:warning:alreadyinitializedconstantBAR知道发生了什么以及如何避免这些警告吗? 最佳答案 在纯Ruby中:classA
如果您尝试在Ruby中的nil对象上调用方法,则会出现NoMethodError异常并显示消息:"undefinedmethod‘...’fornil:NilClass"然而,有一个tryRails中的方法,如果它被发送到一个nil对象,它只返回nil:require'rubygems'require'active_support/all'nil.try(:nonexisting_method)#noNoMethodErrorexceptionanymore那么try如何在内部工作以防止该异常? 最佳答案 像Ruby中的所有其他对象
CSV.open(name,"r").eachdo|row|putsrowend我得到以下错误:CSV::MalformedCSVErrorUnquotedfieldsdonotallow\ror\n文件名是一个.txt制表符分隔文件。我是专门做的。我有一个.csv文件,我转到excel,并将文件保存为.txt制表符分隔的文件。所以它是制表符分隔的。CSV.open不应该能够读取制表符分隔的文件吗? 最佳答案 尝试像这样指定字段分隔符:CSV.open("name","r",{:col_sep=>"\t"}).eachdo|row|
是否可以在应用程序中包含的gem代码中知道应用程序的Rails文件系统根目录?这是gem来源的示例:moduleMyGemdefself.included(base)putsRails.root#returnnilendendActionController::Base.send:include,MyGem谢谢,抱歉我的英语不好 最佳答案 我发现解决类似问题的解决方案是使用railtie初始化程序包含我的模块。所以,在你的/lib/mygem/railtie.rbmoduleMyGemclassRailtie使用此代码,您的模块将在
我正在尝试将一个简单的CSV文件读入HTML表格以在浏览器中显示,但我遇到了麻烦。这就是我正在尝试的:Controller:defshow@csv=CSV.open("file.csv",:headers=>true)end查看:输出:NameStartDateEndDateQuantityPostalCode基本上我只获取标题,而不会读取和呈现CSV正文。 最佳答案 这最终成为最终解决方案:Controller:defshow#OpenaCSVfile,andthenreaditintoaCSV::Tableobjectforda
在我让另一个人重做我的前端UI之前,我的Rails应用程序运行平稳。我已经尝试解决此错误3天了。这是错误:Nosuchfileordirectory-identifyExtractedsource(aroundline#59):575859606162@post=Post.find(params[:id])authorize@postif@post.update_attributes(post_params)flash[:notice]="Postwasupdated."redirect_to[@topic,@post]else{"utf8"=>"✓","_method"=>"patc
有谁知道在Heroku的Bamboo堆栈上启动并运行使用DataMapper的Sinatra应用程序所需的魔法咒语?Bamboo堆栈不包含任何预安装的系统gem,无论我尝试使用何种gem组合,我都会不断收到此错误:undefinedmethod`auto_upgrade!'forDataMapper:Module(NoMethodError)这是我的.gems文件中的内容:sinatrapgdatamapperdo_postgresdm-postgres-adapter这些是我将应用程序推送到Heroku时安装的依赖项:----->Herokureceivingpush----->Si
我在Rails3.1项目中有以下助手-我只是想知道是否有办法测试CSV.generate调用。我很想说我知道如何去做,但事实是我什至不知道从哪里开始。任何想法表示赞赏。require'csv'moduleAdmin::PurchasesHelperdefcsv_purchase_listcolumns=['course','amount','first_name','last_name','contact_phone','contact_mobile','created_at']CSV.generate(:col_sep=>";",:row_sep=>"\r\n",:headers=>