从任何地方运行 powershell 脚本 [英] run powershell script from anywhere

查看:54
本文介绍了从任何地方运行 powershell 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am currently working on a powershell script. The objective of this script is to import data from a .csv file from which new users are created if that username does not already exist in the Active Directory.

我的问题是如何让这个脚本从任何位置运行,所以我所要做的就是输入脚本的名称,它就会运行.我已经能够在 BASH 中做到这一点,但无法弄清楚如何在 Power Shell 中做到这一点.到目前为止,谷歌帮助不大.

My question is how can I make this script run from any location so all I have to do is type the name of the script and it will run. I have been able to do this in BASH but can't figure out how to do this in power shell. So far google has been little help.

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

If it makes any difference i'm using Windows Server 2008 R2

推荐答案

基本思路是创建Powershell 函数 它将完成工作(或将调用位于其他位置的其他脚本)并将此方法放入 Profile.ps1 脚本(该脚本是每次启动 powershell 时加载) - 查看 Windows PowerShell个人资料了解更多详情.

The basic idea is to create Powershell Function which will do the work (or will call other script placed in other location) and put this method to Profile.ps1 script (the script which is loaded everytime you start powershell) - Look at Windows PowerShell Profiles for further details.

这篇关于从任何地方运行 powershell 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