Hi, everybody and my respect!
Once again I need help with my PoSh perversions)))
I’d like to benefit from using some PoSh module features in my script, so I need to check whether this module is installed in the system, and if not - install it. I don’t know, in advance, what user will run my script since there are two different parts of it: the first script checks the current system config, configs the system as needed, and the other script performes some certain tasks. Thus I don’t want to install the module in the CurrentUser scope and would like to install it for all users.
The solution for this is to start new PoSh process with the verb ‘RunAs’ but we have a web proxy and local administrators do not have permissions to access WWW via it. But my script to implement all this faces a problem.
Here is the patient:
if ('ModuleName' -notin (Get-Module -All).Name) {
Start-Process powershell -ArgumentList:"-command & {
if (![System.Net.ServicePointManager]::SecurityProtocol.ToString().Contains('Tls12')) {
[System.Net.ServicePointManager]::SecurityProtocol += [System.Net.SecurityProtocolType]::Tls12
}
`$Args = @{
Name = 'CredentialManager'
Scope = 'AllUsers'
Proxy = (Read-Host -Prompt:'Enter the Web Proxy address: ')
ProxyCredential = (Get-Credential -Message:'Provide Web Proxy credentials:')
Force = `$$true
}
Install-Module @Args
}" -Verb runas
}
else {
'Yahoo!!!'
}
Running this script ends with warnings and a sudsequent error: “WARNING: Unable to resolve package source ‘https://www.powershellgallery.com/api/v2’.
PackageManagement\Install-Package : No match was found for the specified search criteria and module name…”
Pleeeeease?! What else am I missing?
Thanks a lot in advance!!!