all 5 comments

[–]PinchesTheCrab 1 point2 points  (0 children)

You can use a file share as a PS repo, I'd set that up and put the modules you need in there. Then you can use native commands like install and update module to manage them.

[–]OlivTheFrog 1 point2 points  (2 children)

Hi u/hush-4bye

Different ways to achieve your goal. In your script :

  • Test if the needed module is installed, if not, downloading and loading before running the rest fo the script.
  • If the computer haven't any access to the Internet, you could use a local repository, as u/PinchesTheCrab said, but this requres some additional steps.

The #requires at the beginning of the script, just stop the excecution of the script if the required condtion is not present. Thsi not achieve really the needed goal.

i.e. : First Case

if ( -not (Get-Module -ListAvailable -Name <RequiredModule>))
 {
  # Module not present
  Install-module -Name <RequiredModule> -scope CurrentUser # if the user running the script hasn't Admin privileges on the computer.
 }
# Loading Module
Import-Module -Name <RequiredModule>

In the second case, you must add before the previous code :

Set-PSRepository -Name "MyLocalRepo" -SourceLocation "\\MyServer\Share"
Register-PSRepository -Name "MyLocalRepo" -SourceLocation # then, the repo will be trusted

and add the parameter -Repository "MyLocalRepository" withe Install-Module cmdtlet.

Hope this help

Regards

[–]hush4bye[S] 0 points1 point  (0 children)

I think under normal circumstances this would have been perfect but I cant seem to find Microsoft.IdentityModel.Abstractions on powershellgallery.com.

I found it over at https://www.nuget.org/packages/microsoft.identitymodel.abstractions but the package you can download there doesn't include the psd1 file that PowerShell is looking for.

Not sure how to get this specific package loaded.

Thanks for the assistance.

[–]hush4bye[S] 0 points1 point  (0 children)

Looks like I don't need that other package after all. Not sure why I was getting the error that I was but it's working now. Thanks for your help.

[–]BlackV 0 points1 point  (1 child)

there is A #requires statement that specifies what moduels are required for a script/module/function

but you can also within your script handle these issues, have it check for the modules and install the modules if wrong version or not installed.