Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从任意位置运行powershell脚本_Powershell_Window_Windows Server 2008 - Fatal编程技术网

从任意位置运行powershell脚本

从任意位置运行powershell脚本,powershell,window,windows-server-2008,Powershell,Window,Windows Server 2008,我目前正在编写powershell脚本。此脚本的目标是从.csv文件导入数据,如果Active Directory中不存在该用户名,则从该文件创建新用户 我的问题是如何让这个脚本从任何位置运行,所以我所要做的就是键入脚本的名称,它就会运行。我已经能够在BASH中实现这一点,但不知道如何在powershell中实现这一点。到目前为止,谷歌帮不了什么忙 如果有什么不同,我使用的是Windows Server 2008 R2基本思想是创建将执行此工作的脚本(或调用放置在其他位置的其他脚本),并将此方法

我目前正在编写powershell脚本。此脚本的目标是从.csv文件导入数据,如果Active Directory中不存在该用户名,则从该文件创建新用户

我的问题是如何让这个脚本从任何位置运行,所以我所要做的就是键入脚本的名称,它就会运行。我已经能够在BASH中实现这一点,但不知道如何在powershell中实现这一点。到目前为止,谷歌帮不了什么忙


如果有什么不同,我使用的是Windows Server 2008 R2

基本思想是创建将执行此工作的脚本(或调用放置在其他位置的其他脚本),并将此方法放入Profile.ps1脚本(每次启动powershell时加载的脚本)-查看了解更多详细信息。

上面的Powershell函数链接不再存在,因此我想在这里添加答案

简短版本:

  • 您可以使用Powershell函数创建函数。然而,这只会持续该届会议
  • 为了让您能够定期使用函数,您需要将函数生成/添加到自己的PowerShell配置文件中。快速教程包括和。Tomas Panik的Windows链接也有很好的信息

  • 更新:感谢侯赛因·穆萨维报道旧的断链

    您是否尝试将脚本目录添加到您的路径中?此答案的链接实际上给出了一个服务器521错误!包含断开的链接