powershell-2.0

How to close all windows

大城市里の小女人 提交于 2019-11-29 22:14:32
问题 I would like to close all open windows. This will not minimize the windows but the script will close all windows even if it is minimized. Is there a way to do this in a batch program or powershell? 回答1: use this in powershell: Get-Process | Where-Object {$_.MainWindowTitle -ne ""} | stop-process -note: this close powershell console or ise too and can't end his job! (get-process | ? { $_.mainwindowtitle -ne "" -and $_.processname -ne "powershell" } )| stop-process this way only powershell

Rename computer and join to domain in one step with PowerShell

非 Y 不嫁゛ 提交于 2019-11-29 21:25:29
Goal: On a computer running Windows Server 2008 R2, use PowerShell 2.0 to: Rename the computer Join the computer to a domain Condition: Steps 1 and 2 must be performed together, i.e., without a computer restart between them Functions I'm Using These are the PowerShell functions I've created for each step. Rename Computer According to my Internet research, PowerShell 2.0 at one point before release had a built-in cmdlet called Rename-Computer , but it was removed for reasons unknown in CTP 3. My version uses WMI. function Rename-Computer { param ( [Parameter(Mandatory=$true)][string]$name )

How to open Powershell Console Window from Powershell

人走茶凉 提交于 2019-11-29 21:12:36
I am writing a script to use multiple plink (PuTTY) sessions as a Windows version of clusterssh. I am stuck however because I want to open multiple Powershell windows from powershell. When I type the command for powershell, it opens a new session. This is similar to typing bash in bash. I want multiple physical windows opening. I tried -windowstyle as well as the other args to no avail. I was wondering if there is a way you know of. I really appreciate your help. I looked and didn't find anything already here. Thanks for your time. This will do it: Invoke-Item C:\Windows\System32

Combine two or more rows in a csv using powershell

蓝咒 提交于 2019-11-29 18:09:39
I receive a file from one of our clients that looks like this: (I added headers to this to it for easier processing). Sample Input: PlanID,Date,Transaction,Type,Ticker,Amount,Cash 01,121211,div,mf,fjk,25,cash 01,121211,div,mf,fjk,30,cash 01.121211,buy,mf,fjk,55,cash 02,121211,div,sd,ejd,10,cash 02,121211,div,sd,ejd,15,cash 02,121211,buy,sd,ejd,25,cash I need a way to combine all the rows with Transaction= 'div' by summing up their amount for each PlanID. This is how I desire my output to look like: Sample Output: PlanID,Date,Transaction,Type,Ticker,Amount,Cash 01,121211,div,mf,fjk,55,cash 01

Powershell/C#: Invoking a pipeline asynchronously & displaying the results

牧云@^-^@ 提交于 2019-11-29 17:55:43
As per this sample - http://msdn.microsoft.com/en-us/library/windows/desktop/ee706590(v=vs.85).aspx , I am trying to invoke my script in an async way. But, at the same time, I want to give feedback to the GUI on the set of operations happening i.e. want to spit the Write-verbose stuffs happening behind the scenes parallely on the GUI. I am confused in achieving this - because I see there is a DataReady event on the PipelineReader object ? Is it possible to somehow consume that w.r.t the MSDN sample above such that I can show feedback on the GUI ? Conceptually, I am not able to relate this

How to set a binary registry value (REG_BINARY) with PowerShell?

假如想象 提交于 2019-11-29 16:58:15
问题 How to set a binary registry value (REG_BINARY) with PowerShell? Background: I need to change some properties of the ASP.NET State service using a PowerShell script. Unfortunately, the built-in PowerShell cmdlet Set-Service only lets you modify the service description, startup type, display name, and status. I need to modify the Subsequent failures property found on the Recovery tab (when viewing the service's properties). I found that this value was stored in the registry as a REG_BINARY

Removing more than one white space in powershell

為{幸葍}努か 提交于 2019-11-29 16:57:40
问题 I was trying to find a way in powershell to remove more than one white space. But what i found is how to do it in php. "Removing more than one white-space" There will be similar regular expression may available . How to acheive the same in powershell? My string is like this Xcopy Source Desination Some lines may contain more than one white space between Source and destination. 回答1: If you're looking to collapse multiple consecutive whitespace characters into a single space then you can do

pipes and foreach loops

风格不统一 提交于 2019-11-29 16:48:54
Recently, I've been playing with PowerShell, and I've noticed some weird behavior when using pipes and foreach loops that I couldn't understand. This simple code works: $x = foreach ($i in gci){$i.length} $x | measure -max Makes sense. But this code won't: foreach ($i in gci){$i.length} | measure -max And I'm getting the following error: An empty pipe element is not allowed. At line:1 char:33 + foreach ($i in gci){$i.length} | <<<< measure -max + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : EmptyPipeElement What is the difference between

PowerShell pass by reference not working for me

▼魔方 西西 提交于 2019-11-29 16:46:29
问题 I'm trying to make a simple swap function in PowerShell, but passing by reference doesn't seem to work for me. function swap ([ref]$object1, [ref]$object2){ $tmp = $object1.value $object1.value = $object2.value $object2.value = $tmp } $a = 1 $b = 2 $a, $b swap ([ref]$a) ,([ref]$b) $a, $b This SHOULD work, but no... Output: 1 2 1 2 What did I do wrong? 回答1: Call like this: swap ([ref]$a) ([ref]$b) The mistake of using , is described in the Common Gotchas for PowerShell here on Stack Overflow.

Renaming Files with PowerShell

*爱你&永不变心* 提交于 2019-11-29 16:43:04
I need to rename a bunch of files at once in Windows PowerShell. I read the HTG article here and it helped a little. My problem is that It will only rename files in the top of the directory, nothing deeper. For example: There is FOLDER A and inside FOLDERA is a document and FOLDER B. Inside FOLDER B is another document. Both folders and both documents need to be renamed. The way it is working now is that FOLDER A, the document in FOLDER A, and FOLDER B are being renamed, but not the document inside FOLDER B. My current code is: Dir | Rename-Item –NewName { $_.name –replace “ “,”_” } Thanks for