powershell-2.0

Windows PowerShell to find duplicate lines in a file

让人想犯罪 __ 提交于 2019-12-10 23:15:07
问题 I need to find the duplicate values in a text file using power shell let's say if the file content is Apple Orange Banana Orange Orange Desired output should be Orange Orange 回答1: You can also use the Group-Object cmdlet to see if any lines occur more than once: e.g. Get-Content test.txt | Group-Object | Where-Object { $_.Count -gt 1 } | Select -ExpandProperty Name 回答2: Used the Commands mentioned below and it worked. PS C:\Projects> $OriginalContent, $UniqueContent = (Get-Content .\File.txt)

Read line-by-line file and split values

微笑、不失礼 提交于 2019-12-10 23:08:24
问题 I need to read a txt file composed as follow: AA=1000,AA=320009#999999 AA=1011,AA=320303#111111 for each readed line I need to split it by "#" to get at the first turn $test[0] = AA=1000,AA=320009 and $test[1]=999999 and at the second turn $test[0] = AA=1000,AA=320003 $test[1]= 1111111 I have some problems to understand how to use get-content or to get it. 回答1: # Basically, Get-Content will return you an array of strings such as below: # $tests = Get-Content "c:\myfile\path\mytests.txt"

powershell loop to continous check if server is up

二次信任 提交于 2019-12-10 22:46:38
问题 I want to run a script to check if 5 servers are up and running based on a specific service is running.If that service is running then we know that server is up and accesible. If it does not reply with a response back then I want it to continously check for it. Heres what I got so far: Get-Service LANMANSERVER -ComputerName JOHNJ1 Get-Service LANMANSERVER -ComputerName JOHNJ2 Get-Service LANMANSERVER -ComputerName JOHND1 Get-Service LANMANSERVER -ComputerName JOHNM Get-Service LANMANSERVER

How can i take a user dump using powershell

不羁的心 提交于 2019-12-10 20:37:57
问题 I want to take user dump of a process using powershell How can i do it? The same I get on rightclicking the process in Taskmanager 回答1: The easiest way is to use Procdump from Sysinternals toolkit. Use Get-Process to get process id, which you can pass to Procdump for actual dumping. Edit: I'd still rather use readily available tools instead of the hard way. Have you got a valid business reason? Since you insist, there is a Win32 API call that creates user mode memory dumps. It can be invoked

How to find amount of time mstsc is used and by whom?

吃可爱长大的小学妹 提交于 2019-12-10 18:06:30
问题 Our team has geographically dispersed and many virtual machine will be connected by them using remote desktop. I would like to find who is accessing a remote desktop session and how long it is being used. I tried to do it with powershell. I wrote a script where user will invoke mstsc using powershell. It will log who has logged in and when he logged. But i would like to find when some one log off from mstsc or disconnect mstsc . Is there any way to capture that information in log file using

powershell function output to variable

瘦欲@ 提交于 2019-12-10 17:52:08
问题 I have a function in powershell 2.0 named getip which gets the IP address(es) of a remote system. function getip { $strComputer = "computername" $colItems = GWMI -cl "Win32_NetworkAdapterConfiguration" -name "root\CimV2" -comp $strComputer -filter "IpEnabled = TRUE" ForEach ($objItem in $colItems) {Write-Host $objItem.IpAddress} } The problem I'm having is with getting the output of this function to a variable. The folowing doesn't work... $ipaddress = (getip) $ipaddress = getip set-variable

How can I remove a single user ACL from a large set of folders?

最后都变了- 提交于 2019-12-10 17:35:35
问题 I have a very large list of folders and I need to remove a single ACL from each of them. Rather than doing it manually, I'm trying to write a script to do it in a fraction of the time, but I'm running into a bit of trouble. Here is what I have so far: $filepath = "C:\ALCTEST" $user = "domain\username" $folders = @((get-item $filePath)) $folders += Get-ChildItem $filePath -Recurse | where { $_.PSIsContainer -ne $false } ##Need to do this in order to remove item 0 from the array, otherwise #

Powershell verb for destroying a resource

邮差的信 提交于 2019-12-10 17:22:48
问题 I've been trying to stick with the approved list of Powershell verbs when naming my cmdlets. I have a function which creates a resource, so it's called New-ClearCaseView. I'd also like to make a function which destroys this resource once it is no longer in use. However, I don't see any pair verb to go with New. The Remove verb is closest I think, but that's for removing a resource from a collection, not for actually destroying a resource. Any suggestions? Is there any more up to date list of

Powershell: Change file attributes automatically when copying

删除回忆录丶 提交于 2019-12-10 17:01:06
问题 I have a folder of read only files. When I copy one of these files to a test location, I want to be able to copy them and not retain their original attributes. I can do this, but this is lengthy. copy-item srcfilefullname destfilefullname set-itemproperty destfilefullname -isreadonly $false I did not find anything in the documentation for copy-item. I am hoping there is a shorter way. Thanks Steeluser 回答1: Your intention is not very clear. If you want to build a one-liner from that, try this

Removing an item from a array of objects in Powershell

扶醉桌前 提交于 2019-12-10 16:15:19
问题 I have an array object $a which returns an output like below. And by doing $a[0].Name I can access each "Name" entry, $a[0].Available I can access its corresponding Available space. I have another array say $b which contains some names, say $b returns me two names "sandeep_aggr1" and "aggr4". This is just an array (no properties like Name, Avaiable), not an object, so It can't use Compare-Object. I want to remove other entries in the original object $a, except for those with "Name" equal to