I'm trying to run a PowerShell script on a heavily secured, pseudo air-gapped system, and hitting a snag. The script needs to install the "Microsoft.Graph" module, but it won't work due to the network restrictions. I've manually downloaded the required NuPkg and tracked down dependencies down to the Microsoft.IdentityModel.Abstractions package. When I attempt to use "Install-Package 'Path of nupkg'" for this last one, it fails without a solid error message, just showing "invalid result: (microsoft.identitymodel.abstractions:string) [Install-Package], Exception". I've asked if I can get temporary network access to resolve this but don't expect a quick response from IT. Any tips?
4 Answers
If you've got the modules on hand, just use `Import-Module` with the full path to your module in the -Name parameter. Alternatively, you could place the modules in `C:Program FilesWindowsPowerShellModules`, which allows you to use cmdlets directly without needing to run Install-Module or Import-Module since that location is included in $env:PSModulePath.
Consider setting up a local repository! Since your machine is somewhat connected, you can create a network drive, like `//company-srv01/MyCompanyRepo/`, and save the modules there using `Save-Module`. Then, register that folder as your repository on the restricted machine to install modules without network access. This setup is great for managing updates and controlling module versions in corporate settings.
I like that approach. Removing the default PSGallery will simplify installations even more!
Consider skipping the modules entirely beyond what's needed for authentication. You can leverage `Invoke-MgGraphRequest` and native HTTPS endpoints instead. It's a simpler solution that helps you avoid any module conflicts too.
It seems you might be going about the installation the wrong way. If you use a networked PC for this, try the command `Save-Module -Name XYZ -LiteralPath $HOMEDownloads` to download the module along with its dependencies. Then, you can copy everything from that folder to a location listed in `$env:PSModulePath -split ';'`. This should help you install it without the network issues.

That's a handy tip! Thanks for sharing that.