1

This is my first question here and I am also quite new on PowerShell, so I hope I am doing everything alright.

My problem is the following: I want to uninstall a programm on several computers, check if the registry-key is deleted and then install a new version of the programm.

The setup is located on a server within the same domain as the computers.

I want my Script to loop through the computers and execute the setup from the server for every computer. As I am quite new with PowerShell, I have no idea how to do this. I was thinking to maybe use Copy-Item, but I dont want to really move the setup, but simply execute it from the server to the computers? Any idea how to do this?

Best regards

1 Answer 1

1

You can try the following approach.

Note that the need to provide credentials explicitly is a workaround for the infamous double-hop problem.

# The list of computers on which to run the setup program.
$remoteComputers = 'computer1', 'computer2' # ...

# The full UNC path of the setup program.
$setupExePath = '\\server\somepath\setup.exe'

# Obtain credentials that can be used on the
# remote computers to access the share on which 
# the setup program is located.
$creds = Get-Credential

# Run the setup program on all remote computers.
Invoke-Command -ComputerName $remoteComputers {

    # WORKAROUND FOR THE DOUBLE-HOP PROBLEM:
    # Map the target network share as a dummy PS drive using the passed-through
    # credentials.
    # You may - but needn't - use this drive; the mere fact of having established
    # a drive with valid credentials makes the network location accessible in the
    # session, even with direct use of UNC paths.
    $null = New-PSDrive -Credential $using:cred dummy -Root (Split-Path -Parent $using:$setupExePath) -PSProvider FileSystem

    # Invoke the setup program from the UNC share.
    & $using:$setupExePath

    # ... do other things

} 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.