查看: 292|回复: 0

[文章教程] 用PS判断系统版本

[复制链接]
xuanxiao 发表于 2023-5-9 15:27:57 | 显示全部楼层 |阅读模式

  1. 在 powershell 6.0 中新增内置变量
  2. $IsCoreCLR                                                                  
  3. $IsLinux                                                                    
  4. $IsMacOS                                                                    
  5. $IsWindows
  6. 用于判断系统。

  7. #假想中的复制文件脚本,由于win,linux目录路径,不兼容。
  8. #所以你要在一个脚本中,分别写2段代码。
  9. if ($IsWindows)
  10. {
  11.         copy-item c:\xxx d:\yyy
  12. }

  13. if ($IsLinux)
  14. {
  15.         copy-item /home/user1  /home/user2
  16. }





  17. if ($PSEdition -eq 'Desktop') #ps v5.1支持
  18. {
  19. #win
  20. }

  21. if ($PSEdition -eq 'Core')
  22. {
  23. #ps6 in win,ps6 in linux
  24. }
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表

在线客服

售前咨询
售后咨询
服务热线
023-58418553
微信公众号