Skip to content

Commit a4f6de0

Browse files
committed
Initial commit: PowerShell Dev Toolkit
0 parents  commit a4f6de0

27 files changed

+5992
-0
lines changed

.gitignore

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Credential files
2+
creds/
3+
*.cred.xml
4+
*-cred.xml
5+
6+
# Configuration (contains user-specific settings)
7+
config.json
8+
9+
# Environment files
10+
.env
11+
.env.local
12+
.env.*.local
13+
*.env
14+
15+
# Secrets and passwords
16+
secrets/
17+
*.secret
18+
*.key
19+
*.pem
20+
*.p12
21+
*.pfx
22+
23+
# PowerShell credential exports
24+
*.clixml
25+
26+
# Profile backups
27+
*PROFILE_BACKUP*
28+
29+
# OS files
30+
.DS_Store
31+
Thumbs.db
32+
33+
# Editor files
34+
.vscode/
35+
.idea/
36+
*.swp
37+
*.swo
38+
*~

CONTRIBUTING.md

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
# Contributing to PowerShell Dev Toolkit
2+
3+
First off, thank you for considering contributing to PowerShell Dev Toolkit! 🎉
4+
5+
## How Can I Contribute?
6+
7+
### Reporting Bugs
8+
9+
Before creating bug reports, please check the existing issues to avoid duplicates. When you create a bug report, include as many details as possible:
10+
11+
- **Use a clear and descriptive title**
12+
- **Describe the exact steps to reproduce the problem**
13+
- **Provide specific examples**
14+
- **Describe the behavior you observed and what you expected**
15+
- **Include PowerShell version** (`$PSVersionTable.PSVersion`)
16+
- **Include Windows version**
17+
- **Include relevant logs or error messages**
18+
19+
### Suggesting Enhancements
20+
21+
Enhancement suggestions are tracked as GitHub issues. When creating an enhancement suggestion, include:
22+
23+
- **Use a clear and descriptive title**
24+
- **Provide a step-by-step description of the suggested enhancement**
25+
- **Provide specific examples to demonstrate the steps**
26+
- **Describe the current behavior and explain which behavior you expected to see**
27+
- **Explain why this enhancement would be useful**
28+
29+
### Pull Requests
30+
31+
1. **Fork the repository**
32+
2. **Create a new branch** from `main`:
33+
```powershell
34+
git checkout -b feature/your-feature-name
35+
```
36+
3. **Make your changes**:
37+
- Follow the existing code style
38+
- Add comments for complex logic
39+
- Update documentation if needed
40+
4. **Test your changes**:
41+
- Test on a clean Windows machine if possible
42+
- Ensure backward compatibility
43+
5. **Commit your changes**:
44+
```powershell
45+
git commit -m "Add feature: your feature description"
46+
```
47+
6. **Push to your fork**:
48+
```powershell
49+
git push origin feature/your-feature-name
50+
```
51+
7. **Open a Pull Request** with a clear title and description
52+
53+
## Coding Standards
54+
55+
### PowerShell Script Guidelines
56+
57+
1. **Use meaningful variable names**
58+
```powershell
59+
# Good
60+
$serverHostname = "example.com"
61+
62+
# Bad
63+
$s = "example.com"
64+
```
65+
66+
2. **Include comment-based help** for all scripts
67+
```powershell
68+
<#
69+
.SYNOPSIS
70+
Brief description
71+
72+
.DESCRIPTION
73+
Detailed description
74+
75+
.PARAMETER Name
76+
Parameter description
77+
78+
.EXAMPLE
79+
script.ps1 -Name "test"
80+
#>
81+
```
82+
83+
3. **Use approved verbs** for function names
84+
- Get-, Set-, New-, Remove-, Add-, etc.
85+
- Check: `Get-Verb`
86+
87+
4. **Handle errors gracefully**
88+
```powershell
89+
try {
90+
# Your code
91+
} catch {
92+
Write-Host "Error: $($_.Exception.Message)" -ForegroundColor Red
93+
exit 1
94+
}
95+
```
96+
97+
5. **Support common parameters** when appropriate
98+
```powershell
99+
[CmdletBinding()]
100+
param(
101+
[Parameter(Mandatory=$true)]
102+
[string]$Name
103+
)
104+
```
105+
106+
6. **Provide meaningful output**
107+
- Use colored output for better UX
108+
- Support `-AsJson` for programmatic use where appropriate
109+
- Show progress for long-running operations
110+
111+
### Configuration
112+
113+
- **Never hardcode user-specific information**
114+
- **Use `config.json` for user settings**
115+
- **Provide sensible defaults**
116+
- **Document all configuration options** in `config.example.json`
117+
118+
### Security
119+
120+
- **Never commit credentials** or sensitive data
121+
- **Use encrypted credential storage** (Export-Clixml)
122+
- **Always validate user input**
123+
- **Use secure connections** (SSH, HTTPS)
124+
125+
## Documentation
126+
127+
- Update `README.md` if you add new features
128+
- Add examples to help text
129+
- Document configuration options
130+
- Update `helpme.ps1` for new commands
131+
132+
## Testing
133+
134+
While we don't have automated tests yet, please:
135+
136+
1. **Test your changes manually** on Windows 10 and 11
137+
2. **Test with PowerShell 5.1 and 7+**
138+
3. **Test without WSL** (fallback scenarios)
139+
4. **Test with missing dependencies** (graceful degradation)
140+
141+
## Project Structure
142+
143+
```
144+
powershell-dev-toolkit/
145+
├── README.md # Main documentation
146+
├── config.example.json # Configuration template
147+
├── Setup-Environment.ps1 # Setup script
148+
├── Get-ScriptConfig.ps1 # Config loader
149+
├── Connect-SSH.ps1 # SSH scripts
150+
├── Connect-SSHTunnel.ps1
151+
├── Get-*.ps1 # Get/retrieve commands
152+
├── Invoke-*.ps1 # Action commands
153+
├── Start-*.ps1 # Start/launch commands
154+
├── Watch-*.ps1 # Monitor commands
155+
├── New-*.ps1 # Create/generate commands
156+
└── creds/ # Credentials (gitignored)
157+
```
158+
159+
## Commit Messages
160+
161+
Use clear and meaningful commit messages:
162+
163+
- **feat**: New feature
164+
- **fix**: Bug fix
165+
- **docs**: Documentation changes
166+
- **style**: Code style changes (formatting)
167+
- **refactor**: Code refactoring
168+
- **test**: Adding tests
169+
- **chore**: Maintenance tasks
170+
171+
Examples:
172+
```
173+
feat: add support for SQLServer tunneling
174+
fix: resolve credential loading on PowerShell 7
175+
docs: update SSH setup instructions
176+
refactor: simplify server configuration logic
177+
```
178+
179+
## Questions?
180+
181+
Feel free to open an issue with the `question` label if you need clarification on anything.
182+
183+
## Code of Conduct
184+
185+
Be respectful and constructive. We're all here to learn and help each other.
186+
187+
---
188+
189+
Thank you for contributing! 🚀

