Mike
asked on
Need help with a PowerShell Script
Greeting Experts,
I need help updating the following script below with a function to ask for the user's credentials before starting the script. The purpose of the script is to copy files from a UNC path and copy them to a list of pc's in a text file, then execute the command to install the software. Can somebody help me with this script? .
I need help updating the following script below with a function to ask for the user's credentials before starting the script. The purpose of the script is to copy files from a UNC path and copy them to a list of pc's in a text file, then execute the command to install the software. Can somebody help me with this script? .
$computers = Get-Content -“Path C:\Computers.txt"
foreach ($pc in $computers) {
{
Copy-Item "\\domain.com\ens_software\deployment\Folder\program.exe" -Destination "\\$pc\c$\Folder" -Force -Recurse
Invoke-Command -ComputerName $pc -ScriptBlock {"C:\Folder\program.exe /install /quiet /norestart "}
}
Remove-Item -Path "\\$pc\c$\Folder"
In the second case you should add a prompt containing the computer name:
$credential =Get-Credential -Message "Login for $pc"
BTW you should not store data in variables if you do not need to. Your first two lines can be compressed to the following without losing anything:foreach ($pc in Get-Content -Path 'C:\Computers.txt') {
Your first line is wrong anyway, the double quotes must surround the path instead of the complete option:Get-Content -Path "C:\Computers.txt"
ASKER
Thanks
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Open in new window
or here?Open in new window