Powershell: رش الممتلكات

تم إنشاؤها على ٢٥ أكتوبر ٢٠١٧  ·  3تعليقات  ·  مصدر: PowerShell/PowerShell

ملخص

سيكون من المفيد لو تمكنا من استخدام خاصية المتغير (أي حيث تكون هذه الخاصية في حد ذاتها قابلة للتجزئة) إلى أمر ما.

مثال رمز:

function Test-Demo {
    [CmdletBinding()]
    Param (
        [Parameter()]
        [string]$One
        ,
        [Parameter()]
        [string]$Two
    )
    "1 = $One"
    "2 = $Two"
}
$test = @{
    testInt = @{ 
        One = '1'
        Two = '2'
    }
    testString = @{
        One = 'One'
        Two = 'Two'
    }
}

#to splat a property, we first need to assign the property to a "top level" variable:
$t = $test.testString
Test-Demo <strong i="10">@t</strong> 

#however it would be nice if we could instead do this:
Test-Demo @test.testString 

#or if that's not possible for some reason, maybe something like this:
Test-Demo ([splat]$test.testString)

قد يكون هذا مفيدًا بشكل خاص عند التعامل مع ملفات التكوين. على سبيل المثال ، يحتفظ التكوين الخاص بنا بمعلومات قاعدة البيانات (مثال ، كتالوج ، بيانات اعتماد) ، وكذلك أقسام ذات خصائص أخرى خاصة بوظائفنا. على سبيل المثال

$config = Get-MyScriptConfig -Path '.\Config.xml'
Invoke-Something @config.DatabaseConnectionInfo @config.Something
Issue-Question Resolution-Answered

التعليق الأكثر فائدة

يبدو أننا بحاجة إلى إحياء https://github.com/PowerShell/PowerShell-RFC/issues/6 - تقترح مسودة RFC استخدام تعبير معمم ، مع بناء جملة مثل:

Test-Demo @$test.testString

ال 3 كومينتر

يبدو أننا بحاجة إلى إحياء https://github.com/PowerShell/PowerShell-RFC/issues/6 - تقترح مسودة RFC استخدام تعبير معمم ، مع بناء جملة مثل:

Test-Demo @$test.testString

JohnLBevan هل يمكننا إغلاق المشكلة بالبحث https://github.com/PowerShell/PowerShell-RFC/issues/6 ؟

iSazonov . نعم ، سعيد لإغلاق هذا نظرًا لأنه مغطى بالفعل هناك. شكرا لك.

هل كانت هذه الصفحة مفيدة؟
0 / 5 - 0 التقييمات