powershell-2.0

How to close all windows

时间秒杀一切 提交于 2019-11-30 15:12:09
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? 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 windows is still alive but the last command in your script can be stop-process powershell note: this no affect

Powershell: How to use Format-Table with XML data

谁说胖子不能爱 提交于 2019-11-30 14:17:31
<tickets type="array"> <ticket> <assigned-user-id type="integer">123</assigned-user-id> <closed type="boolean">true</closed> <creator-id type="integer">177522</creator-id> <number type="integer">306</number> <state>resolved</state> <tag nil="true"/> <title> title text 1 </title> <updated-at type="datetime">2012-03-14T13:13:11+11:00</updated-at> <user-id type="integer">96438</user-id> <version type="integer">3</version> <user-name>Username</user-name> </ticket> </tickets> I am a Powershell newbie and find a question on xml and format-table. Given above xml file. If I run below script to display

powershell 2.0 redirection file handle exception

我是研究僧i 提交于 2019-11-30 13:51:35
I'm looking for a solution to the The OS handle's position is not what FileStream expected. Do not use a handle simultaneously in one FileStream and in Win32 code or another FileStream. exception that would also work on scripts called within the script containing "the fix" . For the purposes of this question, say that I have two scripts: foo.ps1 # <fix> $bindingFlags = [Reflection.BindingFlags] "Instance,NonPublic,GetField" $objectRef = $host.GetType().GetField( "externalHostRef", $bindingFlags ).GetValue( $host ) $bindingFlags = [Reflection.BindingFlags] "Instance,NonPublic,GetProperty"

Having a optional parameter that requires another parameter to be present

邮差的信 提交于 2019-11-30 13:23:38
Quite simply, how do I initialize the params part of my Powershell Script so I can have a command line arguments like Get-Foo [-foo1] <foo1Arg> [-foo2 <foo2Arg> [-bar <barArg>]] So the only time I can use -bar is when foo2 has ben defined. If -bar was not dependent on -foo2 I could just do [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$foo1, [string]$foo2, [string]$bar ) However I do not know what to do to make that dependent parameter. My reading of the original question is slightly different to C.B.'s. From Get-Foo [-foo1] <foo1Arg> [-foo2 <foo2Arg> [-bar <barArg>]] The

PowerShell Remoting giving “Access is Denied” error

↘锁芯ラ 提交于 2019-11-30 13:10:11
问题 I am trying to use PowerShell Remoting to check some disk sizes from a Server in a remote domain, but the commands I am running are failing to work. The situation is like this: Source Server is in Domain A Destination Server is in Domain B There is no trust in place between these domains The Server in Domain B is running Exchange 2010, and I can run Exchange 2010 Specific commands against it from Server A using this command: $Session = New-PSSession -ConfigurationName Microsoft.Exchange

Powershell Error “The term 'Get-SPWeb' is not recognized as the name of a cmdlet, function…”

☆樱花仙子☆ 提交于 2019-11-30 11:46:35
问题 I just typed the follow to try and get my SharePoint site: $spWeb = Get-SPWeb -Identity "http://nycs00058260/sites/usitp" It gave me the following error The term 'Get-SPWeb' is not recognized as the name of a cmdlet, function, script... The url is correct so why am I getting this error? 回答1: I think this need to be run from the Management Shell rather than the console, it sounds like the module isn't being imported into the Powershell console. You can add the module by running: Add-PSSnapin

PowerShell pass by reference not working for me

牧云@^-^@ 提交于 2019-11-30 11:38:13
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? manojlds Call like this: swap ([ref]$a) ([ref]$b) The mistake of using , is described in the Common Gotchas for PowerShell here on Stack Overflow . Shay Levy By the way, PowerShell has a special syntax to swap values, and there isn't a need to

Removing more than one white space in powershell

血红的双手。 提交于 2019-11-30 11:37:43
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. If you're looking to collapse multiple consecutive whitespace characters into a single space then you can do this using the -replace operator: '[ Hello, World! ]' -replace '\s+', ' ' ...returns... [ Hello, World! ] The

Run my third-party DLL file with PowerShell

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 10:59:43
问题 I am not sure if this is possible or not with PowerShell. But basically I have a Windows Forms program that configures a program called EO Server. The EO Server has an API, and I make a reference to EOServerAPI.dll to make the following code run. using EOserverAPI; ... private void myButton_Click(object sender, EventArgs e) { String MDSConnString="Data Source=MSI;Initial Catalog=EOMDS;Integrated Security=True;"; //Create the connection IEOMDSAPI myEOMDSAPI = EOMDSAPI.Create(MDSConnString); /

powershell - extract file name and extension

醉酒当歌 提交于 2019-11-30 10:53:40
问题 I need to extract file name and extension from e.g. my.file.xlsx. I don't know the name of file or extension and there may be more dots in the name, so I need to search the string from the right and when I find first dot (or last from the left), extract the part on the right side and the part on the left side from that dot. Maybe there is better solution, but I did'n find anything here or anywhere else. Thank you 回答1: If the file is coming off the disk and as others have stated, use the