We have an old server and some software on there appears to be exhausting the ports, so we were trying to follow some documentation to track down the culprit. I'm keen to try the PowerShell Get-NetTCPConnection to see if something we have control over is hogging them. The documentation below states that on Windows Server 2008 R2 PowerShell can be updated to include the command, but I'm struggling to find the update that does it.
With PowerShell 5.1 I'm getting the below:
PS C:\> Get-NetTCPConnection
Get-NetTCPConnection : The term 'Get-NetTCPConnection' 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-NetTCPConnection
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-NetTCPConnection:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
https://learn.microsoft.com/en-us/windows/client-management/troubleshoot-tcpip-port-exhaust#troubleshoot-port-exhaustion states - "For Windows 7 and Windows Server 2008 R2, you can update your PowerShell version to include the above cmdlet [Get-NetTCPConnection]."
We're running PowerShell 5.1.
I tried adding the NetTCPIP module using the PowerShell command line Install-Module -Name NetTCPIP, but this didn't work for me either.
What am I missing?
PS C:\> $host
Name : ConsoleHost
Version : 5.1.14409.1005
InstanceId : 6b4acbbe-854d-42bd-b8a0-3685836fa9fb
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : en-GB
CurrentUICulture : en-US
PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled : True
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace
PS C:\> $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
The Microsoft Doc also says the following:
For Windows 7 and Windows Server 2008 R2, you can use the below script to collect the netstat output at defined frequency. From the outputs, you can see the port usage trend.
#ECHO ON
set v=%1
:loop
set /a v+=1
ECHO %date% %time% >> netstat.txt
netstat -ano >> netstat.txt
PING 1.1.1.1 -n 1 -w 60000 >NUL
goto loop
Have you tried this already?
Related
I'm Attempting to Unzip A folder located on a shared drive to the root of C:\ on a remote PC but keep getting errors, how do i correct this Powershell?
$Computers = "LN-T48-PF11BL57"
Invoke-Command -Computername $Computers -ScriptBlock {
Expand-Archive -LiteralPath '\\LNAPPS\APPS\Adobe iManage Fix\Program Files (x86).zip' -DestinationPath C:\ -Force } -Verbose
Write-Host "Enter to Exit"
This returns the following error:
A positional parameter cannot be found that accepts argument '\\LNAPPS\APPS\Adobe iManage Fix\Program Files (x86).zip'.
+ CategoryInfo : InvalidArgument: (:) [Expand-Archive], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Expand-Archive
+ PSComputerName : LN-T48-PF11BL57
A few things here:
Remember Windows balks are dropping stuff in the root c:.
So, are we to assume that \LNApps is a server name and \APPS is a
folder share configured on that server?
Lastly, unless that server is running PowerShell v5, that
Expand-Archive cmdlet is not there.
Hence this...
: InvalidArgument: (:) [Expand-Archive], ParameterBindingException
(Get-CimInstance -ClassName CIM_OperatingSystem).Caption
Microsoft Windows Server 2012 R2 Standard
$PSVersionTable
Name Value
---- -----
PSVersion 4.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.42000
BuildVersion 6.3.9600.19170
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion 2.2
Get-Command -Name '*Expand-archive*'
# No results
(Get-CimInstance -ClassName CIM_OperatingSystem).Caption
Microsoft Windows 10 Pro
$PSVersionTable
Name Value
---- -----
PSVersion 5.1.17763.316
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0, 5.0, 5.1.17763.316}
BuildVersion 10.0.17763.316
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Get-Command -Name '*Expand-archive*'
CommandType Name Version Source
----------- ---- ------- ------
Function Expand-Archive 1.0.1.0 Microsoft.PowerShell.Archive
If that cmdlet is not there, you need to use the .Net namespace, System.IO.Compression.FileSystem, to deal with this use case.
can be used to either compress or extract files using this class. The
following example will compress the files stored in the c:\testing
folder:
Add-Type -Assembly 'System.IO.Compression.FileSystem'
[System.IO.Compression.ZipFile]::CreateFromDirectory('c:\testing', 'c:\testing.zip','Optimal',$false)
When you want to extract files, use the ExtractToDirectory method:
[System.IO.Compression.ZipFile]::ExtractToDirectory('c:\testing.zip', 'c:\newtest')
This script works fine:
$machines = get-content H:\0PS\Restart\Inventory417.txt
restart-computer -computername $machines -force
This script DID work fine until this week. I made no changes prior to the failure:
$machines = get-content H:\0PS\Restart\InventoryAccom.txt
restart-computer -computername $machines -force
With the omission of the '417' in the first one and the 'Accom' in the second, there are 100 additional characters in each and they both LOOK identical to me.
Can someone see what I'm missing? The info re: the Powershell version is;
Name Value
---- -----
PSVersion 5.1.14409.1018
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14409.1018
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Thanks very much!
I've copied working scripts and merely substituted the name of the inventory file and tried running that. The same failure occurred.
The results for about three years is that the PCs either restarted or reported the PC ID that failed. All of the scripts except for the one indicated above still do so.
None of the scripts have ever returned a list of anything UNLESS there are devices that fail to restart - then those devices are listed.
When I run the script, the following is returned immediately:
PS C:\Windows\system32> $machines = get-content H:\0PS\Restart\InventoryAccom.txt
restart-computer -computername $machines -force
Restart-Computer : Cannot validate argument on parameter 'ComputerName'. The argument is null or
empty. Provide an argument that is not null or empty, and then try the command again.
At line:2 char:32
+ restart-computer -computername $machines -force
+ ~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Restart-Computer], ParameterBindingValidationExcep
tion
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.Resta
rtComputerCommand
PS C:\Windows\system32>
Sorry. Forgot to mention that I CAN shut them down via shutdown /i.
I have windows 7 64-bit , and i have install sharepoint management shell from this link https://www.microsoft.com/en-us/download/details.aspx?id=35588.
but when i open the SP management shell and i try to run this command:-
PS C:\> Connect-PnPOnline https://*****.sharepoint.com/sites/***/
I got this error:-
Connect-PnPOnline : The term 'Connect-PnPOnline' 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
+ Connect-PnPOnline
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Connect-PnPOnline:String) [], C ommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
so not sure what i am missing?
Here is my version table:-
PS C:\> $psversiontable
Name Value
---- -----
PSVersion 3.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.42000
BuildVersion 6.2.9200.22198
PSCompatibleVersions {1.0, 2.0, 3.0}
PSRemotingProtocolVersion 2.2
Please install the Pnp PowerShell assembly in your system from here:
SharePoint/PnP-PowerShell
And then consume in SharePoint Online Management Shell:
Connect-PnPOnline –Url https://tenant.sharepoint.com –Credentials (Get-Credential)
It will pop up a credential window, input credential and then continue:
If the machine has Internet access and you're on PowerShell 6 or later, it's actually easier to use PowerShell-Get by running:
Install-Module SharepointPNPPowershellOnline
Note: PowerShellGet is available for earlier PowerShell versions as well, but needs to be installed first - see here.
Works on Win 10 but on server 2012 R2 its not there.
PS> Get-PSReadlineKeyHandler
Get-PSReadlineKeyHandler : The term 'Get-PSReadlineKeyHandler' 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-PSReadlineKeyHandler
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-PSReadlineKeyHandler:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Can confirm I'm running v5
PS> $PSVersionTable
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
You can install it from the PowerShell gallery. But I believe you are correct that Windows 10 is the only OS that installs the module by default.
Find-Module psreadline | Install-Module
I have a disconnected session on Win7 Embedded SP1 32 bit station. I am trying to connect to that session. When I attempt to connect I get an error that suggests PSRemotingProtocolVersion mismatch. I can see my Windows 8.1 station has version 2.3 and the Win7 station has 2.2. How can I correct this issue so I can connect to the disconnected session?
Here is excerpts from my session...
PS C:\> Get-PSSession ef-pos-01.faculty.example.org
Id Name ComputerName State ConfigurationName Availability
-- ---- ------------ ----- ----------------- ------------
1 Session3 ef-pos-01.fa... Disconnected Microsoft.PowerShell None
PS C:\> Get-Pssession ef-pos-01.faculty.example.org | Connect-PSSession
Connect-PSSession : The connect operation failed for session Session3 with the following error message: Connecting to remote server
ef-pos-01.faculty.example.org failed with the following error message : The server that is running Windows PowerShell does not support connect operations on
the protocolversion 2.3 that is negotiated by the client computer. Make sure the client computer is compatible with the build 6.3.9600.16406 and the protocol
version 2.2 of Windows PowerShell. For more information, see the about_Remote_Troubleshooting Help topic.
At line:1 char:46
+ Get-Pssession ef-pos-01.faculty.example.org | Connect-PSSession
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Connect-PSSession], RuntimeException
+ FullyQualifiedErrorId : -2141974621,PSSessionConnectFailed,Microsoft.PowerShell.Commands.ConnectPSSessionCommand
PS C:\> Enter-PSSession ef-pos-01.faculty.example.org
[ef-pos-01.faculty.example.org]: PS C:\Users\mike.mackenna\Documents> $PSVersiontable
Name Value
---- -----
PSVersion 4.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.17929
BuildVersion 6.3.9600.16406
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion 2.2
[ef-pos-01.faculty.example.org]: PS C:\Users\mike.mackenna\Documents> exit
PS C:\> $PSversionTable
Name Value
---- -----
PSVersion 5.0.10105.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.34209
BuildVersion 10.0.10105.0
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
I had this problem connecting Windows 10 (PS 5) to Server 2012 (PS 3). I could create the session and do whatever, but couldn't reconnect to it, even from the server. Likewise I could create and reconnect on the server (to localhost) but attempting to connect from my computer failed and broke the session.
I resolved this by installing WMF5 on the server to bring it up to PowerShell 5, is now running smoothly.