Unable to Unzip Folder when invoked on a remote PC - powershell

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')

Related

I have 8 brief scripts to restart PCs in diff rooms. One abruptly stopped. No changes have fixed it

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.

Connect-PnPOnline : The term 'Connect-PnPOnline' is not recognized as the name of a cmdlet, function, script file, or operable program

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.

Server 2012 R2 missing PSReadline cmdlets?

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

Psedit on a item created with the New-Item cmdlet throws exception

When I create a new file using the New-Item cmdlet and want to edit it within PowerShell ISE using psedit I receive the following exception:
Exception calling "Add" with "1" argument(s): "Object reference not set to an instance of an object."
At line:7 char:13
+ $psISE.CurrentPowerShellTab.Files.Add($_.FullName) > $nul ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : NullReferenceException
Code:
New-Item readme.txt
psedit readme.txt
PsVersionTable:
Name Value
---- -----
PSVersion 5.0.10586.494
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.10586.494
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Is this a known Bug? Any workaround?
Running the following works without an issue and opens a new tab in the ISE with the readme.txt:
New-Item Readme.txt -ItemType file
psedit Readme.txt
PSVersiontable:
Name Value
---- -----
PSVersion 4.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.34209
BuildVersion 6.3.9600.17400
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion 2.2
It seems like this is a PowerShell V5 bug since its working fine on PowerShell V4 (see the comment from Micky Balladelli). A workaround is to create the file using the Out-File cmdlet:
'' | Out-File readme.txt
psedit readme.txt

PS Remoting Protocol Version Mismatch

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.