none
Scripting Question RRS feed

  • Question

  • Good Morning,  I am trying to push and install LAPS on all my workstations. the script is below. 

    $computers = "C:\testPC.txt"
    $source = "C:\LAPS\LAPS.x64.msi"
    $destination = "C$\temp"
    Get-Content $computers | foreach {copy-item -path $source -Destination \$_C$$destination}
    Invoke-Command -ComputerName $computers -Credential (Get-Credential) -ScriptBlock {start-process -Filepath $destination -ArgumentList '/silent' -wait }

    I am getting the following error message

    Invoke-Command : One or more computer names are not valid. If you are trying to pass a URI, use the -ConnectionUri parameter, or pass URI objects instead of strings.
    At C:\Users\jeff.bearden\Documents\LAPS Test.ps1:5 char:1
    + Invoke-Command -ComputerName $computers -Credential (Get-Credential)  ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (System.String[]:String[]) [Invoke-Command], ArgumentException
        + FullyQualifiedErrorId : PSSessionInvalidComputerName,Microsoft.PowerShell.Commands.InvokeCommandCommand

    What am i missing?

    Wednesday, September 25, 2019 3:20 PM

Answers

  • I would recommend deploying via GPO (or similar software distribution system). This has numerous advantages:

    • Package gets installed as a matter of organizational policy
    • Upgrades are simple
    • New machines get the package installed automatically (as a matter of policy)
    • Package management is standardized

    ...and possibly more. It is best not to install a package like this using a one-off approach.


    -- Bill Stewart [Bill_Stewart]

    Wednesday, September 25, 2019 3:43 PM
    Moderator

All replies

  • I would recommend deploying via GPO (or similar software distribution system). This has numerous advantages:

    • Package gets installed as a matter of organizational policy
    • Upgrades are simple
    • New machines get the package installed automatically (as a matter of policy)
    • Package management is standardized

    ...and possibly more. It is best not to install a package like this using a one-off approach.


    -- Bill Stewart [Bill_Stewart]

    Wednesday, September 25, 2019 3:43 PM
    Moderator
  • You are sending a file name as a computer name. You need to use the file contents.

    Always use the simplest approach until you are a more experienced code:

    Get-Content C:\testPC.txt | 
    	ForEach-Object {
    			Copy-Item -path C:\LAPS\LAPS.x64.msi -Destination "\\$_\C$\temp"
    			Invoke-Command -ComputerName $_ -Credential -ScriptBlock {
    				Start-Process -Filepath c:\temp\LAPS.x64.msi -ArgumentList '/silent' -wait -NoNewWindow
    			}
    	}
    Please take Bill's advice for deploying software.


    \_(ツ)_/






    • Edited by jrv Wednesday, September 25, 2019 7:53 PM
    Wednesday, September 25, 2019 7:50 PM