Skillpedia
برمجة عامة48k · #5482

powershell-windows

ما الذي تفعله

يعلّمك هذا الدليل كيفية كتابة سكربتات PowerShell على Windows بشكل صحيح وآمن. يوضح القواعد المهمة لتجنب الأخطاء الشائعة، مثل الاستخدام الصحيح للأقواس، وتجنب الرموز الخاصة، والتحقق من وجود شيء قبل استخدامه.

متى تستخدمها

  • ✓عندما تتعلم كتابة سكربتات PowerShell.
  • ✓إذا كانت سكربتاتك تعطي أخطاء غير متوقعة.
  • ✓للتأكد من أن سكربتاتك تعمل بشكل جيد على أجهزة مختلفة.

رابط المهارة

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/powershell-windows/SKILL.md

انسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.

طريقة الاستخدام

أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.

رسالة جاهزة للصق

استخدم هذه المهارة لمساعدتي: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/powershell-windows/SKILL.md اقرأ ملف SKILL.md في هذا الرابط ونفّذ تعليماته لمهمتي.
تريد أن يجد الذكاء الاصطناعي مهارات مثل هذه بنفسه؟ثبّت خادم Skillpedia MCP المجاني: سطر واحد، ويبحث في 15,000+ مهارة قبل كل مهمة.ثبّته في دقيقة واحدة →

مثال على ما تطلبه من الذكاء الاصطناعي

“كيف أستخدم الأقواس بشكل صحيح في سكربت PowerShell مع «or»؟”

5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.

كيف تعمل

يشرح الدليل قواعد PowerShell، مثل الحاجة إلى الأقواس في حالات معينة، وأهمية استخدام الرموز البسيطة، أي ASCII، فقط. كما يوضح كيفية التحقق من أن المتغير يحمل قيمة قبل استخدامه.

المحتوى التقني (ملف SKILL.md الأصلي)

النص الأصلي من المؤلف، مباشرة من GitHub.

PowerShell Windows Patterns

Critical patterns and pitfalls for Windows PowerShell.


1. Operator Syntax Rules

CRITICAL: Parentheses Required

❌ Wrong ✅ Correct
if (Test-Path "a" -or Test-Path "b") if ((Test-Path "a") -or (Test-Path "b"))
if (Get-Item $x -and $y -eq 5) if ((Get-Item $x) -and ($y -eq 5))

Rule: Each cmdlet call MUST be in parentheses when using logical operators.


2. Unicode/Emoji Restriction

CRITICAL: No Unicode in Scripts

Purpose ❌ Don't Use ✅ Use
Success ✅ ✓ [OK] [+]
Error ❌ ✗ 🔴 [!] [X]
Warning ⚠️ 🟡 [*] [WARN]
Info ℹ️ 🔵 [i] [INFO]
Progress ⏳ [...]

Rule: Use ASCII characters only in PowerShell scripts.


3. Null Check Patterns

Always Check Before Access

❌ Wrong ✅ Correct
$array.Count -gt 0 $array -and $array.Count -gt 0
$text.Length if ($text) { $text.Length }

4. String Interpolation

Complex Expressions

❌ Wrong ✅ Correct
"Value: $($obj.prop.sub)" Store in variable first

Pattern:

$value = $obj.prop.sub
Write-Output "Value: $value"

5. Error Handling

ErrorActionPreference

Value Use
Stop Development (fail fast)
Continue Production scripts
SilentlyContinue When errors expected

Try/Catch Pattern

  • Don't return inside try block
  • Use finally for cleanup
  • Return after try/catch

6. File Paths

Windows Path Rules

Pattern Use
Literal path C:\Users\User\file.txt
Variable path Join-Path $env:USERPROFILE "file.txt"
Relative Join-Path $ScriptDir "data"

Rule: Use Join-Path for cross-platform safety.


7. Array Operations

Correct Patterns

Operation Syntax
Empty array $array = @()
Add item $array += $item
ArrayList add `$list.Add($item)

8. JSON Operations

CRITICAL: Depth Parameter

❌ Wrong ✅ Correct
ConvertTo-Json ConvertTo-Json -Depth 10

Rule: Always specify -Depth for nested objects.

File Operations

Operation Pattern
Read `Get-Content "file.json" -Raw
Write `$data

9. Common Errors

Error Message Cause Fix
"parameter 'or'" Missing parentheses Wrap cmdlets in ()
"Unexpected token" Unicode character Use ASCII only
"Cannot find property" Null object Check null first
"Cannot convert" Type mismatch Use .ToString()

10. Script Template

# Strict mode
Set-StrictMode -Version Latest
$ErrorActionPreference = "Continue"

# Paths
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path

# Main
try {
    # Logic here
    Write-Output "[OK] Done"
    exit 0
}
catch {
    Write-Warning "Error: $_"
    exit 1
}

Remember: PowerShell has unique syntax rules. Parentheses, ASCII-only, and null checks are non-negotiable.

When to Use

This skill is applicable to execute the workflow or actions described in the overview.

Limitations

  • Use this skill only when the task clearly matches the scope described above.
  • Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
  • Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
الأسئلة الشائعة

لماذا لا أستطيع استخدام الرموز التعبيرية أو الرموز الخاصة في السكربتات؟

قد يواجه PowerShell صعوبة في فهم الرموز غير الإنجليزية الأساسية. استخدام الرموز الأساسية فقط يضمن عمل السكربت على أي حاسوب دون أخطاء غريبة.

ما هو التحقق من القيمة الفارغة ولماذا هو مهم؟

هو مثل التحقق من أن الصندوق فارغ قبل أن تحاول إخراج شيء منه. إذا حاولت استخدام شيء غير موجود، أي قيمته null، قد ينهار السكربت. التحقق أولاً يمنع هذه الأخطاء.

كيف يتعامل PowerShell مع الأخطاء؟

يمكنك أن تطلب منه التوقف عند حدوث خطأ، أو أن يستمر رغم الأخطاء، أو أن يتجاهل الأخطاء المتوقعة. وهناك أيضاً طريقة لتجربة تنفيذ شيء والتقاط الأخطاء إن وقعت، وهي Try/Catch.

التفاصيل

الوصف الأصلي من المؤلف

PowerShell Windows patterns. Critical pitfalls, operator syntax, error handling.

repo: sickn33/agentic-awesome-skills

الشعبية

نجوم GitHub
48k
الترتيب
#5482
الترخيص
MIT
آخر تحديث
15‏/10‏/2026

هل هذه المهارة مفيدة؟

0

سجّل الدخول للتصويت.

التعليقات

  • …

المزيد من المهارات من هذا المستودع

مهارات مشابهة