Link to home
Start Free TrialLog in
Avatar of jskfan
jskfanFlag 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

ASKER CERTIFIED SOLUTION
Avatar of NVIT
NVIT
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jskfan

ASKER

NVIT

Thank you.
Can you comment each line  of the code what it does ?
the code is already commented
Avatar of 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'
Avatar of jskfan

ASKER

any updates on this ?
Thank you
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
Avatar of 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.
Avatar of 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'
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?
Avatar of 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
Avatar of jskfan

ASKER

Thanks