您现在的位置是:网站首页> 编程资料编程资料
Powershell脚本中包含文件资源的例子_PowerShell_
2023-05-26
351人已围观
简介 Powershell脚本中包含文件资源的例子_PowerShell_
Powershell3.0及以后版本。
如果你的脚本需要添加额外资源,比如文本中的服务器名、图片名等等,这时你需要考虑脚本的灵活性。
不要使用绝对路径去指派你的资源路径,在Powershell3.0中可以使用$PSScriptRoot替代你的脚本路径(不支持2.0)
复制代码 代码如下:
$picture = "$PSScriptRoot\Resources\picture.png"
Test-Path -Path $picture
$data = "$PSScriptRoot\Resources\somedata.txt"
Get-Content -Path $data
$PSScriptRoot总是可以获得你脚本运行所在目录名,当然你可能会发现它在执行时为空,这时你只需要将它保存到脚本中执行即可。
相关内容
- Powershell实现从注册表获取用户配置脚本分享_PowerShell_
- Powershell实现从注册表获取本地关联文件的扩展名_PowerShell_
- PowerShell中实现播放WAV音频文件_PowerShell_
- PowerShell实现获取进程所有者_PowerShell_
- Powershell中打开网页实例_PowerShell_
- Powershell实现按类型排序_PowerShell_
- Powershell读取本机注册表中的所有软件关联扩展名_PowerShell_
- Powershell截取字符串并添加省略号的例子_PowerShell_
- Powershell使用C#实现缩写路径_PowerShell_
- PowerShell中iso8601格式日期和DateTime对象互转实例_PowerShell_
