Script fails invoke-command local computer to a remote server

I have a script on my local c drive in a folder c:\util n script name is test3.ps1

I would like to run this script on any machine I can invoke-command to

 

PS C:\util> Invoke-Command -ComputerName tgcs011 -ScriptBlock { c:\util\test3.ps1 int }
The term ‘c:\util\test3.ps1’ 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.

  • CategoryInfo : ObjectNotFound: (c:\util\test3.ps1:String) [], CommandNotFoundException
  • FullyQualifiedErrorId : CommandNotFoundException
  • PSComputerName : tgcs011

PS C:\util> $PSVersionTable

Name Value


PSVersion 5.1.16299.967
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
BuildVersion 10.0.16299.967
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

I was trying this at work and came home on my network and get the same results at work PSV is 3.0

 

The script is a two liner

Clear-Host
get-service nscp

 

Has to be a syntax error???

 

Any ideas

If I got you right you have 2 options:

  1. Because it’s just a one liner you could simply use this one line in the script block instead of the file name.
  2. If you use a file you should use the according paramter set of Invoke-Command -ComputerName ‘tgcs011’ -FilePath ‘c:\util\test3.ps1’

… I’d recomend to re-read the complete help including the examples … :wink: :smiley:

Hi that worked on my home network

I tried on my work server

PS C:\util> invoke-command -ComputerName metro-12-fs02 -FilePath ‘c:\util\Get-WindowsUpdates.ps1’
Cannot validate argument on parameter ‘Source’. The argument is null or empty. Supply an argument that is not null or
empty and then try the command again.

  • CategoryInfo : InvalidData: (:slight_smile: [New-EventLog], ParameterBindingValidationException
  • FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.NewEventLogCommand
  • PSComputerName : metro-12-fs02

Cannot validate argument on parameter ‘Source’. The argument is null or empty. Supply an argument that is not null or
empty and then try the command again.

  • CategoryInfo : InvalidData: (:slight_smile: [Write-EventLog], ParameterBindingValidationException
  • FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.WriteEventLogCommand
  • PSComputerName : metro-12-fs02

Title : 2019-02 Preview of Monthly Quality Rollup for Windows Server 2012 for x64-based Systems
(KB4487024)
Description : Install this update to resolve issues in Windows. For a complete listing of the issues that are
included in this update, see the associated Microsoft Knowledge Base article for more
information. After you install this item, you may have to restart your computer.
SupportUrl : http://support.microsoft.com/help/4487024
UninstallationNotes : This software update can be removed by selecting View installed updates in the Programs and
Features Control Panel.
RebootRequired : False

Title : 2019-02 Preview of Quality Rollup for .NET Framework 3.5, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1,
4.7.2 for Windows Server 2012 for x64 (KB4487257)
Description : Install this update to resolve issues in Windows. For a complete listing of the issues that are
included in this update, see the associated Microsoft Knowledge Base article for more
information. After you install this item, you may have to restart your computer.
SupportUrl : http://support.microsoft.com
UninstallationNotes : This software update can be removed by selecting View installed updates in the Programs and
Features Control Panel.
RebootRequired : False

Cannot validate argument on parameter ‘Source’. The argument is null or empty. Supply an argument that is not null or
empty and then try the command again.

  • CategoryInfo : InvalidData: (:slight_smile: [Write-EventLog], ParameterBindingValidationException
  • FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.WriteEventLogCommand
  • PSComputerName : metro-12-fs02

 

Could it be cause of the version of powershell?

 

Thanks

Seems like error is thrown from Get-WindowsUpdates.ps1 script. Make sure the inputs are passed to the script properly.

I got the script from here

https://gallery.technet.microsoft.com/Get-WindowsUpdatesps1-7c82c1f4

It stats this

Without any parameters the script will return the title of each update that
is currently available.

 

 

Also when i run the script local without any arguments it runs fine.

 

PS C:\util> .\Get-WindowsUpdates.ps1

Title : 2019-02 Preview of Monthly Quality Rollup for Windows Server 2012 for x64-based Systems
(KB4487024)
Description : Install this update to resolve issues in Windows. For a complete listing of the issues that are
included in this update, see the associated Microsoft Knowledge Base article for more
information. After you install this item, you may have to restart your computer.
SupportUrl : http://support.microsoft.com/help/4487024
UninstallationNotes : This software update can be removed by selecting View installed updates in the Programs and
Features Control Panel.
RebootRequired : False

Title : 2019-02 Preview of Quality Rollup for .NET Framework 3.5, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1,
4.7.2 for Windows Server 2012 for x64 (KB4487257)
Description : Install this update to resolve issues in Windows. For a complete listing of the issues that are
included in this update, see the associated Microsoft Knowledge Base article for more
information. After you install this item, you may have to restart your computer.
SupportUrl : http://support.microsoft.com
UninstallationNotes : This software update can be removed by selecting View installed updates in the Programs and
Features Control Panel.
RebootRequired : False

Get-WindowsUpdates.ps1
Where is this file located, on your admin workstation or on the remote server?

Just curious… try…

# If it is on the remote server then - the script needs to be on this server UNC path
Invoke-Command -ComputerName 'metro-12-fs02' -ScriptBlock { & 'c:\util\Get-WindowsUpdates.ps1' }

# If the file is on your workstation - the script needs to be on this server UNC path
Invoke-Command -ComputerName 'metro-12-fs02' -ScriptBlock { & '\\YourWorkstationName\c$\util\Get-WindowsUpdates.ps1' }

I got around this by coping the file to every server.

I now can run it from my one server and invoke command to all others in the network

I just need to have Winrm working on all servers now. My firewall guy needs to set the firewall policy on all servers. he is working on that

 

We can close this issue as resolved

 

Thanks for all the help