code_junkie

Importing “libraries” in powershell

Nov 12th, 2011
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. # to load c:powershellscriptscluster_utils.ps1 if it isn't already loaded
  2. . require cluster_utils
  3.  
  4. $global:loaded_scripts=@{}
  5. function require([string]$filename){
  6. if (!$loaded_scripts[$filename]){
  7. . c:powershellscripts$filename.ps1
  8. $loaded_scripts[$filename]=get-date
  9. }
  10. }
  11.  
  12. function reload($filename){
  13. . c:powershellscripts$filename.ps1
  14. $loaded_scripts[$filename]=get-date
  15. }
  16.  
  17. $global:scriptdirectory = 'C:powershellscripts'
  18. $global:loaded_scripts = @{}
  19.  
  20. function require {
  21. param(
  22. [string[]]$filenames=$(throw 'Please specify scripts to load'),
  23. [string]$path=$scriptdirectory
  24. )
  25.  
  26. $unloadedFilenames = $filenames | where { -not $loaded_scripts[$_] }
  27. reload $unloadedFilenames $path
  28. }
  29.  
  30. function reload {
  31. param(
  32. [string[]]$filenames=$(throw 'Please specify scripts to reload'),
  33. [string]$path=$scriptdirectory
  34. )
  35.  
  36. foreach( $filename in $filenames ) {
  37. . (Join-Path $path $filename)
  38. $loaded_scripts[$filename] = Get-Date
  39. }
  40. }
  41.  
  42. $global:scriptdirectory= 'c:powershellscripts'
  43. $global:loaded_scripts=@{}
  44. function require(){
  45. param ([string]$filename, [string]$path=$scriptdirectory)
  46. if (!$loaded_scripts[$filename]){
  47. . (Join-Path $path $filename)
  48. $loaded_scripts[$filename]=get-date
  49. }
  50. }
  51.  
  52. function reload(){
  53. param ([string]$filename, [string]$path=$scriptdirectory)
  54. . (Join-Path $path $filename)
  55. $loaded_scripts[$filename]=get-date
  56. }
Add Comment
Please, Sign In to add comment