Publish-Module fails with NuGet.Build.Tasks.Pack.targets(198,5) error : Index was outside the bounds of the array - powershell

I've upgraded to dotnet sdk version 3.1 and am trying to publish my powershell module. I am using powershell 5.1.
I run the command:
Publish-Module -Path "C:\sources\myModules\InstallationUtils\" -NuGetApiKey "xxxxxxx" -Repository internal.packages.org"
and get the error:
[C:\Users\xxxxxx\AppData\Local\Temp\469d7c83-6e1a-4366-b948-6a415b0279be\Temp.csproj]
Successfully created package
'C:\Users\xxxxxx\AppData\Local\Temp\158464074\myModules\InstallationUtils\InstallationUtils.1.4.8.nupkg'.
C:\Program Files\dotnet\sdk\3.1.201\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(198,5): error :
Index was outside the bounds of the array.
[C:\Users\xxxxxx\AppData\Local\Temp\469d7c83-6e1a-4366-b948-6a415b0279be\Temp.csproj]
'.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2.1\PSModule.psm1:10944 char:17
+ ... Publish-PSArtifactUtility #PublishPSArtifactUtility_Param ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : FailedToCreateCompressedModule,Publish-PSArtifactUtility
Is anyone have similar issues and managed to fix it?
thanks

I have a work around, which involves replacing the old version of version nuget.exe in
C:\Users\xxxxx\AppData\Local\Microsoft\Windows\PowerShell\PowerShellGet\
with the latest version of nuget.exe .
I found the work around on SQLDBAWithABeard but I am hoping that there is a better solution than this?

Related

Powershell InvokeGlobal Parameter count mismatch

I installed PSFramework on my W2k12 server. However when I run an import-module PSFramework I get the following error:
Exception calling "InvokeGlobal" with "0" argument(s): "Parameter count mismatch."
At C:\Program Files\WindowsPowerShell\Modules\psframework\1.6.181\PSFramework.psm1:7348 char:2
+ $isInstalled = $provider.IsInstalledScript.InvokeGlobal()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : TargetParameterCountException
This works fine on my Win 10 machine.
Any ideas?
Thanks in advance,
Jake.
I'm the maintainer of PSFramework, sorry about that fail!
One of my security-related feature updates broke PSv3 & PSv4 support, I didn't notice right away and then was drowned in heavy workload to fix it timely.
I've added an issue that you can track until it is resolved:
https://github.com/PowershellFrameworkCollective/psframework/issues/474
In the meantime, you can resolve this on your server by updating its PowerShell to v5.1 as Mathias suggested, which will resolve it right away.

Powershell - Not able to find module

I'm experiencing problems when (re)installing modules in PowerShell (see Screenshot link below). It has worked before as the module is already installed.
Screenshot error
Already tried the following:
Set-ExecutionPolicy: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy?view=powershell-6
.Net Framework 4.7.2 is already installed: https://community.powerbi.com/t5/Developer/Unable-to-Connect-with-Power-BI-Service-using-PowerShell/td-p/483356
Repository change: Unable to find repository on Update-Module
I'm out of ideas / Google results. Any suggestions/ideas that I can try? Many thanks in advance.
Error in text:
PS C:\Windows\system32> Install-module MicrosoftPowerBIMgmt
WARNING: Source Location 'https://www.powershellgallery.com/api/v2/package/MicrosoftPowerBIMgmt/1.0.840' is not valid.
PackageManagement\Install-Package : Package 'MicrosoftPowerBIMgmt' failed to download.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1772 char:21
+ ... $null = PackageManagement\Install-Package #PSBoundParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (C:\Users\admin....werBIMgmt.nupkg:String) [Install-Package], Exception
+ FullyQualifiedErrorId : PackageFailedInstallOrDownload,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
Best regards
Seems like you have outdated version of PowerShellGet 1.0.0.1. Try this first (as admin) and then retry your update.
Update-Module PowerShellGet
Try running this
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

"rm: cannot remove 'wslServer.sh': No such file or directory"

