Can Switch do two things from One selection?

powershell

    Next

  • 1. Syntax files for 3rd party editors
    Looking at using something else to write my scripts. From looking back in this NG, there's a syntax file for "TextPad" (never heard of it), and I seem to remember one for Vim maybe? Are there others? Comments on which may be the most up-to-date/advanced? Marco
  • 2. Duplicating import-csv with write-output
    Wondering if we can duplicate the output of import-csv using write-output instead? PS C:\> write-output "Country,Points" ` >> "U.S.A.,20" ` >> "Canada,10"|format-table -property country,points >> Country,Points U.S.A.,20 Canada,10 PS C:\> gc country.csv Country,Points U.S.A.,20 Canada,10 PS C:\> import-csv country.csv Country Points ------- ------ U.S.A. 20 Canada 10 I have a cmdlet (PowerGadget's out-map) that takes import-csv formatted input, and I'm wondering if I can add some more smarts to the data input. Can import-csv use scriptblocks? I'm not sure if that would do the trick for me...
  • 3. local admin group members?
    What is the equivalent in PS of the bellow code (cannot find .members in PS): strComputer = "atl-fs-01" Set colGroups = GetObject("WinNT://" & strComputer & "/Administrators") For Each objUser In colGroups.Members Wscript.Echo objUser.Name Next Thanks, VB
  • 4. Using group|sort count
    PS C:\> gc country.csv Country,Points U.S.A.,20 Canada,10 PS C:\> gc country.csv|%{$_.split(',')[0]}|group|sort count Count Name Group ----- ---- ----- 1 Canada {Canada} 1 U.S.A. {U.S.A.} 1 Country {Country} Can I use group|sort count to give me output formatted simply like this (Country,Total count): Canada,1 U.S.A.1 Using select-object? Perhaps there's a better way? I have it working using an ADO recordset, but is that overkill?

Can Switch do two things from One selection?

Postby OldDog » Sat, 30 Aug 2008 03:52:50 GMT

Hi,

I was wondering if I could use switch at the end of my PS script to do
the following:

$title = "Save File or Continue"
$message = "Do you want to Save the file in C:\Scripts and Quit Excel?
Click on Yes or No"

$yes = New-Object System.Management.Automation.Host.ChoiceDescription
"&Yes", `
    "Saves the file in C:\Scripts and Quits Excel."

$no = New-Object System.Management.Automation.Host.ChoiceDescription
"&No", `
    "Saves the file in C:\Scripts and leaves Excel open."

$options = [System.Management.Automation.Host.ChoiceDescription[]]
($yes, $no)

$result = $host.ui.PromptForChoice($title, $message, $options, 1)

switch ($result)
    {
        0 {$xl.Quit()}
        1 {"You selected No."}
    }


For selection 0 I would like to $xl.Quit() and kill the process. stop-
process -name excel

I want to do this because for some reason, Excel keeps running on my
system after I quit.

TIA

OldDog

Re: Can Switch do two things from One selection?

Postby Kryten » Sat, 30 Aug 2008 08:39:38 GMT

Hi OldDog,

I don't see why you can't do more than one thing in a single switch
block..

$title = "Save file or continue?"
$message = "Do you want to Save the file in C:\Scripts and Quit Excel?
Choose YES or NO"
$a = new-object -comobject wscript.shell;$b = $a.popup("$message",
0,"$title", 4)
switch ($b) {
6 { " You selected yes"
	#--Do your YES stuff under here--#
	$xl.Quit()
	Stop-Process -name EXCEL
   }
7 {	"You selected no"
	#--Do your NO stuff under here--#
        #-->>                                      <<--#
   }
}

Good luck,
Stuart


Re: Can Switch do two things from One selection?

Postby Kryten » Tue, 02 Sep 2008 05:48:42 GMT

Hi Shay,

The EXCEL process{*filter*} around after I've closed it manually has
been something that's
bugged me for a long time now.

I tried your suggestion and it kills that process.

Brilliant! Thank you.

Are there any other com objects that come to mind that would benefit
from this type of
'clean up' after use?

Regards,
Stuart





Re: Can Switch do two things from One selection?

Postby Shay Levy [MVP] » Tue, 02 Sep 2008 06:16:06 GMT

Hi OldDog,


Try to release the com object after quiting:

[System.Runtime.Interopservices.Marshal]::ReleaseComObject($xl)




---
Shay Levy
Windows PowerShell MVP
 http://www.**--****.com/ 



O> Hi,
O> 
O> I was wondering if I could use switch at the end of my PS script to
O> do the following:
O> 
O> $title = "Save File or Continue"
O> $message = "Do you want to Save the file in C:\Scripts and Quit
O> Excel?
O> Click on Yes or No"
O> $yes = New-Object System.Management.Automation.Host.ChoiceDescription
O> "&Yes", `
O> "Saves the file in C:\Scripts and Quits Excel."
O> $no = New-Object System.Management.Automation.Host.ChoiceDescription
O> "&No", `
O> "Saves the file in C:\Scripts and leaves Excel open."
O> $options = [System.Management.Automation.Host.ChoiceDescription[]]
O> ($yes, $no)
O> 
O> $result = $host.ui.PromptForChoice($title, $message, $options, 1)
O> 
O> switch ($result)
O> {
O> 0 {$xl.Quit()}
O> 1 {"You selected No."}
O> }
O> For selection 0 I would like to $xl.Quit() and kill the process.
O> stop- process -name excel
O> 
O> I want to do this because for some reason, Excel keeps running on my
O> system after I quit.
O> 
O> TIA
O> 
O> OldDog
O>



Re: Can Switch do two things from One selection?

Postby Alex K. Angelopoulos » Wed, 03 Sep 2008 00:24:38 GMT

Excel is generally the worst offender this way - there have been problems 
with it not shutting down when told to that go back a very long time - but 
there definitely are other ActiveX applications that exhibit this kind of 
behavior. Since ActiveX applications are generally rare and each have their 
own quirks, I usually test whether they shut down in different situations 
when using them from PowerShell by keeping an eye on the process list, then 
release the object if they don't shut down correctly.

Unfortunately, this isn't all that useful if you're keeping an application 
around to use during a PowerShell session. In those cases, I've noticed that 
even some of the better-behaved ActiveX applications don't work the way we 
might want. For example, some of the better-behaved ActiveX applications 
will indeed shut down automatically if they don't have an open, modified 
document when you close PowerShell by typing exit, but will hang around if 
you close PS with the "X" at the top of the shell window. My general rule of 
thumb is to always unhide ActiveX applications and minimize them. This at 
least ensures that I can see and close them if I exit PS the wrong way or 
lose connection to the app somehow.









Similar Threads:

1.Can I do two things at One time???

I need to know can I use MCE 2005 PC to surf the net at the same time someone 
is on the extender using the XBOX extender to access music and ect. from the 
same PC or can you only do one thing at a time? I am really confused if 
someone could just explain it a little bit I would appreciate it!!!

2.One or Two, Routers or Switches ?

Hi, I am not a computer professional and am quite ignorant when it
comes to networking. I have a question to the group and will appreciate
if some knowledgable person can give me an answer.

Recently I have been assigned a task to set up a six computer lab at
work. They all run on Windows 2000 Pro (Don't ask me why they don't
hire a pro to do it) We have two network feeds in the room. My question
is, what is the best inexpensive way to hook up the six computers to
the network, while making maximum use of the bandwidth provided by the
two feeds ?

Should I buy one or two, switch or router ? If I buy one switch can the
two feeds be plugged in and utilized ? I have seen a switch with eight
ports but does not specify where should the feed goes, does it matter ?


If one switch / router will not work and I will have to buy TWO to make
use of the two network feeds, what would be the differences between
having routers or switches ?

Thank you in advance.

3.Two nics, one server - unmanaged switch

Hello,

I was curious if there is a way to give my server more throughput.   I 
currently have all gigabit switches (unmanaged).   My server is a 2950 and 
we work with a lot of very large files.    I have enough memory and 
processing power however the network throughput is a little high. 
Currently I have one nic connected.

Thanks 


4.Switching from two nics to one

I am currently running SBS 2003 Standard and have two offices both with 
non-static IPs that I need to have a static VPN between.  The main office's 
IP is managed through DYNDNS.org.  Everything I read says that to utilize VPN 
routers I should go to a single nic on the SBS server.  Is this the best 
strategy?  Each office also has a wireless router.  Should the setup be 
Broadband Modem>VPN Router>Server, Wireless router?  Am I headed down the 
correct path?

Skids.

5.How to switch primary/secondary mouse button on only one of two mi

I have two touchpads (Cirque EasyCat USB) plugged into my Windows XP laptop.  
I like to switch hands between the one mounted on my right and one mounted on 
my left.  So, I would like to make the mouse on the left act left-handed by 
switching the primary and secondary buttons.  And leave the mouse on the 
right with normal primary and secondary buttons.

The Windows XP "Mouse Properties" box has a "Switch primary and secondary 
buttons" option, but that affects all connected mice.  It isn't worth the 
effort to toggle this everytime I switch hands.

Is there a way to "Switch primary and secondary buttons" for just one of the 
mice?


thanks,
Steve

P.S. I even tried physically opening the device to see if I could switch 
some wires.  But the switches are mounted on the circuitboard directly and 
I'm not skilled enough with soldering to change that.



Return to powershell

 

Who is online

Users browsing this forum: No registered users and 52 guest