powershell

Trouble parsing string to object with PowerShell

匆匆过客 提交于 2021-02-08 07:33:27
问题 I have a string with structured data (see below). I need to take this string and convert it to an object, so I can export it to .csv (or whatever else is requested of me). I ran the following code: $data = $string -replace "\s*:\s*","=" But my output looks like this: City=Country=Department=DisplayName=John Doe DistinguishedName=CN=John Doe, CN=Users, DC=domain, DC=com EmailAddress=jdoe@domain.com Enabled=False Fax=GivenName=John MobilePhone=Name=John Doe ObjectClass=user ObjectGUID=cdb9a45c

what does “..”(DotDot) mean in “cd..” command in powershell? [closed]

淺唱寂寞╮ 提交于 2021-02-08 07:30:10
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 1 year ago . Improve this question I already know what it does. it simply goes one directory or folder backwards . But what's mysterious for me are those two dot. cd.. #it has the same function as popd with the difference that it changes the #current working directory if someone tell me what is

Replace column comma separator in csv file and handle fields with single quotes around value

我与影子孤独终老i 提交于 2021-02-08 07:27:46
问题 A system is producing a csv file which i have no influence over. There are two columns where the values MAYBE enclosed in a pair of single quotes if the data itself contains commas. Example Data - 4 columns 123,'abc,def,ghf',ajajaj,1 345,abdf,'abc,def,ghi',2 556,abdf,def,3 999,'a,b,d','d,e,f',4 Result I want using powershell... The commas that are not part of the data - meaning those commas that separate the fields are replaced with a specified delimiter (in the case below pipe-star). Those

Replace column comma separator in csv file and handle fields with single quotes around value

佐手、 提交于 2021-02-08 07:26:51
问题 A system is producing a csv file which i have no influence over. There are two columns where the values MAYBE enclosed in a pair of single quotes if the data itself contains commas. Example Data - 4 columns 123,'abc,def,ghf',ajajaj,1 345,abdf,'abc,def,ghi',2 556,abdf,def,3 999,'a,b,d','d,e,f',4 Result I want using powershell... The commas that are not part of the data - meaning those commas that separate the fields are replaced with a specified delimiter (in the case below pipe-star). Those

How can I keep UNIX LF line endings?

百般思念 提交于 2021-02-08 07:25:41
问题 I have a large (9 GiB), ASCII encoded, pipe delimited file with UNIX-style line endings; 0x0A. I want to sample the first 100 records into a file for investigation. The following will produce 100 records (1 header record and 99 data records). However, it changes the line endings to DOS/Winodws style; CRLF, 0x0D0A. Get-Content -Path .\wellmed_hce_elig_20191223.txt | Select-Object -first 100 | Out-File -FilePath .\elig.txt -Encoding ascii I know about iconv, recode, and dos2unix. Those programs

How can I keep UNIX LF line endings?

淺唱寂寞╮ 提交于 2021-02-08 07:25:05
问题 I have a large (9 GiB), ASCII encoded, pipe delimited file with UNIX-style line endings; 0x0A. I want to sample the first 100 records into a file for investigation. The following will produce 100 records (1 header record and 99 data records). However, it changes the line endings to DOS/Winodws style; CRLF, 0x0D0A. Get-Content -Path .\wellmed_hce_elig_20191223.txt | Select-Object -first 100 | Out-File -FilePath .\elig.txt -Encoding ascii I know about iconv, recode, and dos2unix. Those programs

How to insert list as parameter from powershell to SqlPlus

橙三吉。 提交于 2021-02-08 07:24:55
问题 I have a query which is like this in a file : script.sql select * from test_table where name in (&1) This is an example of query i'm trying to make and i execute it with a power shell script which is like this : $names = '''Name1'', ''Name2''' $params = '"' + $names + '"' sqlplus -silent $username/$password@$tnsalias "@script.sql" $params Note that $names has a variable list of names But then when the script is executed, the parameter get substitute like this : former : where name in (&1) new

Output for try / catch in Powershell Classes

橙三吉。 提交于 2021-02-08 07:24:53
问题 Experimenting with using classes in powershell, I'm uncertain how to display output. For instance in this code block the write-error does not display the error message: class Test { [string] $test Test ([string] $test) { $this.test = $test } [test] Testfail() { try { Get-Childitem F:\ -ErrorAction stop } catch { Write-Host "ERROR!!! $this.test" Exit 1 } return $this.test + "not an error!" } } In this case it's is obvious that the code runs the catch statement as the powershell window exits

Output for try / catch in Powershell Classes

ぃ、小莉子 提交于 2021-02-08 07:23:47
问题 Experimenting with using classes in powershell, I'm uncertain how to display output. For instance in this code block the write-error does not display the error message: class Test { [string] $test Test ([string] $test) { $this.test = $test } [test] Testfail() { try { Get-Childitem F:\ -ErrorAction stop } catch { Write-Host "ERROR!!! $this.test" Exit 1 } return $this.test + "not an error!" } } In this case it's is obvious that the code runs the catch statement as the powershell window exits

How to insert list as parameter from powershell to SqlPlus

此生再无相见时 提交于 2021-02-08 07:23:00
问题 I have a query which is like this in a file : script.sql select * from test_table where name in (&1) This is an example of query i'm trying to make and i execute it with a power shell script which is like this : $names = '''Name1'', ''Name2''' $params = '"' + $names + '"' sqlplus -silent $username/$password@$tnsalias "@script.sql" $params Note that $names has a variable list of names But then when the script is executed, the parameter get substitute like this : former : where name in (&1) new