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.
Related
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: 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!
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
**********************
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.
I have an application that is required to check the versions of various system EXEs and DLLs to determine if they are vulnerable or not. This is a native C++ application which does not provide any specific WinSxS linkages in its manifest. On Windows 7, when I invoke GetFileVersionInfo on an absolute path, for example "c:\windows\system32\taskeng.exe", I receive the version information for "C:\Windows\winsxs\x86_microsoft-windows-taskscheduler-engine_31bf3856ad364e35_6.1.7600.16385_none_e582a352202e02c8\taskeng.exe"
So, to clarify, the version c:\windows\system32\taskeng.exe reported by Windows Explorer is 6.1.7600.16699.
The version of c:\windows\system32\taskeng.exe reported by GetFileVersionInfo() is 6.1.7600.16385.
How do I force my app to not have its file redirected via WinSxS?
Here's a PowerShell script to show the difference. FileVersion is a string that is different than the composition of [FileMajorPart].[FileMinorPart].[FileBuildPart].[FilePrivatePart].
PS C:\> [System.Diagnostics.FileVersionInfo]::GetVersionInfo("c:\windows\system32\taskeng.exe") | Format-List -property *
Comments :
CompanyName : Microsoft Corporation
FileBuildPart : 7601
FileDescription : Task Scheduler Engine
FileMajorPart : 6
FileMinorPart : 1
FileName : c:\windows\system32\taskeng.exe
FilePrivatePart : 17514
FileVersion : 6.1.7600.16385 (win7_rtm.090713-1255)
InternalName : TaskEng
IsDebug : False
IsPatched : False
IsPrivateBuild : False
IsPreRelease : False
IsSpecialBuild : False
Language : English (United States)
LegalCopyright : © Microsoft Corporation. All rights reserved.
LegalTrademarks :
OriginalFilename : taskeng.exe.mui
PrivateBuild :
ProductBuildPart : 7601
ProductMajorPart : 6
ProductMinorPart : 1
ProductName : Microsoft® Windows® Operating System
ProductPrivatePart : 17514
ProductVersion : 6.1.7600.16385
SpecialBuild :
Are you sure you are looking at the correct fields? GetFileVersionInfo() gives me the same thing as Explorer with one caveat: the FileVersion in the StringFileInfo is 6.1.7600.16385 whereas the FileVersion in the VS_FIXEDFILEINFO is 6.1.7600.16699. Explorer is showing the FileVersion from the VS_FIXEDFILEINFO. I guess Microsoft just didn't update the StringFileInfo for some reason.