Avatar of jskfan
jskfan
Flag for Cyprus asked on

"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
	}
}

Open in new window

PowershellScripting Languages

Avatar of undefined
Last Comment
jskfan

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
NVIT

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
jskfan

ASKER
NVIT

Thank you.
Can you comment each line  of the code what it does ?
David Johnson, CD

the code is already commented
jskfan

ASKER
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'
Your help has saved me hundreds of hours of internet surfing.
fblack61
jskfan

ASKER
any updates on this ?
Thank you
David Johnson, CD

Invoke-Command -ComputerName Server01 -Credential Domain01\User01 -ScriptBlock { Get-Culture }

Open in new window


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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
NVIT

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?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
jskfan

ASKER
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
jskfan

ASKER
Thanks