2

The variable at the top of the script defines several commands/variables for New-PSDrive, as well as connection and installation. After this, a function is created to open a text file and extract information out of it. I know this part works because I use it in 2 other scripts. Lastly, The script executes the commands in the first variable.

The script will show as running successfully, but checking the remote computer reveals that nothing happened.

Prior to doing any of this activity, the remote computer has a script run against it that:

  • enables PSRemoting (setting firewall rules and starting WinRM), and
  • bypasses execution policies.

After those steps, the script below is run to install a piece of software.

$eAudIT2014V2Install = {
  $eAudIT2014V2password = ConvertTo-SecureString "PasswordHere" -AsPlainText -Force
  $eAudIT2014V2cred = New-Object System.Management.Automation.PSCredential('domain\user', $eAudIT2014V2password)
  $eAudIT2014V2drive = New-PSDrive -Name eAudIT2014V2 -PSProvider FileSystem -Root "\\Server\Share" -Credential $eAudIT2014V2cred
  $eAudIT2014V2job = Start-Job {"eAudIT2014V2:\Setup.cmd"}
  Wait-Job $eAudIT2014V2job
  Receive-Job $eAudIT2014V2job
}

Function Get-OpenFile($initialDirectory) {
  [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") |
    Out-Null

  $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
  $OpenFileDialog.InitialDirectory = $initialDirectory
  $OpenFileDialog.ShowDialog()
  $OpenFileDialog.Filename
  $OpenFileDialog.ShowHelp = $true
}

$InputFile = Get-OpenFile
if ($InputFile -eq "Cancel") {
  Write-Host "Canceled By User"
  exit
} else {
  $Computers = @(Get-Content -Path $InputFile)
}

foreach ($computer in $computers) {
  Write-Host "Installing eAudIT 2014V2 on Selected Computers"
  Invoke-Command $eAudIT2014V2Install
}

I'm noticing that if I tell this script to run something basic like notepad.exe, a dllhost process starts on the machine, but notepad never does. What am I doing wrong?

1 Answer 1

4

The answer is pretty simple here. All of your script is for naught if you don't tell the Invoke-Command cmdlet what computer you want to execute the code on. As it is you are simply iterating a loop and invoking that command X number of times on the local machine. You need to change that second to the last line to specify the machine to execute the code on:

Invoke-Command $eAudIT2014V2Install -ComputerName $computer
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks very much for the input. Adding that computers line did in fact get processes to run remotely, but nothing is happening on the screen, and there's most certainly no installation activity of the setup file I triggered. Ideas?
Don't forget powershell commands are run under your own session. So a logged on user will not see what you're doing as they are different sessions. If you look under task manager under all processes you would likely see that notepad is running. If you wanted to open notepad on a remote computer that is visible to the logged in user, one way you could do it would be a scheduled task.

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.