I already was asking a similar question here: https://superuser.com/questions/1613630/most-of-powershell-commands-not-working?noredirect=1
Basically, I wasn't able to fix the issue so I got a replacement computer. Brand new. Started setting it up and only did the following:
Installed VS Code
Turned on Powershell extension in VS Code
It prompted something about Package Manager needing an update or it will not work properly
Asked me to install NuGet to get the Package Manager
After that PowerShell 5.1 stopped working again.
Modules not autoloading, fresh instance of powershell does this:
PS C:\WINDOWS\system32> Write-Host
Write-Host : The term 'Write-Host' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
At line:1 char:1
+ Write-Host
+ ~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Write-Host:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Any ideas?
This fixed it for me:
(Get-Module -ListAvailable).Name | %{Import-Module -Name $_ -Force}
[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12
Install-Module -Name PackageManagement -Force -RequiredVersion 1.4.6 -Scope AllUsers -AllowClobber -Verbose
Then if the last command doesn't install NuGet do this:
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Related
My Setup: Windows 10.17134, PowerShell 5.1.17134.407
When trying to Register a new PSRepository using the Code below….
Register-PSRepository -Name "PSGallery" –SourceLocation "https://www.powershellgallery.com/api/v2/" -InstallationPolicy Trusted
….it gives me the following error:
FullyQualifiedErrorId : UseDefaultParameterSetOnRegisterPSRepository,Register-PSRepository
I am not able to install the VMWare PowerCLI Module with this command:
Save-module -Name vmware.powercli -path c:\temp
….it gives me this error:
FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.SavePackage
Here are the results of a days googling
I'm running
Register-PSRepository
-Name "PSGallery"
–SourceLocation "https://www.powershellgallery.com/api/v2/"
-InstallationPolicy Trusted
(multiline for clarity)
and I kept getting
Register-PSRepository : Use 'Register-PSRepository -Default' to
register the PSGallery repository. At line:1 char:1
+ Register-PSRepository -Name "PSGallery" –SourceLocation "https://www. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (PSGallery:String) [Register-PSRepository], ArgumentException
+ FullyQualifiedErrorId : UseDefaultParameterSetOnRegisterPSRepository,Register-PSRepository
I assumed this was to do with proxy settings so I tried all of the various methods of setting the proxy in powershell to no avail.
Finally I ran
Get-PSRepository
and discovered that the repository was already registered, it was just untrusted
So I ran
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
The original reason I had for doIng this is because when I run
Install-PackageProvider -Name NuGet -Force -Scope CurrentUser
I get
Install-PackageProvider : No match was found for the specified search
criteria for the provider 'NuGet'. The package provider requires
'PackageManagement' and 'Provider' tags. Please check if the specified
package has the tags. At line:1 char:1
+ Install-PackageProvider -Name NuGet -Force -Scope CurrentUser
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (Microsoft.PowerShel\u2026tallPackageProvider:InstallPackageProvider)
[Install-PackageProvider], Exception
+ FullyQualifiedErrorId : NoMatchFoundForProvider,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider
Unfortunately, making the repository trusted did no help with my issue
... and the original reason for doing this was so I could run
Install-Module -Name SqlServer -Force -Verbose -Scope CurrentUser
Which was failing (sorry no error message, it was so long ago)
After all my fiddling however, this statement now works without error.
Not sure if it was all the proxy config, or making NuGet trusted or both
I've been chasing this problem for days. I isolated it to Install-PackageProvider not being able to download:
Microsoft.PackageManagement.NuGetProvider-2.8.5.208.dll
In my case, my company does not allow us to download DLLs from the internet without due process. I engaged due process and got an approved copy of the DLL. Then it needs to be placed here:
$env:ProgramFiles\PackageManagement\ProviderAssemblies\nuget\2.8.5.208\Microsoft.PackageManagement.NuGetProvider.dll
Note the version becomes a folder and is stripped from the name.
Manually doing so eliminates the need to run Install-PackageProvider. Some articles state that Import-PackageProvider is necessary to get PowerShell to recognise it. But, I did not need to do the Import. Just try Install-Module -Name SqlServer -Force again.
I'm trying to create user assigned identity, the documentation says that 6.13 should include this function: https://learn.microsoft.com/en-us/powershell/module/azurerm.managedserviceidentity/new-azurermuserassignedidentity?view=azurermps-6.13.0
I uninstalled old versions of Azure RM and installed the latest:
PS C:\Users\user> Get-Module AzureRM -ListAvailable | Select-Object -Property Name,Version,Path
Name Version Path
---- ------- ----
AzureRM 6.13.1 C:\Program Files\WindowsPowerShell\Modules\AzureRM\6.13.1\AzureRM.psd1
But when I try to use it I get the following error:
PS C:\Users\zakima> New-AzureRmUserAssignedIdentity -ResourceGroupName PSRG -Name ID1
New-AzureRmUserAssignedIdentity : The term 'New-AzureRmUserAssignedIdentity' is not recognized as the name of a
cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
At line:1 char:1
+ New-AzureRmUserAssignedIdentity -ResourceGroupName PSRG -Name ID1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (New-AzureRmUserAssignedIdentity:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Am I missing some config setting?
The New-AzureRmUserAssignedIdentity Cmdlet resides in the AzureRM.ManagedServiceIdentity module. This module in turn can be found in the PowerShell Gallery and can be installed via:
Install-Module -Name "AzureRM.ManagedServiceIdentity" -AllowPrerelease
Note that the AllowPrerelease flag for Install-Module might not be available for your installed PowerShellGet version, so you might need to update it before the above would work:
Install-Module "PowerShellGet" –Repository "PSGallery" –Force
The problem is that UserAssignedIdentity is still in preview and apparently is not included in AzureRM package.
The following steps made it work for me:
Move to Az package (note - you need uninstall AzureRM first!). It still doesn't include New-AzUserAssignedIdentity.
Install Az.ManagedServiceIdentity directly by running this command:
Install-Module -Name Az.ManagedServiceIdentity
Enjoy!
I've written the PS script below to 7zip a folder using 7Zip4Powershell however when during the build it fails with the following error:
Install-Module : The term 'Install-Module' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At C:\Build\Work\19\s\DevOps\7zCompress.ps1:3 char:5
+ Install-Module -Scope CurrentUser -Name 7Zip4PowerShell -Verbose -Force
+ ~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Install-Module:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Compress-7Zip : The term 'Compress-7Zip' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Build\Work\19\s\DevOps\7zCompress.ps1:18 char:1
+ Compress-7Zip -Path $sourcedir -ArchiveFileName $filename -CompressionLevel $com ...
+ ~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Compress-7Zip:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Process completed with exit code 0 and had 1 error(s) written to the error stream.
Script
param([string]$sourcedir, [string]$filename, [string]$compressionLevel, [string]$compressionMethod)
If (-not (Get-Module -ListAvailable -Name 7Zip4PowerShell)) {
Install-Module -Scope CurrentUser -Name 7Zip4PowerShell -Verbose -Force
}
If(Test-Path $filename) {
Remove-Item $filename
}
If (-not $compressionLevel) {
$compressionLevel = "Normal"
}
If (-not $compressionMethod) {
$compressionMethod = "Lzma2"
}
Compress-7Zip -Path $sourcedir -ArchiveFileName $filename -CompressionLevel $compressionLevel -CompressionMethod $compressionMethod
How do I get TFS 2015 On-Premises to recognize the Install-Module is a valid command? I've already installed the MSI for Install-Module on that machine. Do I perhaps need to add it as a build agent capability?
According to your error message , double check your powershell version in the build agent machine.
Cause from Powershell 5.0 onwards you , you will be able to use the cmdlet to Install-Module, Save-Module. If you are using the lower version of PS, will get similar error.
You could also manually RDP to the build agent with the build service account and run the PS script. This will narrow down if the issue is related to the environment or your build definition.
Hello I am not powershell programmer and I learning right now using pluralsight and exericese file giving me error and I think it happening because or version change of Azure Powershell from 0.9.8 to version 1.0
Here is error :
c:\Pluralsight\chef\2-chef> .\Create-CourseEnvironmentARM.ps1
Switch-AzureMode : The term 'Switch-AzureMode' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of
the name, or if a path was included, verify that the path is correct and try again.
At C:\Pluralsight\chef\2-chef\Create-CourseEnvironmentARM.ps1:28 char:1
+ Switch-AzureMode AzureResourceManager -Verbose
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Switch-AzureMode:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Test-AzureResourceGroup : The term 'Test-AzureResourceGroup' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Pluralsight\chef\2-chef\Create-CourseEnvironmentARM.ps1:32 char:5
+ if((Test-AzureResourceGroup -ResourceGroupName $GroupName) -eq $false){
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Test-AzureResourceGroup:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
New-AzureResourceGroupDeployment : The term 'New-AzureResourceGroupDeployment' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Pluralsight\chef\2-chef\Create-CourseEnvironmentARM.ps1:44 char:1
+ New-AzureResourceGroupDeployment `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (New-AzureResourceGroupDeployment:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
File Name :.\Create-CourseEnvironmentARM.ps1
I was searching error in google and confirm that azure power shell
deprecate function "Switch-AzureMode AzureResourceManager -Verbose"
https://github.com/Azure/azure-powershell/wiki/Deprecation-of-Switch-AzureMode-in-Azure-PowerShell
Switch-AzureMode AzureResourceManager -Verbose
Here is code from Create-CourseEnvironmentARM.ps1
Switch-AzureMode AzureResourceManager -Verbose
### Create Resource Group ###
if((Test-AzureResourceGroup -ResourceGroupName $GroupName) -eq $false){
New-AzureResourceGroup -Name $GroupName -Location $Location -Verbose
$ResourceGroup = Get-AzureResourceGroup -Name $GroupName
}
else {$ResourceGroup = Get-AzureResourceGroup -Name $GroupName}
$parameters = #{
'newStorageAccountName'="$StorageName";
'adminUsername'="$AdminUsername";
'dnsNameForPublicIP'="$PublicDNSName"
}
New-AzureResourceGroupDeployment `
-Name $DeploymentName `
-ResourceGroupName $ResourceGroup.ResourceGroupName `
-TemplateFile azuredeploy.json `
-TemplateParameterObject $parameters `
-Verbose
Please help me to correct this code. I think author is never update course and I am in middle of course. I hope someone help me to fix this problem.
There is no more "Switch-AzureMode" since v. 1.0.0 of the Powershell.
The ARM and ASM cmdlets exists together and live together. The ASM cmdlets are with unchanged names, but the ARM cmdlets are all now with RM in their name. Like:
Add-AzureRmAccount
Both the powershell cmdlets can be installed via Web Platform Installer.
More, when on Windows 10, the ARM cmdlets can be installed via PowerShell Gallery using the ofllowing commands (under Aministrative PowerShell console):
Install-Module AzureRM
Confirm all the questions being asked. Then run the
Install-AzureRM
Then you are done with the ARM module. Just make sure that your local execution policy is at least "RemoteSigned".
At the end, you will have to edit all your PowerShell scripts to match the new cmdlets and their parameters. Like the New-AzureResourceGroup is now New-AzureRmResourceGroup: https://msdn.microsoft.com/en-us/library/mt603739.aspx
I'm new to PowerShell, Pester and the new VSO build system and I'm trying to get Pester to run my tests for each check in. I've set up and configured a simple PowerShell script to run on each check in.
I first tried simply Invoke-Pester to see if the VSO team had envisioned this and set up common unit test frameworks, but I go the following predictable result:
Invoke-Pester : The term 'Invoke-Pester' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\a\64df1c11\Operations Tools\powershell\runPowershellTests.ps1:1 char:1
+ Invoke-Pester
+ ~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Invoke-Pester:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I tried to use PSGet:
(new-object Net.WebClient).DownloadString("http://psget.net/GetPsGet.ps1") | iex
install-module Pester
Invoke-Pester
But that isn't working either:
New-Item : Access to the path 'PsGet' is denied.
At line:17 char:5
+ New-Item -Path ($Destination + "\PsGet\") -ItemType Directory -Force | Out-N ...
How can I remotely install and execute Pester to run my unit tests?
Try this with PsGet:
(new-object Net.WebClient).DownloadString("http://psget.net/GetPsGet.ps1") | iex
Install-Module Pester -Global
Or use Chocolatey:
iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
choco install pester
There is a task in the VSO marketplace that lets you run your Pester unit tests. The task can be found here at the marketplace. You can see the source code at: git Vsts-Build-Pester