![]() You can run your script like so #powershell script | Out-File "C:\Somedirectory\Somescript.ps1" -ErrorAction Silentl圜ontinue This does mean that there's a period where your password is stored in an easily read variable, which is why the last line of the script is to clear that variable. The important part is the top three lines that show you how to extract a username and password from a Get-Credential command, which you can store in a variable and pass it on to your task creation sequence. You can modify this to whatever you need. Register-ScheduledTask -TaskName $using:jobname -Action $using:A -Trigger $using:T -RunLevel Highest -User $using:username -Password $using:password Invoke-Command -ComputerName -ScriptBlock $T = New-ScheduledTaskTrigger -Daily -At 12am $A = New-ScheduledTaskAction -Execute "Powershell.exe" -Argument "-file C:\script.ps1" $cred = Get-Credential -Message "Enter credentials" Here's my script #Get username and password Register-ScheduledTask test -InputObject $task $task = New-ScheduledTask -Action $action -Principal $principal -Trigger $trigger -Settings $settings $settings = New-ScheduledTaskSettingsSet -Hidden -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries $principal = New-ScheduledTaskPrincipal -UserId $userid -RunLevel Highest $trigger = New-ScheduledTaskTrigger -AtLogOn ![]() $action = New-ScheduledTaskAction -Execute "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -Argument '-NoProfile -NoLogo -windowstyle Hidden -NonInteractive -ExecutionPolicy Bypass -file ""' So can anyone help me? $userid = Get-CimInstance –ClassName Win32_ComputerSystem | Select-Object -expand UserName But I'm not sure about that and there's also not a parameter for the password. I also read something that you've to enter the password to make sure that this checkbox will be enabled. This will work after enabling "run whether user is logged on or not". The only thing I want is to run it hidden. ![]() Research Triangle Powershell User Group remote-capableīelow you'll see the commands to create a scheduled task.Philadelphia PowerShell User Group remote-capable.Madison Power Users Group remote-capable.Denver Microsoft Enterprise Management User Group.NET, POSH is a full-featured task automation framework for distributed Microsoft platforms and solutions. Windows PowerShell (POSH) is a command-line shell and associated scripting language created by Microsoft. Submission Guidelines | Link Flair - How To
0 Comments
Leave a Reply. |