Connect-SSH.ps1

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
param(
2+
[Parameter(Mandatory = $true, Position = 0)]
3+
[string]$Target
4+
)
5+
6+
# Load config
7+
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
8+
. "$scriptDir\Get-ScriptConfig.ps1"
9+
$config = Get-ScriptConfig
10+
11+
if (-not $config) {
12+
Write-Host "Please configure config.json before using SSH commands." -ForegroundColor Red
13+
exit 1
14+
}
15+
16+
# Get servers from config
17+
$servers = @{}
18+
if ($config.ssh.servers) {
19+
foreach ($key in $config.ssh.servers.PSObject.Properties.Name) {
20+
$servers[$key] = $config.ssh.servers.$key.hostname
21+
}
22+
}
23+
24+
# Resolve hostname
25+
if ($servers.ContainsKey($Target)) {
26+
$Server = $servers[$Target]
27+
} else {
28+
$Server = $Target
29+
}
30+
31+
# Try Posh-SSH first if WSL not available
32+
$useWSL = $true
33+
$wsl = Get-Command wsl -ErrorAction SilentlyContinue
34+
if (-not $wsl) {
35+
$useWSL = $false
36+
# Use Posh-SSH
37+
try {
38+
Import-Module Posh-SSH -ErrorAction Stop
39+
} catch {
40+
Write-Host "Neither WSL nor Posh-SSH is available." -ForegroundColor Red
41+
Write-Host "Install WSL: wsl --install" -ForegroundColor Yellow
42+
Write-Host "Or install Posh-SSH: Install-Module -Name Posh-SSH" -ForegroundColor Yellow
43+
exit 1
44+
}
45+
}
46+
47+
# Get credentials
48+
$credsDir = Join-Path $scriptDir "creds"
49+
$credFile = $config.ssh.credentialFile
50+
if (-not $credFile) {
51+
$credFile = "ssh-credentials.xml"
52+
}
53+
$credPath = Join-Path $credsDir $credFile
54+
55+
if (-not (Test-Path $credPath)) {
56+
Write-Host ""
57+
Write-Host "Credential file not found!" -ForegroundColor Yellow
58+
Write-Host ""
59+
Write-Host "To set up SSH credentials:" -ForegroundColor Cyan
60+
Write-Host " 1. Create credentials directory if needed:" -ForegroundColor White
61+
Write-Host " New-Item -Path '$credsDir' -ItemType Directory -Force" -ForegroundColor Gray
62+
Write-Host ""
63+
Write-Host " 2. Store your credentials:" -ForegroundColor White
64+
Write-Host " `$cred = Get-Credential -UserName 'your-ssh-username'" -ForegroundColor Gray
65+
Write-Host " `$cred | Export-Clixml '$credPath'" -ForegroundColor Gray
66+
Write-Host ""
67+
exit 1
68+
}
69+
70+
$cred = Import-Clixml $credPath
71+
$username = $cred.UserName
72+
$password = $cred.GetNetworkCredential().Password
73+
74+
# Use WSL with sshpass for proper terminal handling
75+
if ($useWSL) {
76+
# Check if sshpass is installed
77+
$hasSshpass = wsl bash -c "command -v sshpass >/dev/null 2>&1 && echo 'yes' || echo 'no'"
78+
if ($hasSshpass -match 'no') {
79+
Write-Host "Installing sshpass in WSL (one-time setup)..." -ForegroundColor Yellow
80+
wsl bash -c "sudo apt-get update && sudo apt-get install -y sshpass"
81+
}
82+
83+
# Connect using sshpass through WSL (proper terminal handling)
84+
wsl bash -c "SSHPASS='$password' sshpass -e ssh -o StrictHostKeyChecking=no $username@$Server"
85+
} else {
86+
# Fallback to Posh-SSH
87+
Write-Host "Connecting to $Server as $username..." -ForegroundColor Cyan
88+
try {
89+
$session = New-SSHSession -ComputerName $Server -Credential $cred -AcceptKey
90+
Invoke-SSHCommand -SessionId $session.SessionId -Command "bash -l" -TimeOut 3600
91+
Remove-SSHSession -SessionId $session.SessionId | Out-Null
92+
} catch {
93+
Write-Host "Connection failed: $($_.Exception.Message)" -ForegroundColor Red
94+
exit 1
95+
}
96+
}

0 commit comments

Comments
 (0)