Skip to content

Commit 16ce762

Browse files
committed
RFC for PowerShell Core Interop Module
1 parent 374e7a4 commit 16ce762

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
2+
3+
RFC: RFC<four digit unique incrementing number - assigned by Committee>
4+
Author: Darwin Sanoy
5+
Status: Draft
6+
SupercededBy:
7+
Version: 0.1
8+
Area: Standard Modules
9+
Comments Due: 5/1/2017
10+
---
11+
12+
# Interop Module Which Emulates Windows On PowerShell Core On Non-Windows
13+
14+
I have written one script for configuring security for AWS which runs, without modification, on Linux or Windows.
15+
16+
I have written serveral debugging scripts which also run, unmodified, on Linux or Windows. [Code is Here] (https://github.com/DarwinJS/DebugDeepPSHExecution)
17+
18+
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.
19+
20+
I know that some will think that this support should be bi-directional - but I personally feel that the adoption of PowerShell on Linux will most likely be
21+
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
22+
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
23+
was as Linux does not rely on as many environment variables to point to platform-wide standard paths. (e.g. /tmp folder) However, if it should be addressed up front, it
24+
would seem to make sense if this module had a neutral name and did fix ups in both directions.
25+
26+
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
27+
to "windowize" the Linux platform and would be confusing for Linux professionals and organizations who might adopt PowerShell to manage pure Linux environments.
28+
29+
## Motivation
30+
31+
As an administrator who wishes to start managing Linux with PowerShell,
32+
I can port Windows scripts, snippets and modules that contain popular Windows references (usually environment variables) to Linux without changing every reference
33+
so that I can save work by reuse as much of my Windows PowerShell code as possible, and where desirable, create scripts that run on both Windows and Linux unmodified.
34+
35+
## Specification
36+
37+
- Standard shipped-with PowerShell Core module
38+
- Written as a script
39+
- That "fixes up" a Linux environment
40+
- with common Windows standard pointers
41+
- or code samples for common things that need to be done
42+
- including code samples of methods that simply work on both platforms unchanged
43+
- that requires some action from an administrator to enable (e.g. run a CMDLet in their script or a machine based profile)
44+
45+
###example
46+
Only tested on CentOS - so may need improvement for other distros
47+
48+
`
49+
$RunningOnWindows = $true
50+
If ((Test-Path variable:IsWindows) -AND !$IsWindows)
51+
{
52+
write-output 'Running on PowerShell Core, exposing runtime information'
53+
If ((!(Test-Path env:temp)) -AND (Test-Path '/tmp'))
54+
{ $env:temp = '/tmp' }
55+
If ($(hostname) -ilike '*.*')
56+
{ $env:computername = ($env:computername).split('.')[0] }
57+
Else
58+
{ $env:computername = hostname }
59+
60+
If ((uname -a) -ilike '*_64*')
61+
{ $OSBitness = 64 }
62+
63+
$RunningOnWindows = $false
64+
}
65+
66+
#Demonstrates *specific method* that works on both Windows and Linux for Process Bitness
67+
$PROCBitness = 32 #Default
68+
If ([System.IntPtr]::Size -eq 8)
69+
{
70+
$PROCBitness = 64
71+
}
72+
`
73+
## Alternate Proposals and Considerations
74+
75+
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)