将CSV列保存到数组? [英] Saving CSV columns to array?
问题描述
我想将CSV文件中的三列保存到三个不同的数组中,一个用于用户名,一个用于ip地址,一个用于密码。但它似乎不工作(至少从我理解)。
这里的代码:
$ Importedcsv = Import-csvC:\my\file\is\located\here.txt-Delimiter;
$ Importedcsv.password + = $ PasswordArray
$ Importedcsv.address + = $ AdressArray
$ Importedcsv.username + = $ UsernameArray
这是我得到的错误:
在此对象上找不到属性username。验证该属性是否存在并且可以设置。
在C:\blyat\cyka\ruski.ps1:7 char:1
+ $ Importedcsv.username + = $ UsernameArray
+ ~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo:InvalidOperation:(:) [],RuntimeException
+ FullyQualifiedErrorId:PropertyAssignmentException
我也得到其他列的错误。
如果您想了解更多细节,请问:D
请记住,我只使用PowerShell
CSV档案:
address; username; password
192.168.0.10; advokathuset\user; #adfgad
192.168.0.10; atek\user; #afdgadfg
192.168。 0.10; digo\user; #adfgadf
192.168.0.10; daldens\user; #adfgsdfh
192.168.0.10; elservicetibro\user; adfgdasf
192.168.0.10; finmek\user ; #adfhsfgj
192.168.0.10; formidabel\user; #zadfsgsdfh
192.168.0.10; gronsakshuset\user;#sdfgsfgh1
192.168.0.10; jarisafe\user; #adfgfjg
192.168.0.10; jattadalen\user; #adfgadfgh
192.168.0.10; ks\user; #sadfgsfdgh
192.168.0.10; karstorp\user; #sfdgsgfdh
192.168.0.10 ; leklandet\user; #gadsfhsd
192.168.0.10; nordiskindustri\useer; #sdfgm
192.168.0.10; odz\user; #gsdfjsdrg
192.168.0.10; oneup\user ; #sfdtghsfdg
192.168.0.10; proline\user; #sdfjdgfh
192.168.0.10; saj\user; #dsfgsj
192.168.0.10; swedcon\user; #sadfasd
192.168.0.10; sek \user; #a gffghj
192.168.0.10; sir\user; sfhgd ghj
192.168.0.10; skinnwille\user;#sdfgs35 4dfgh
192.168 .0.10; SMEA\user; dsfg456egt
192.168.0.10; tibromobel\user; fghjfgh1
192.168.0.10; tibrokok\user; sdfgsdfg
192.168.0.10; tottegott \user; sdfgsfgj
192.168.0.10; unojohanssons\user; sdfgsdfg
192.168.0.10; variantkok\user;#dfgsdfgs1
192.168.0.10; wexman\user; sdfg
192.168。 0.10; wikstrands\user; khfjg
192.168.0.10; willbo\user; asdffdsafe
192.168.0.10; skovdeft\user;#5asdfasdf
192.168.0.10; kungsaterkok\user; asdfasdf
192.168.0.10; soderstroms\user; asdfasdf
192.168.0.10; elogistik\user; asdfasdf
解决方案>我看到两个错误。
$ Importedcsv = Import-csvC:\my\file\is\located\here.txt-Delimiter;
$ PasswordArray = @($ Importedcsv.password)
$ AdressArray = @($ Importedcsv.Address)
$ UsernameArray = @($ Importedcsv.username)
I want to save three columns I have in a CSV file to three different arrays, one for usernames, one for ip-addresses and one for passwords. But it doesn't seem to work (atleast from what I understand).
Here's the code:
$Importedcsv = Import-csv "C:\my\file\is\located\here.txt" -Delimiter ";" $Importedcsv.password += $PasswordArray $Importedcsv.address += $AdressArray $Importedcsv.username += $UsernameArray
This is the error I get:
The property 'username' cannot be found on this object. Verify that the property exists and can be set. At C:\blyat\cyka\ruski.ps1:7 char:1 + $Importedcsv.username += $UsernameArray + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : PropertyAssignmentException
I also get the error with the other columns.
If you want more specifics please ask nicely :D
Keep in mind that I have only worked with PowerShell for a few days so please try to explain everything as detailed as possible, thanks!
CSV file:
address;username;password 192.168.0.10;advokathuset\user;#adfgad 192.168.0.10;atek\user;#afdgadfg 192.168.0.10;digo\user;#adfgadf 192.168.0.10;daldens\user;#adfgsdfh 192.168.0.10;elservicetibro\user;adfgdasf 192.168.0.10;finmek\user;#adfhsfgj 192.168.0.10;formidabel\user;#zadfsgsdfh 192.168.0.10;gronsakshuset\user;#sdfgsfgh1 192.168.0.10;jarisafe\user;#adfgfjg 192.168.0.10;jattadalen\user;#adfgadfgh 192.168.0.10;ks\user;#sadfgsfdgh 192.168.0.10;karstorp\user;#sfdgsgfdh 192.168.0.10;leklandet\user;#gadsfhsd 192.168.0.10;nordiskindustri\useer;#sdfgm 192.168.0.10;odz\user;#gsdfjsdrg 192.168.0.10;oneup\user;#sfdtghsfdg 192.168.0.10;proline\user;#sdfjdgfh 192.168.0.10;saj\user;#dsfgsj 192.168.0.10;swedcon\user;#sadfasd 192.168.0.10;sek\user;#a gffghj 192.168.0.10;sir\user;sfhgd ghj 192.168.0.10;skinnwille\user;#sdfgs35 4dfgh 192.168.0.10;SMEA\user;dsfg456egt 192.168.0.10;tibromobel\user;fghjfgh1 192.168.0.10;tibrokok\user;sdfgsdfg 192.168.0.10;tottegott\user;sdfgsfgj 192.168.0.10;unojohanssons\user;sdfgsdfg 192.168.0.10;variantkok\user;#dfgsdfgs1 192.168.0.10;wexman\user;sdfg 192.168.0.10;wikstrands\user;khfjg 192.168.0.10;willbo\user;asdffdsafe 192.168.0.10;skovdeft\user;#5asdfasdf 192.168.0.10;kungsaterkok\user;asdfasdf 192.168.0.10;soderstroms\user; asdfasdf 192.168.0.10;elogistik\user;asdfasdf
解决方案Two errors I can see. You are trying to add to an array the doesn't exist yet and you are trying to put the data in the wrong direction.
$Importedcsv = Import-csv "C:\my\file\is\located\here.txt" -Delimiter ";" $PasswordArray = @($Importedcsv.password) $AdressArray = @($Importedcsv.Address) $UsernameArray = @($Importedcsv.username)
这篇关于将CSV列保存到数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文