powershell-2.0

Find duplicate values in one of the two columns in a text file

不羁岁月 提交于 2019-12-23 11:39:10
问题 I have a text file with two values in each line separated by a space. Now I want to know duplicate values in one of the columns. Is it possible to achieve this using Windows powershell. Given a text file: Apple Fruit Banana Fruit Carrot Vegetable Desired output is: (I want to find duplicates in second column) Fruit 回答1: You could use the Import-CSV cmdlet and specify a whitespace delimiter to easy get access of the second column. Then you can group the objects using the second column and

Alter Sort-Object behavior

元气小坏坏 提交于 2019-12-23 11:01:39
问题 When working with a drive mapped to a Linux share, filenames are case sensitive. PowerShell handles this as expected, but I'd like to sort the output in a manner analogous to the sort order used in the "C" locale, which means sorting by character value in ascending order from U+0000 all the way through U+10FFFF (e.g. '0foo' comes before 'Foo' and 'Foo' comes before 'bar' and 'bar' comes before 'foo') To illustrate the problem: PS > gci Z:\foo | sort -casesensitive xyz Xyz XYZ yZ YZ Output

Alter Sort-Object behavior

给你一囗甜甜゛ 提交于 2019-12-23 11:01:24
问题 When working with a drive mapped to a Linux share, filenames are case sensitive. PowerShell handles this as expected, but I'd like to sort the output in a manner analogous to the sort order used in the "C" locale, which means sorting by character value in ascending order from U+0000 all the way through U+10FFFF (e.g. '0foo' comes before 'Foo' and 'Foo' comes before 'bar' and 'bar' comes before 'foo') To illustrate the problem: PS > gci Z:\foo | sort -casesensitive xyz Xyz XYZ yZ YZ Output

Usage of powerShell.AddCommand

青春壹個敷衍的年華 提交于 2019-12-23 10:47:08
问题 I would like to execute this event using c#. Get-WinEvent -Path 'D:\Events\myevents.evt' -Oldest | Select-Object -Property * | ForEach-Object {$_ | ConvertTo-Json} I have written upto path = "D:\\Events\\myevents.evt"; var powerShell = PowerShell.Create(); powerShell.AddCommand("Get-WinEvent"); powerShell.AddParameter("Path"); powerShell.AddArgument(path); powerShell.AddParameter("Oldest"); powerShell.AddCommand("Select-Object"); powerShell.AddParameter("Property"); powerShell.AddArgument("*"

Why is powershell adding additional parameters to Web Service Method Signatures

孤者浪人 提交于 2019-12-23 09:59:43
问题 I'm trying to use Powershell to ping a couple of WCF Webservices from the command line. e.g. I have an WCF Operation [OperationContract] string DoWork(string name); And I can call that with Powershell using. $proxy = New-WebServiceProxy -Uri 'http://localhost/TestService/Service.svc' $proxy.DoWork('Hello World') This works fine as long as the input params and return types are strings. However if I introduce integers, the generated method signatures & return types have additional

What is the default order of result set from Get-ChildItem command in powershell?

我只是一个虾纸丫 提交于 2019-12-23 08:47:42
问题 What is the default order of result set from Get-ChildItem command in powershell? Is there a order at all or is it just random and would give the results in a different order every time. 回答1: First folders in alphanumeric order (first numbers as [char]). Then files in alphanumeric order (first numbers as [char]). 回答2: There is no guaranteed default sort order. The documentation doesn't state one. The implementation in FileSystemProvider ends up calling DirectoryInfo.GetFiles. The

“Start-Process -NoNewWindow” within a Start-Job?

随声附和 提交于 2019-12-23 08:29:38
问题 I'm having issues using Start-Process within a Start-Job, specifically when using -NoNewWindow . For example, this test code: Start-Job -scriptblock { Start-Process cmd -NoNewWindow -Wait -ArgumentList '/c', 'echo' | out-null Start-Process cmd # We'll never get here } get-job | wait-job | receive-job get-job | remove-job Returns the following error, that apparently google hasnt heard of: Receive-Job : There is an error processing data from the background process. Error reported: Cannot

PowerShell: error executing command using Invoke-Command?

丶灬走出姿态 提交于 2019-12-23 08:08:34
问题 I'm trying to execute the following statement on remoter server: Invoke-Command -ComputerName server1 -ScriptBlock {Get-Process} but I get an error message: [server1] Connecting to remote server failed with the following error message : The client cannot connect to the destination specified in the request. Verify that the serv ice on the destination is running and is accepting requests. Consult the logs and documentation for the WS-Management service running on the destination, most commonly

Powershell script for going into texts files within a directory and replacing characters

不打扰是莪最后的温柔 提交于 2019-12-23 04:37:13
问题 Morning all, I'm trying to work out how to go into a number of text files within a directory, and replace the characters with the following: 'BS' = '\' 'FS' = '/' 'CO' = ':' What I managed to get to so far is: (get-content C:\users\x\desktop\info\*.txt) | foreach-object {$_ -replace "bs", "\"} | set-content C:\Users\x\desktop\info\*.txt I have got 6 text files, all with a line of text in them, the script above copies the line of text into all the text files. So what I end up with is 6 text

How to download newest file from SharePoint using PowerShell

大城市里の小女人 提交于 2019-12-23 04:33:53
问题 I'm just curious, do I have any possibility to download the file from SharePoint document library? The problem is that I have like 3-4 files in this library and I need to get the file with the latest modification date. Thank you in advance. 回答1: Refer to the link below, but instead of using the actual SharePoint URL for the directory use the File Explorer address for the SharePoint site. Powershell Script: $dir = "\\sharepoint.domain.com\site\Foo\SubFoo\SharedDocuments\Folder\" $latest = Get