小编Tom*_*mek的帖子

比较Powershell中的System.Version

我有一种情况,我必须根据比较版本在脚本中做出决定。请考虑以下示例:

PS C:\>
[version]$SomeVersion='1.1.1'
[version]$OtherVersion='1.1.1.0'

PS C:\> $SomeVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
1      1      1      -1      

PS C:\> $OtherVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
1      1      1      0       

PS C:\>$SomeVersion -ge $OtherVersion
False
Run Code Online (Sandbox Code Playgroud)

比较类型为System.Version的对象时,我想省略修订版,但
我找不到任何明智的方法。
有没有?

注意-我已经尝试做过:

PS C:\> ($scriptversion |select major,minor,build) -gt ($currentVersion|select major,minor,build)

Cannot compare "@{Major=1; Minor=1; Build=1}" to "@{Major=1; Minor=1; 
Build=1}" because the objects are not the same type or the object "@{Major=1; 
Minor=1; Build=1}" does not implement "IComparable".
At …
Run Code Online (Sandbox Code Playgroud)

powershell

3
推荐指数
1
解决办法
6080
查看次数

Register-PsRepository : 在此对象上找不到属性“名称”

尝试运行 Register-PsRepository 时出现以下错误

我试过了:

  • 重新安装 WMF 5、PowerShellGet 和 PackageManagement 模块
  • 更新所述模块
  • 调试 PowerShellGet 模块我可以看到 PsBoundParameters 确实将 Name 值传递给 Register-PackageSource 命令。
  • 当我手动运行 Register-PackageSource 时,它​​确实可以正常工作。

有任何想法吗?

PS C:\> Register-PSRepository -Name MyRepo -SourceLocation  https://MyRepo.com/api/Myrepo   -Credential $c
PackageManagement\Register-PackageSource : The property 'Name' cannot be 
found on this object. Verify that the property exists.
At C:\Program  Files\WindowsPowerShell\Modules\PowerShellGet\1.6.0\PSModule.psm1:4631 char:17
Run Code Online (Sandbox Code Playgroud)

powershell powershellget

3
推荐指数
1
解决办法
1752
查看次数

标签 统计

powershell ×2

powershellget ×1