Skip to content

Commit 9ab5c66

Browse files
authored
Merge pull request #66 from DarwinJS/master
Interop Module(s) Which Patch(es) a PowerShell Runspace to Match The "Developed On" Platform of the PowerShell Code
2 parents 9df1e22 + 4e97731 commit 9ab5c66

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
2+
RFC: RFC<four digit unique incrementing number - assigned by Committee>
3+
4+
Author: Darwin Sanoy
5+
6+
Status: Draft
7+
8+
SupercededBy:
9+
10+
Version: 0.1
11+
12+
Area: Standard Modules
13+
14+
Comments Due: 5/1/2017
15+
---
16+
17+
# Interop Module(s) Which Patch(es) a PowerShell Runspace to Match The "Developed On" Platform of the PowerShell Code
18+
19+
I have written one script for configuring security for AWS which runs, without modification, on Linux or Windows.
20+
21+
I have written serveral debugging scripts which also run, unmodified, on Linux or Windows. [Code is Here] (https://github.com/DarwinJS/DebugDeepPSHExecution)
22+
23+
I have learned serveral fixups that go a long way to making things work without changing the code. For example, creating $env:temp and pointing it to /tmp on Linux.
24+
25+
I personally feel that the adoption of PowerShell on Linux will most likely be
26+
driven by those who know PowerShell well on Windows and want to use it to manage Linux. I think it will be quite a while before there is much traction to
27+
go the other direction (start learning PowerShell on Linux, get proficient, start using it to manage Windows). It is also a little more challenging to go the other
28+
was as Linux does not rely on as many environment variables to point to platform-wide standard paths. (e.g. /tmp folder)
29+
30+
31+
I have addressed the issue as bi-directional in this RFC, but would be quick to back off to Dev on Windows => Run on Linux if the other way seems not worth the effort.
32+
If both directions were desirable upfront, it would seem to make sense if this module had a neutral name and did fix ups in both directions -
33+
unless that would make the code too complex - then perhaps a module per "interop direction".
34+
35+
I also want to full acknowledge that this type of support is not appropriate to compile right into the PowerShell code itself - as it would seem to then be attempting
36+
to "windowize" the Linux platform and would be confusing for Linux professionals and organizations who might adopt PowerShell to manage pure Linux environments.
37+
38+
## Motivation
39+
40+
As an administrator who wishes to start managing Linux with PowerShell,
41+
(or vice versa) I can port scripts, snippets and modules that that contain
42+
popular references on my initial development platform (eg environment variables)
43+
to the other platform without changing every reference, so that I can save work
44+
by reusing as much of my "Developed On" platform PowerShell code as possible, and
45+
where desirable, create scripts that run on both Windows and Linux unmodified.
46+
47+
## Specification
48+
49+
- Standard shipped-with PowerShell Core module
50+
- Written as a script
51+
- That "fixes up" a target environment
52+
- dynamically (does not make persistent changes)
53+
- within the PowerShell session (does not dynamically change things beyond the current session)
54+
- with common standard pointers for the "Developed on" platform
55+
- or code samples for common things that need to be done from the "developed on" platform
56+
- using existing reference technology common to both platforms and available in PowerShell (e.g. Environment Variables & PowerShell Variables)
57+
- and includes code samples of methods that simply work on both platforms unchanged (e.g. A way to check bitness that works unmodified on both platforms - even though there is not a PowerShell standard for exposing this information)
58+
- that can work under all Windows PowerShell editions (not just Core - even if only distributed with Core)
59+
- that requires some action from an administrator to enable (e.g. run a CMDLet in their script or a machine based PowerShell profile)
60+
61+
###Example
62+
63+
~~~~PowerShell
64+
#Code that adapts Windows PowerShell to Linux
65+
#NOTE: Only tested on CentOS - so may need improvement for other distros
66+
$RunningOnWindows = $true
67+
If ((Test-Path variable:IsWindows) -AND !$IsWindows)
68+
{
69+
write-output 'Running on PowerShell Core, exposing runtime information'
70+
If ((!(Test-Path env:temp)) -AND (Test-Path '/tmp'))
71+
{ $env:temp = '/tmp' }
72+
If ($(hostname) -ilike '*.*')
73+
{ $env:computername = ($env:computername).split('.')[0] }
74+
Else
75+
{ $env:computername = hostname }
76+
77+
If ((uname -a) -ilike '*_64*')
78+
{ $OSBitness = 64 }
79+
80+
$RunningOnWindows = $false
81+
}
82+
83+
#Demonstrates *specific method* that works on both Windows and Linux for Process Bitness
84+
$PROCBitness = 32 #Default
85+
If ([System.IntPtr]::Size -eq 8)
86+
{
87+
$PROCBitness = 64
88+
}
89+
~~~~
90+
91+
## Alternate Proposals and Considerations
92+
93+
Alternatively any individual who has the need for such functionality will generally pursue it on their own, resulting in many custom solutions and lacking the value of community collaboration.

0 commit comments

Comments
 (0)