"Double-Click" an icon on the desktop with a Script.
"Double-Click" an icon on the desktop with a Script.
I have this script below. That replaces a string in a file on each computer listed on the CSV file.
after the string has been replaced on a computer, I would like it to execute(Double-Click) on an icon located on the Desktop , lets say the name of the Icon is "DoubleClickhere"
Thank you
## csv file with machines and user names to process:$csv = 'c:\Scripts\Computers.csv'## Absolute local file path on the clients:$filePath = 'C:\test.txt'$pattern = '(-username\s+)\S+'Import-Csv -Path $csv | ForEach-Object { $computer = $_.ComputerName.Trim() $newUser = $_.NewUsername.Trim() $fileUNC = "\\$($computer)\$($filePath.Replace(':', '$'))" Write-Host "Processing $($computer), new user '$($newUser)' ..." -NoNewline Try { $content = Get-Content -Path $fileUNC -ErrorAction Stop $content -replace $pattern, "`$1$($newUser)" | Set-Content -Path $fileUNC -Force -ErrorAction Stop Write-Host " OK" -ForegroundColor Green } Catch { Write-Host " FAILED: $($_.Exception.Message)" -ForegroundColor Red }}
What happens .. you already have the list of computers and users?
note any output-host won't work as it outputs to the active computers screen not the screen where it is called from
jskfan
ASKER
Yes I have CSV file that contains computer names.
I can make it text file if that's easier for you
The original question asks to help with: "Double-Click" an icon on the desktop with a Script, which I have answered.
jskfan
ASKER
Thanks INVIT
AUTHOR Commented: 2019-12-15
Perfect..it works fine on one computer
can you make it read computers from CSV and execute code for each computer
example from 'c:\Scripts\Computers.csv'
Qlemo
To simulate clicking on a desktop icon you need to log in remotely as the respective user. Quite difficult if that user happens to matter for "executing" the shortcut. Does it matter?
Is the shortcut target some kind of setup only ran for changing the user data stored in the changed file?
it is always the the Administrator account who logs in ... it is one time double-click by the Administrator account...and that is it
I need the script to "double-click" on an icon on each computer desktop( listed on csv file).
the double-click is triggered with Administrator account.
Thank you.
Can you comment each line of the code what it does ?