|
"A space for AD, Exchange and other technical stuff"
-- Where Information Technology Lives! --
|
|
|
Creating and using a function in powershell. make a new script, call it getProcess.ps1.
Function getProcess
{ Get-Process | format-table name, id, ws -autosize } To call this you must load it into memory as a function. To do so run . C:\scripts\getProcess.ps1 (Note the (.) and the space before the path. This loads the function in the memory) Now call the function getProcess by simply typing getProcess. To take it one step further and make the script look like this. Remember to reload the function with the . C:\scripts\getProcess.ps1 command each time you change it.
Function getProcess
{ param($processname) Get-Process $processname | Format-Table name, id, ws -autosize } Now call it by: getProcess <someProcessName> You will get the information on just the process you have specified. Change the getProcess <someProcessName> to getProcess a* and you will get a list of all processes running that begin with "a". If you wanted to use the function (or reuse it) in the script simply call it. Try it.
getProcess *
Function getProcess
Hope it helps. dw |
|
|