据我所知,PowerShell似乎没有所谓的三元运算符的内置表达式.
例如,在支持三元运算符的C语言中,我可以编写如下内容:
<condition> ? <condition-is-true> : <condition-is-false>;
Run Code Online (Sandbox Code Playgroud)
如果在PowerShell中确实不存在,那么实现相同结果的最佳方法(即易于阅读和维护)是什么?
在Python中编写Web应用程序时,运行开发服务器很容易.Django和Google App Engine(GAE)都附带简单的服务器.
我正在寻找的主要功能是没有配置.我想要一些像GAE dev服务器,你只需要在服务器启动时将应用程序目录作为参数传递.
有没有理由认为这对PHP来说更难?
我一直在使用TFS中的持续集成(CI)构建.但是,在我上一个项目中,我们开始使用门控签入触发器.
使用门禁办理登机手续有什么不利之处吗?因为如果它阻止团队检查损坏的代码,那么CI触发器的目的是什么?
从PowerShell获取注册表项中的值的方法是:
Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion CommonFilesDir
Run Code Online (Sandbox Code Playgroud)
但是,该命令返回一些我通常不想要的额外属性:
CommonFilesDir : C:\Program Files\Common Files
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
PSChildName : CurrentVersion
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.Core\Registry
Run Code Online (Sandbox Code Playgroud)
我只想要实际值,在这种情况下是一个字符串.要做到这一点,我必须使用更详细:
$commonFilesDir = (Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion CommonFilesDir).CommonFilesDir
Run Code Online (Sandbox Code Playgroud)
除了编写我自己的别名之外,有没有办法不写两次属性名并获取字符串?
我可以运行以下命令,但它返回一个PSObject:
Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion | Select CommonFilesDir
Run Code Online (Sandbox Code Playgroud) 我已经尽可能地简化了我的情况。我有一个 PowerShell 脚本,它使用Start-Process cmdlet通过“以管理员身份运行”选项以编程方式启动进程:
param
(
# Arguments to pass to the process, if any
[string[]] $ArgList
)
if($ArgList)
{
Start-Process -FilePath notepad.exe -ArgumentList $ArgList -Verb RunAs
}
else
{
Start-Process -FilePath notepad.exe -Verb RunAs
}
Run Code Online (Sandbox Code Playgroud)
由于ArgumentList不能为 NULL 或为空,我不得不添加if-else以避免ParameterArgumentValidationError错误。
一切都按预期工作没有问题,但我只是想知道是否有更优雅(但仍然简单)的方法来完成它而不使用if-else块。