In my ongoing war with WSL2/VSCODE I'm trying to completely remove the .vscode-insiders directory from my machine.
rm -rf wont work, neither will delete from windows. Anyone know How I can destroy this thing?
I'm trying to get a dev environment set up with WSL2 VS CODE and Docker in Windows 10 insiders (18965).
I ran into problems trying to install the remote development pack, specifically the /ms-vscode-remote.remote-wsl-0.39.4 extension which is causing no end of problems.
However When I try to remove all vs code-insiders residue I get permissions problems with:
:/mnt/c/Users/micro/.vscode-insiders/extensions/ms-vscode-remote.remote-wsl-0.39.4/scripts/wslServer.sh
I cant delete it from the Ubuntu side with rm -rf
cannot remove 'wslServer.sh': No such file or directory
I cant delete it from windows explorer - no permissions
I cant delete it from powershell as admin running Remove-item.
Looked at all the existing answers on stack and none have a solution as far as i can see.
Would love some help?
Remove-Item : Access is denied
At line:1 char:1
+ Remove-Item wslServer.sh
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (C:\Users\micro...ts\wslServer.sh:String) [Remove-Item], Unauthorized
AccessException
+ FullyQualifiedErrorId : ItemExistsUnauthorizedAccessError,Microsoft.PowerShell.Commands.RemoveItemCommand
Remove-Item : Cannot find path
'C:\Users\micro.vscode-insiders\extensions\ms-vscode-remote.remote-wsl-0.39.4\scripts\wslServer.sh' because it does
not exist.
At line:1 char:1
+ Remove-Item wslServer.sh
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\Users\micro...ts\wslServer.sh:String) [Remove-Item], ItemNotFoundEx
ception
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand
Ctrl+alt+delete - right click 'Windows Subsystem For Linux' - end task.
Now try deleting the folder or let VScode do it for you.

Trouble installing Powercli 11.x

Easing back into Windows after a 3-4 year MacOS hiatus. Powershell has come a long way but I am running into some errors I can't figure out here.
Every article I see on installing the newer PowerCLI is rather simple. Use a package manager to download/install it and off you run. Not for me, I'm getting the following error when trying to run Install-Module -Name VMware.PowerCLI:
PackageManagement\Install-Package : Unable to find dependent module(s) (VMware.VimAutomation.Cis.Core)
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.0.4\PSModule.psm1:9307 char:21
+ ... $null = PackageManagement\Install-Package #PSBoundParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (VMware.VimAutomation.Cis.Core:String) [Install-Package], Exception
+ FullyQualifiedErrorId : UnableToFindDependencyPackage,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
I have tried this on two Windows machines and even with Powershell Core on a Mac. Same issue every time. What am I missing and/or doing wrong?

Getting error while exporting azure db using powershell

Followed Export SQL database example using link :
https://learn.microsoft.com/en-us/azure/sql-database/sql-database-export-powershell#export-sql-database-example
Getting below error:
New-AzureRmSqlDatabaseExport : ResourceNotFound: The Resource 'Microsoft.Sql/servers/XXX.database.windows.net/databases/[DBNAME]' under resource group 'Default-SQL-SoutheastAsia' was
not found.
At [FilePath]\sample.ps1:24 char:18
+ $exportRequest = New-AzureRmSqlDatabaseExport –ResourceGroupName $ResourceGroupN ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzureRmSqlDatabaseExport], CloudException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Sql.ImportExport.Cmdlet.NewAzureSqlDatabaseExport
Get-AzureRmSqlDatabaseImportExportStatus : Cannot bind argument to parameter 'OperationStatusLink' because it is null.
At [FilePath]\sample.ps1:30 char:63
+ Get-AzureRmSqlDatabaseImportExportStatus -OperationStatusLink $exportRequest.Ope ...
+ CategoryInfo : InvalidData: (:) [Get-AzureRmSqlDatabaseImportExportStatus], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.Azure.Commands.Sql.ImportExport.Cmdlet.GetAzureSqlDatabaseImportExportStatus
Any help?
I had this same issue today, actually. I think if you change your server name to not use the fully-qualified name, that might do it. So, just use "xxxxx."
At least that's what worked for me.
You need to verify that your Automation account has latest modules imported and are up to date (AzureRM.Automation – AzureRM.Profile – AzureRM.Sql) atleast to Version: 2.5.0. If modules show a different version, i.e. 1.0.3 then:
navigate to assets in the automation account, select modules and click on
Update Azure Modules
.
Wait for the modules to get updated it normally takes a few minutes