diff --git a/.github/workflows/docs-workflow.yml b/.github/workflows/docs-workflow.yml new file mode 100644 index 0000000..84d08d3 --- /dev/null +++ b/.github/workflows/docs-workflow.yml @@ -0,0 +1,163 @@ +name: PowerShell Documentation + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + schedule: + - cron: '0 0 * * 5' # Weekly run on Friday at midnight + +jobs: + validate: + name: Validate PowerShell Scripts + runs-on: windows-latest + + steps: + - uses: actions/checkout@v3 + + - name: Install PSScriptAnalyzer + shell: pwsh + run: | + Set-PSRepository PSGallery -InstallationPolicy Trusted + Install-Module -Name PSScriptAnalyzer -Force + + - name: Lint with PSScriptAnalyzer + shell: pwsh + run: | + $results = Invoke-ScriptAnalyzer -Path ./commands -Recurse -Settings PSGallery + $results | Format-Table -AutoSize + if ($results) { + Write-Warning "PSScriptAnalyzer found issues. Please review them." + $results | Format-Table -AutoSize + } + + - name: Check PowerShell syntax + shell: pwsh + run: | + $files = Get-ChildItem -Path ./commands -Include *.ps1,*.psm1 -Recurse + foreach ($file in $files) { + $syntaxErrors = $null + $null = [System.Management.Automation.PSParser]::Tokenize((Get-Content -Path $file.FullName -Raw), [ref]$syntaxErrors) + if ($syntaxErrors.Count -gt 0) { + Write-Error "Syntax errors in $($file.FullName)" + $syntaxErrors | Format-Table -AutoSize + exit 1 + } + } + + build-docs: + name: Build Documentation + runs-on: ubuntu-latest + needs: validate + + steps: + - uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.10' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install mkdocs mkdocs-material pymdown-extensions + + - name: Generate command documentation + shell: bash + run: | + mkdir -p docs/commands + for file in commands/*.ps1; do + filename=$(basename "$file" .ps1) + echo "# $filename Commands" > "docs/commands/${filename}.md" + echo '```powershell' >> "docs/commands/${filename}.md" + cat "$file" >> "docs/commands/${filename}.md" + echo '```' >> "docs/commands/${filename}.md" + done + + - name: Build documentation + run: | + mkdocs build + + - name: Deploy to GitHub Pages + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./site + + update-readme: + name: Update README with Command Count + runs-on: ubuntu-latest + needs: validate + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + + steps: + - uses: actions/checkout@v3 + + - name: Count commands + id: count + shell: bash + run: | + TOTAL_COUNT=$(grep -r "function " ./commands | wc -l) + echo "TOTAL_COUNT=$TOTAL_COUNT" >> $GITHUB_ENV + + AD_COUNT=$(grep -r "function " ./commands/active-directory.ps1 2>/dev/null | wc -l || echo "0") + echo "AD_COUNT=$AD_COUNT" >> $GITHUB_ENV + + AZURE_COUNT=$(grep -r "function " ./commands/azure-m365.ps1 2>/dev/null | wc -l || echo "0") + echo "AZURE_COUNT=$AZURE_COUNT" >> $GITHUB_ENV + + SECURITY_COUNT=$(grep -r "function " ./commands/security.ps1 2>/dev/null | wc -l || echo "0") + echo "SECURITY_COUNT=$SECURITY_COUNT" >> $GITHUB_ENV + + - name: Update README + uses: actions/github-script@v6 + with: + script: | + const fs = require('fs'); + const readme = fs.readFileSync('README.md', 'utf8'); + + // Update command count in the description + let updatedReadme = readme.replace( + /📘 Curated PowerShell command library for IT professionals - \d+\+ ready-to-use commands/, + `📘 Curated PowerShell command library for IT professionals - ${process.env.TOTAL_COUNT}+ ready-to-use commands` + ); + + // Add command count by category if not present + if (!updatedReadme.includes('## Command Count')) { + updatedReadme += `\n\n## Command Count\n\n`; + updatedReadme += `- **Total Commands**: ${process.env.TOTAL_COUNT}\n`; + updatedReadme += `- **Active Directory**: ${process.env.AD_COUNT}\n`; + updatedReadme += `- **Azure & Microsoft 365**: ${process.env.AZURE_COUNT}\n`; + updatedReadme += `- **Security**: ${process.env.SECURITY_COUNT}\n`; + } else { + // Update existing command count section + updatedReadme = updatedReadme.replace( + /- \*\*Total Commands\*\*: \d+/, + `- **Total Commands**: ${process.env.TOTAL_COUNT}` + ); + updatedReadme = updatedReadme.replace( + /- \*\*Active Directory\*\*: \d+/, + `- **Active Directory**: ${process.env.AD_COUNT}` + ); + updatedReadme = updatedReadme.replace( + /- \*\*Azure & Microsoft 365\*\*: \d+/, + `- **Azure & Microsoft 365**: ${process.env.AZURE_COUNT}` + ); + updatedReadme = updatedReadme.replace( + /- \*\*Security\*\*: \d+/, + `- **Security**: ${process.env.SECURITY_COUNT}` + ); + } + + fs.writeFileSync('README.md', updatedReadme); + + - name: Commit and push if changed + run: | + git config --global user.name 'GitHub Actions' + git config --global user.email 'actions@github.com' + git add README.md + git diff --quiet && git diff --staged --quiet || git commit -m "Update command count in README [skip ci]" + git push \ No newline at end of file diff --git a/README.md b/README.md index 97c2cc7..2c5c69c 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,187 @@ -# PowerShell Command Reference +# PowerShell Command Reference Library -This repository serves as a curated reference of PowerShell commands categorized by use case. It is designed for quick lookup and practical usage, especially for IT administrators and engineers. + + + -## Categories -- Active Directory -- Azure and Microsoft 365 -- File System and Disk Management -- Networking and Firewall -- Scheduled Tasks and Automation -- Security and Permissions +> 📘 Curated PowerShell command library for IT professionals - 100+ ready-to-use commands for AD, Azure, security, and automation tasks -## Usage -Each `.ps1` file includes a set of command snippets grouped by category. You can copy/paste them into your PowerShell terminal or integrate them into scripts as needed. +## 🚀 Overview -## Contributing -Pull requests are welcome. Please group related commands under the appropriate `.ps1` file or request a new category if needed. +This repository provides a comprehensive collection of PowerShell commands and scripts organized by category for IT professionals, system administrators, and cloud engineers. Each command includes detailed explanations, usage examples, and best practices. -## License -MIT License. See `LICENSE` for details. +## 📋 Categories -## Author -Jaquan Watson -[Portfolio](https://jaquanwatson.github.io) | [GitHub](https://github.com/jaquanwatson) +
| 🔹 Active Directory | +User management, group policies, domain operations, security groups | +
| ☁️ Azure & Microsoft 365 | +Resource management, tenant administration, Exchange Online, SharePoint | +
| 💾 File System & Storage | +File operations, disk management, permissions, backup/restore | +
| 🌐 Networking | +DNS, DHCP, firewall configuration, connectivity testing | +
| 🔒 Security & Compliance | +Auditing, permissions, encryption, compliance reporting | +
| ⚙️ Automation | +Scheduled tasks, workflows, event triggers, reporting | +