Unoffical empeg BBS

Quick Links: Empeg FAQ | RioCar.Org | Hijack | BigDisk Builder | jEmplode | emphatic
Repairs: Repairs

Topic Options
#331572 - 30/03/2010 13:13 PowerShell
drakino
carpal tunnel

Registered: 08/06/1999
Posts: 7868
I'm starting to get into PowerShell, and figured I'd check to see who else out there is using it, and what resources there are out there.

So far, I've been looking through Microsoft's own sites on it, and have these bookmarked:

http://technet.microsoft.com/en-us/scriptcenter/dd742419.aspx
http://msdn.microsoft.com/en-us/library/aa973757(VS.85).aspx
http://blogs.msdn.com/PowerShell/

My long term goal is to try and use PowerShell instead of the older Cmd.exe based environment, both on my local machines and when scripting remote deployments. A few things have won me over so far, mostly due to common command parity between PowerShell and Unix commands. I've also run into quirks already, like invoke-item causing a network based app to not quite function properly.

Top
#331574 - 30/03/2010 15:39 Re: PowerShell [Re: drakino]
canuckInOR
carpal tunnel

Registered: 13/02/2002
Posts: 3212
Loc: Portland, OR
If you're looking for command-parity with Unix commands, why not just install Cygwin?

If you'll pardon the minor thread jack, though, since you bring up Cmd.exe, does anyone know a decent console/shell program on Windows (where decent is defined by one that has tabbed shells, and, preferably, mouse copy-paste semantics akin to Linux?) I've found Console, but it has some... annoying idiosyncrasies.

Top
#331575 - 30/03/2010 15:58 Re: PowerShell [Re: canuckInOR]
drakino
carpal tunnel

Registered: 08/06/1999
Posts: 7868
Cygwin is decent for what it does, but it has a load of quirks to deal with when trying to run Windows processes. I figure since PowerShell is purposely built for Windows that it should fit in better. I don't necessarily need the unixland stuff in windows, just something similar in power.

As for the command parity comment, it was mostly due to my normal process of typing "ls" and other such unix commands everywhere. Including in cmd.exe windows, and getting back the typical "I have no idea what your asking about" response.

Top
#331576 - 30/03/2010 17:24 Re: PowerShell [Re: canuckInOR]
wfaulk
carpal tunnel

Registered: 25/12/2000
Posts: 16706
Loc: Raleigh, NC US
The only other one I recall is ColorConsole.
_________________________
Bitt Faulk

Top
#331602 - 31/03/2010 15:55 Re: PowerShell [Re: wfaulk]
canuckInOR
carpal tunnel

Registered: 13/02/2002
Posts: 3212
Loc: Portland, OR
Urk. Looks pretty, but bad usability. Thanks for the suggestion, though -- I hadn't seen that one. I found Terminator last night, which makes me happy. It doesn't have the key bindings I'd prefer, but hooray for open source!

Top
#331603 - 31/03/2010 15:58 Re: PowerShell [Re: drakino]
canuckInOR
carpal tunnel

Registered: 13/02/2002
Posts: 3212
Loc: Portland, OR
Quote:
I don't necessarily need the unixland stuff in windows, just something similar in power.
Ah, I see. PowerShell does look pretty nifty from that point of view.

Top
#332081 - 14/04/2010 13:52 Re: PowerShell [Re: canuckInOR]
drakino
carpal tunnel

Registered: 08/06/1999
Posts: 7868
Random tidbit I figured I'd toss in here. Security under Powershell is, well, very locked down by default due to concerns over normal users being e-mailed a script and running it.

The big thing for me was just getting .ps1 scripts to run both locally and remotely. By default, they won't, and most sites talk about using "SetExecutionPolicy RemoteSigned" to be able to run local unsigned scripts. However, that only covers the surface, and the security applies to 5 different scopes. Running the scripts remotely is a bit different. What finally helped is looking at "Get-ExecutionPolicy -list", as it shows the 5 different scopes and each security level. Ultimately for development I've ended up changing 3 of the 5 scopes to just full bypass mode.

Top
#332082 - 14/04/2010 14:14 Re: PowerShell [Re: drakino]
Roger
carpal tunnel

Registered: 18/01/2000
Posts: 5682
Loc: London, UK
Unless you want to mess about with generating a development/test CA and signing your scripts, that's about the only way to do it, to be honest.
_________________________
-- roger

Top
#332084 - 14/04/2010 14:27 Re: PowerShell [Re: Roger]
drakino
carpal tunnel

Registered: 08/06/1999
Posts: 7868
Good to know. I'll look deeper into signing scripts down the road for production systems, since those machines will be more exposed. For now, I'm just working with local build boxes that are already on a secured network.

Top
#332977 - 14/05/2010 19:39 Re: PowerShell [Re: drakino]
drakino
carpal tunnel

Registered: 08/06/1999
Posts: 7868
For my future reference

http://devcentral.f5.com/weblogs/Joe/archive/2009/01/13/powershell-abcs---p-is-for-parameters.aspx

params is quite handy for allowing scripts to use -flags instead of absolute positioning of command line arguments. Similar to OptionParser in python.

Top
#366467 - 06/04/2016 17:06 Re: PowerShell [Re: drakino]
drakino
carpal tunnel

Registered: 08/06/1999
Posts: 7868
Necro posting to add some additional useful links. Making a new attempt to adopt Powershell when working on Windows. When I first made this, I successfully transformed the Vigil Build system to use Powershell scripts, however I didn't put much effort into also transitioning my personal usage of a command prompt on Windows. I'm now working to get more comfortable in the command prompt side, especially with the nice improvements to the built in console app of the upcoming Windows 10 Anniversary Update.

Powershell offers various levels of profile scripts much like shells on the Unix side. System level for all users, user specific, and invocation specific. A good summary, and what variables to reference for them is here: https://technet.microsoft.com/en-us/libr...ror=-2147217396

Visual Studio when installed creates shortcuts to it's own CMD prompts that add a number of tools to the path. However as of the 2015 version, it doesn't create shortcuts to Powershell equivalents. This Stack Overflow link has something to add to the Powershell profile that can handle Visual Studio 2010-2015 versions: http://stackoverflow.com/questions/21247...-prompt#2124759

I'm also working to retrain myself on Powershell specific ways to check certain things. One is checking the path, or appending to it.
Display the path:
Code:
$env:path
$env:path -split ";"

Appending to the path:
Code:
$env:Path += ";C:\SomePath\Directory"

Top
#366469 - 07/04/2016 21:31 Re: PowerShell [Re: drakino]
drakino
carpal tunnel

Registered: 08/06/1999
Posts: 7868
Preserving past command history across sessions can be useful. There are some newer ways to do this under Powershell 3 and external scripts that also restore the ability to use the up arrow to cycle through past commands.

As the first step for my setup, I'm only concentrating on preserving history and getting it working with Powershell 2. If anyone else has experience with the more advanced methods that work with 3 or above, feel free to share it here.

I've added the following into my profile script (from an MS MVP on StackOverflow):
Code:
#Register an exit event to save history
Register-EngineEvent PowerShell.Exiting {
    Get-History -Count 32767 | Group CommandLine | 
    Foreach {$_.Group[0]} | Export-CliXml "$home\pshist.xml" } -SupportEvent

#And restore history from that file 
Import-CliXml "$home\pshist.xml" | Add-History

Top