• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >PowerShell > PowerShell包含另一个脚本文件和获取当前脚本所在目录的方法例子

PowerShell包含另一个脚本文件和获取当前脚本所在目录的方法例子

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了powershell脚本,powershell执行脚本,powershell 运行脚本,powershell常用脚本,powershell脚本下载等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

本文介绍在PowerShell脚本中,如何获取脚本文件(.ps1文件)所在的目录。本文介绍在方法适用于PowerShell 3.0。

在PowerShell 3.0中,有一个变量可以很方便的获取脚本所在的目录。我们在e:\ps\script1.ps1和script2.ps1,内容分别如下:

script1.ps1内容:
Write-Host "This is script1.ps1"
Write-Host "Let me call script2.ps1:"

. "$PSScriptRoot\script2.ps1"
</div>

script2.ps1内容:
Write-Host "This is script2.ps1"
</div>
运行script1.ps1,将用调用script2.ps1的脚本代码。

注意,在script1.ps1脚本中,我们使用了$PSScriptRoot这一变量来获取脚本所在的目录。这个变量在PowerShell 3.0中新增加的一个变量。在运行script1.ps1脚本时,这个变量就代指了E:\ps这个目录路径。

好了,关于PowerShell使用$PSScriptRoot获取脚本所在的目录,本文就介绍这么多,希望对大家有所帮助。

</div>

您可能想查找下面的文章:

  • PowerShell因为在此系统中禁止执行脚本的解决方法
  • PowerShell时间记录脚本
  • Powershell实现编写和运行脚本
  • PowerShell脚本反引号用法实例:随时随地给代码换行
  • Powershell脚本的4种执行权限介绍
  • PowerShell中获取当前运行脚本路径的方法
  • PowerShell实现动态获取当前脚本运行时消耗的内存
  • PowerShell实现的文件同步脚本分享
  • Powershell实现获取电脑序列号功能脚本分享
  • Powershell脚本中使用条件断点实例

相关文章

  • Powershell实现编写和运行脚本
  • Powershell比较两个文件夹的不同
  • PowerShell中查找字符串位置的IndexOf函数使用实例
  • PowerShell中使用正则和ValidateSet验证参数合法性
  • Powershell Profiles配置文件的存放位置介绍
  • PowerShell单行注释、多行注释、块注释的方法
  • PowerShell查看本机文件关联程序和默认打开程序的方法
  • PowerShell显示隐藏文件和系统文件的方法
  • PowerShell获取字符串长度的方法
  • Powershell小技巧之查询AD用户

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • Powershell小技巧之播放WAV声音
    • Powershell小技巧之判断是否包涵大小写
    • PowerShell入门教程之PowerShell管道介绍
    • Windows Powershell过滤管道结果
    • PowerShell 3.0管理Hyper-V 3.0
    • PowerShell中简单的自定义函数和调用函数例子
    • PowerShell小技巧之使用New-Module命令动态创建对象
    • PowerShell在控制台输出特殊符号的方法
    • Windows Powershell强类型数组
    • PowerShell脚本源码输出到文件的最佳写法

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有