Schedule a task with powershell to a list of computers
-
giovedì 28 giugno 2012 02:34
Hi guys, I really need some help here please. I am trying to schedule a task on remote computers using Powershell. I am new at scripting and this is code I've found on the net . Looks like this
$computers= Get-Content "c:\scripts\Computers.txt" `
| Where-Object { $_.Trim() -ne '' } #remove empty lines
foreach ($computers in $computers) {
"Creating task for $computers"
SCHTASKS /Create /ST 06:00 /SC MINUTE /MO 60 /TN AcadLicCheck /TR "'\\servername\Apps\Autodesk\Autocad\AutoCAD_Shared\Support\User_Lic_Open\Shell_Script_to_invoke_BAT_file.vbs'" /f /s $computers
}The script is creating at all the computers but looks like is creating under my username name. I want the task to be created under the current user that is logged on on that computer. Any idea how I can achieve that?
Thanks you very much in advance!
- Modificato StefanNZ giovedì 28 giugno 2012 02:43
Tutte le risposte
-
venerdì 29 giugno 2012 21:02
I don't think you can as the current user, unless you know that user's name, or want to poll the PC for the current logged in user.
Additionally, unless you know that user's password, the task will only run when the user is logged in.When I was working on the Windows PowerShell 2.0 Bible, I created a script that would let you specify the user account and password to run a task under.
Ping me at my email address, and I will try to dig it up.
Karl
When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer
My Blog: http://unlockpowershell.wordpress.com
My Book: Windows PowerShell 2.0 Bible
My E-mail: -join ("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"}) -
lunedì 2 luglio 2012 06:29Moderatore
Hi,
The below similar thread should be helpful:
Schedule a task with PowerShell
Regards,
Yan Li
Yan Li
TechNet Community Support
-
mercoledì 4 luglio 2012 02:59
Thanks guys, if I will type the command like this in Powershell is working:
SCHTASKS /Create /ST 06:00 /SC MINUTE /MO 60 /TN AcadLicCheck /TR "'\\strongerchch\public\Apps\Autodesk\Autocad\AutoCAD_Shared\Support\User_Lic_Open\Shell_Script_to_invoke_BAT_file.vbs'" /f /s computername /ru username
I don't have to know the user's password for that username
So I need some how to find the name of the current user that is logged on on that computer but I have no idea how to do that.
Thanks
- Modificato StefanNZ mercoledì 4 luglio 2012 03:15

