Visual Studio Code error "/bin/sh: 1: powershell: not found" - powershell

I get the error "/bin/sh: 1: powershell: not found" in the OUTPUT tab in Visual Studio Code Version 1.53.0 when i try to run simple script in a new file which is open in the editor.
does the "which pwsh" output "/opt/microsoft/powershell/7/pwsh" have anything to do with this? Maybe the path.
And as a result the PROBLEMS tab outputs:
some extra details:
PS /home/arend/.vscode/extensions/ms-vscode.powershell-2020.6.0/examples> which pwsh
/opt/microsoft/powershell/7/pwsh
PS /home/arend/.vscode/extensions/ms-vscode.powershell-2020.6.0/examples> $PSVersionTable
Name Value
PSVersion 7.1.1
PSEdition Core
GitCommitId 7.1.1
OS Linux 5.4.0-65-generic #73~18.04.1-Ubuntu SMP Tue Jan 19 09:02:24 UTC 2021
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Visual Studio Code
Version: 1.53.0
Commit: 8490d3dde47c57ba65ec40dd192d014fd2113496
Date: 2021-02-03T15:56:04.185Z
Electron: 11.2.1
Chrome: 87.0.4280.141
Node.js: 12.18.3
V8: 8.7.220.31-electron.0
OS: Linux x64 5.4.0-65-generic

Related

Ubuntu 20 cannot Connect to MS Online Service via Powershell

I am using Ubuntu 20 and I have installed powershell to manage Office 365 accounts.
The powershell version is as follows:
Name Value
PSVersion 7.3.1
PSEdition Core
GitCommitId 7.3.1
OS Linux 5.15.0-58-generic #64~20.04.1-Ubuntu SMP Fri Jan 6 16:42:31 UTC 2023
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
When I run the command line with the correct credentials:
Connect-MsolService -Credential $Credentials
I get this error message:
Connect-MsolService: Could not load file or assembly 'System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.
Connect-MsolService: Could not load file or assembly 'System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.
Does any one know why?
Any help would be greatly appreciated...

System.Net.WebClient error can't download picture from the intranet

I have a problem with powershell.
I am trying to download a gif from the intranet of our company with a BAT data, but it always say the following error:
powershell -Command "(New-Object System.Net.WebClient).DownloadFile('https://domain.name/file.name','C:\file.name')"
can anyone help me?
edit: Here is the version of powershell:
sure here is the table:
Name Value
---- -----
PSVersion 5.0.10586.117
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.10586.117
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
The windows version is Windows 2008 R2
Best regards,
Xplosio

Can't change powershell version

I have a Windows 10 machine that is running Powershell version 5. When I type in $psversiontable, I get:
PS C:\WINDOWS\system32> $psversiontable
Name Value
---- -----
PSVersion 5.1.14393.1198
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.1198
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
When I try to change version by typing in powershell -version 4.0, I still get this:
PS C:\WINDOWS\system32> $psversiontable
Name Value
---- -----
PSVersion 5.1.14393.1198
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.1198
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Do you know how I can run version 4?
Thanks!
The short answer is you can't. There is only a special mode for version 2.0.
Otherwise PowerShell is extremely backwards compatible. Even further PowerShell 3.0 and 4.0 can't be installed side-by-side. Sapien wrote a great blog post covering additional details on this
In general barring a very few outlier bugs, code written for PowerShell 3.0 or 4.0 will work with 5.0/5.1

PowerShell Script With Classes won't execute on Fresh Windows 10 Installation

I am attempting to execute a PowerShell script that works fine on a windows 10 PC that has visual studio and all its dependencies installed, but it will not execute on a VM with a fresh installation of windows 10 pro. I've chiseled the script down and determined that the thing it does not like is the definition of a class in the script.
Class Computer {
[String]$Name
[String]$Description
[String]$Type
[String]$Owner
}
The error I get when running the script with nothing but this class definition is:
An error occurred while creating the pipeline.
+CategoryInfo: NotSpecified: (:) [], ParentContainsErrorRecordException
+FullyQualifiedErrorId: RuntimeException
Running $PSVersionTable on the fresh VM:
Name Value
---- -----
PSVersion 5.0.10240.16384
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.42000
BuildVersion 10.0.10240.16384
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
Doesn't PowerShell 5.0 have support for classes? Am I missing a .NET framework dependency that isn't installed or enabled by default with a fresh Windows 10 installation?
To get the WMF 5.0 functionaly, please update to the November Update (10.0.10586.0) per The WMF 5.0 release blog.
Note: If you are running Windows 10, you can get the same set of functionality available in WMF 5.0 RTM by updating to the November update of Windows 10 (Version 1511). If you have not already updated your Windows 10 system, select the Start button, then select Settings > Update & security > Windows Update > Check for updates.

PowerShell $PSVersionTable

I have PowerShell 3.0 installed, and I wish to emulate v1.0
When I launch PowerShell 3.0 with -Version 1 $PSVersionTable reports:
Name Value
---- -----
CLRVersion 2.0.50727.5456
BuildVersion 6.1.7601.17514
PSVersion 2.0
WSManStackVersion 2.0
PSCompatibleVersions {1.0, 2.0}
SerializationVersion 1.1.0.1
PSRemotingProtocolVersion 2.1
If I use the -Version 2 parameter I get the same result
If I use the -Version 3 parameter I get version 3.
Question, why can't I emulate version 1?
Looking at this answer, I don't think you can run 1 & 2 side-by-side without some surgery on the GAC (so it would follow that 1, 2 & 3 don't all co-exist either - only 2 & 3, because 2 & 3 were designed to run side by side). Version 2 was meant to completely replace version 1, AFAICT.
You can not run V1 using the side by side stuff. That was never supported. You CAN run V2 from V3, but not V1.