Remote PowerShell : Error 307 - windows

On a Widnows 7 PC, I have an error 307 when I run the Invoke-Command or Enter-PSSession in PowerShell. I have the two computers in the trusted zone. When I run the same command on a Windows 8.1 or Windows Server 2012 R2, I don't have the error and the command works perfectly. The target runs Windows Server 2012 R2.
They both run PowerShell v4.0 (for Widnows 7, I upgraded according to MS : https://www.microsoft.com/en-us/download/details.aspx?id=40855).
For Windows 7 :
PS C:\> $PSVersionTable
Name Value
---- -----
PSVersion 4.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.18444
BuildVersion 6.3.9600.16406
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion 2.2
PS C:\> Enter-PSSession -ComputerName 127.0.0.1
[...]HTTP error 307[...]
+ Enter-PSSession -ComputerName 127.0.0.1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument : (127.0.0.1:String) [Enter-PSSession], PSRemotingTransportException
+ FullyQualifiedErrorId : CreateRemoteRunspaceFailed
For Windows 8.1 or Windows Server 2012 R2 :
PS C:\> $PSVersionTable
Name Value
---- -----
PSVersion 4.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.34014
BuildVersion 6.3.9600.17400
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion 2.2
PS C:\> Enter-PSSession -ComputerName 127.0.0.1
[127.0.0.1]: PS C:>
Moreover, when I test the connexion with Test-WSMan, I get a HTTP error 12152. And the two machines ping the other.
Have you an idea for a possible solution ?
ps : the exact English message when run Invoke-Command :
[xxxxx] Connecting to remote server srvpwdev01 failed with the following error message : <f:WSManFault xmlns:f="http://schemas.microsoft.com/wbem/wsman/1/wsmanfault" Code="2150859023" Machine="xxxxx"><f:Message></f:Message></f:WSManFault> For more information, see the about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OpenError: (srvpwdev01:String) [], PSRemotingTransportException
+ FullyQualifiedErrorId : -2144108273,PSSessionStateBroken
I have the number 307 in a French Windows.

Related

Does PowerShell cmdlet Get-WindowsFeature only work on Windows Server?

New to Powershell here.
I'm running a system with Windows-10.
Is the PowerShell command Get-WindowsFeature only available on Windows Server?
When I run this command:
Get-WindowsFeature
I get the following error:
Get-WindowsFeature : The term 'Get-WindowsFeature' 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
Get-WindowsFeature
+ CategoryInfo : ObjectNotFound: (Get-WindowsFeature:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Here is my current PowerShell version information:
Name Value
---- ----- PSVersion 5.1.19041.2364
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.2364
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Thanks

Cannot use cd on Windows Powershell. Path not found

Cannot use cd: file not found
When I run
cd C:\Users\zoua2\Downloads\pwa-ecommerce-demo-payment-request-api.zip\pwa-ecommerce-demo-payment-request-api
on powershell. It outputs
cd : Cannot find path 'C:\Users\zoua2\Downloads\pwa-ecommerce-demo-payment-request-api.zip\pwa-ecommerce-demo-payment-request-api' because it does not exist.
At line:1 char:1
+ cd C:\Users\zoua2\Downloads\pwa-ecommerce-demo-payment-request-api.zi ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\Users\zoua2\...ent-request-api:String) [Set-Location], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand
Device data:
Operating system: Windows 10 64 bit
PSVersionTable Data:
Name Value
---- -----
PSVersion 5.1.18362.752
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.18362.752
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
You're getting that error because C:\Users\zoua2\Downloads\pwa-ecommerce-demo-payment-request-api.zip\pwa-ecommerce-demo-payment-request-api is not a valid file path.
Windows programmatically unpacks the archive metadata and allows you to seemlessly "browse" the contents in Explorer, but the entries in the archive don't actually exists as files in the underlying file system - not until you unpack the zip file.
If you don't want to unpack the entire archive to disk, do like Explorer does and inspect the archive programmatically before extract anything!

Powershell issues with Start-Transcript

I am trying to log my simple script for windows updates. When I to the Start-Transcript command it starts but it ends right after it starts. Currently running powershell 5.1 below is the code I am trying to log.
#Start Log
Start-Transcript -Path $logFolder\windowsupdate.$logDate.log
#Get and install Windows Updates
Get-WUInstall -MicrosoftUpdate -AcceptAll -IgnoreReboot
Get-WUInstall -MicrosoftUpdate -AcceptAll -Install -IgnoreReboot
#Set install from MS
#Add-WUServiceManager -ServiceID 7971f918-a847-4430-9279-4a52d1efe18d
#stop Logging
Stop-Transcript
The output is below. I started out some information. Also as you can see the start time and end time are the same but the script was still running when it ended the Transcript.
**********************
Windows PowerShell transcript start
Start time: 20190918224703
Username: ********
RunAs User: ********
Machine: ******** (Microsoft Windows NT 10.0.14393.0)
Host Application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Process ID: 9368
PSVersion: 5.1.14393.3053
PSEdition: Desktop
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.14393.3053
BuildVersion: 10.0.14393.3053
CLRVersion: 4.0.30319.42000
WSManStackVersion: 3.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1
**********************
Transcript started, output file is C:\********\WU-Logs\windowsupdate.2019-09-18-22-47.log
**********************
Windows PowerShell transcript end
End time: 20190918224703
**********************

Powershell : $host.version output different between script and shell

Why the output of $host.version is different if we start it from a script called with ".\script.ps1" and if we execute the command un the shell ?
from shell :
PS C:\Users\user\Desktop> $PSVersiontable
Name Value
--- -----
PSVersion 5.1.14409.1005
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14409.1005
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
from script :
PS C:\Users\user\Desktop>.\check.ps1
System.Collections.Hashtable
Key : PSVersion
Value : 5.1.14409.1005
Name : PSVersion
Key : PSEdition
Value : Desktop
Name : PSEdition
Key : PSCompatibleVersions
Value : {1.0, 2.0, 3.0, 4.0...}
Name : PSCompatibleVersions
[...]
Thanks
Because they're different hosts.. Console, ISE, etc. are all different hosts.
If you're referring to your PowerShell version, they aren't different, even in your own question.

Unable to set certificate friendly name through PowerShell (access is denied)

I'm trying to update a (root) certificate's friendly name through PowerShell.
The certificate I'm trying to update is highlighted in the screenshot below (taken from certmgr.msc):
Here's the PowerShell code (largely taken from here):
Set-Location cert:
cd .\CurrentUser\Root
$cert = gci .\02FAF3E291435468607857694DF5E45B68851868
$cert.FriendlyName = "UserTrust CA"
(I've verified the thumbprint with the certificate properties in certmgr.msc to make sure it's the same certificate).
The last line will result in the following error:
Exception setting "FriendlyName": "Access is denied.
"
At line:1 char:7
+ $cert. <<<< FriendlyName = "UserTrust CA"
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
I've tried the following things so far:
Running PowerShell as administrator
Changing the execution policy using: Set-ExecutionPolicy Unrestricted
Other information:
PowerShell version is 2.0 (running on Windows 7 Enterprise x64)
I'm running the x64 version of PS
DEP and UAC are disabled
My account is part of the Administrators group
I'm a complete PowerShell n00b ;-)
PS version output:
$PSVersionTable.PSVersion
Major Minor Build Revision
----- ----- ----- --------
2 0 -1 -1
You need to update your version of Powershell to 3.0 or 4.0.
See Get-ChildItem for Certificate
I have Powershell 4.0 and I was able to change the FriendlyName without problems. This was visible in certmgr.msc after a restart.
You can download Powershell 4.0 here.
If you are a Powershell beginner it's probably better to use Get-ChildItem instead of gci for improved readability. Also, cd is an alias of Set-Location so it's better to choose one or the other in your script to avoid confusion.

Resources