我有一些我认为很酷的想法,但我不知道如何让它全部发挥作用......所以,我会问......
我有一个问题,他们都很相似,所以我觉得他们可能都有相同的答案,但我不确定。
我试过使用 TypeDefinitions 、 Add-Type 、 New-Object 等,但这些都不起作用。我一直在搞乱所涉及的数学......尽管我尽了最大的努力?仍然没有弄清楚如何让它工作。我问过其他程序员,但他们可能都对我要完成的事情有错误的想法。所以这里...
# Being able to call system objects, or system type objects from an array of common strings ( lets call each one it's own 'lego' ). #
# Instead of ... #
if ([ Security.Principal.WindowsPrincipal ][ Security.Principal.WindowsIdentity ]::GetCurrent()).IsInRole([ Security.Principal.WindowsBuiltInRole ]'Administrator')
{ execute the script... }
# You could do this...
$0 = "." , "Windows" , "Security" , "Principal" , "Identity" , "BuiltInRole"
$1 = -join $0[ 2 , 0 , 3 , 0 , 1 ]
$2 = $0[ 3..5 ] | % { New-Object $1 + $_ }
if (-join $2[0..1]::GetCurrent()).IsInRole($2[2])
{ execute script }
# Haven't gotten it working yet though, can't really call methods or types from a string as far as I know, but I know that SID strings are essentially calling types from a numerical index hence "S-1-5-21-...etc"
```
# Calling assemblies or assembly types from an array of strings (in the same manner as above for loading ASP.Net Assemblies - which are also system objects
# Example of how they're loaded now....
using System ;
using System.Collections.Generic ;
using System.Diagnostics ;
using System.Linq ;
using System.Threading.Tasks ;
using Microsoft.AspNetCore.Mvc ;
using securedigitsplus.Models ;
# and how I'd like to load them in PowerShell and not even need the .cs files
$0 = "System" , ".Collections.Generic" , ".Diagnostics" , ".Linq" , ".Threading.Tasks" , "#etc.....#"
$1 = $0[0] , @( foreach ( $j in 1..4 ) | % { -join $0[0,$j] } )
0..$1.count | % { using ( New-Object or Add-Type -TypeDeclaration $_ I've tried both with no success... }
```
我希望我已经对我正在尝试做的事情给出了足够好的解释或示例。一般的想法是我希望能够在某个时候在循环中创建 CmdLetBinding() ,特别是如果有一堆类似的并且 DefaultParameterSetName 似乎不是一个好的解决方案,但我'我现在只想用简单的功能/开关来做到这一点。
如果有人认为“你想在这里重新发明轮子”......我想这有一些优点......但我的看法是,“没有什么是完美的,即使是其他人使用的轮子也不行......你有一个想要成长的想法。请问可以帮助实现这一目标的人。”
侃侃尔雅
相关分类