问题
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.
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.
If it makes any difference i'm using Windows Server 2008 R2
回答1:
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.
回答2:
The link above for Powershell Function from Tomas Panik is not there anymore so I want to add to the answer here.
Short version:
- You can create your function by using Powershell Function. However, this will only last for that session only.
- In order for you to use your function regularly, you need to generate/add your function to your own PowerShell profile. Quick tutorial is here. Tomas Panik's link to Windows PowerShell Profiles also has very good info..
来源:https://stackoverflow.com/questions/15466499/run-powershell-script-from-anywhere