Any ideas about how to re-write this in powershell? Especially what means
"impersonationLevel=impersonate" and "\root\cimv2"?
http://msdn.microsoft.com/en-us/library/aa394601.aspx
Set objWMIService = GetObject("winmgmts:" _ &
"{impersonationLevel=impersonate}!\\" _ & strComputer & "\root\cimv2")
regards,
George
To get a listing, you simply need to do:
get-wmiobject win32_scheduledjob
Note: That you can only list jobs that are also created via WMI. If the
Windows Task Scheduler was used, you cannot view these via WMI.
However, you can view WMI created jobs via the Windows Task Scheduler,
but you should not modify them via the UI.
See also:
http://www.eggheadcafe.com/software/aspnet/32911381/gwmi-win32scheduledjob-.aspx
Marco
--
*Microsoft MVP - Admin Frameworks
https://mvp.support.microsoft.com/profile/Marco.Shaw
*Co-Author - Sams Windows PowerShell Unleashed 2nd Edition (due December
15th, 2008)
*PowerShell Co-Community Director - http://www.powershellcommunity.org
*Blog - http://marcoshaw.blogspot.com
ImpersonationLevel: http://msdn.microsoft.com/en-us/library/aa393852(VS.85).aspx
\root\cimv2 is the default namespace for the schema classes. These are the
primary classes for working with Windows-based operating systems.
You can list the classes for this namespace using the -list parameter:
PS > Get-WMIObject -list
To get just the win32_* classes:
Get-WMIObject -list | where {$_.name -like "win32_*"}
HTH
---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar: http://tinyurl.com/PSToolbar
G> Hello everyone,
G>
G> Any ideas about how to re-write this in powershell? Especially what
G> means "impersonationLevel=impersonate" and "\root\cimv2"?
G>
G> http://msdn.microsoft.com/en-us/library/aa394601.aspx
G>
G> Set objWMIService = GetObject("winmgmts:" _ &
G> "{impersonationLevel=impersonate}!\\" _ & strComputer &
G> "\root\cimv2")
G>
G> regards,
G> George
Do you have any ideas about how to re-write this following script into
powershell? Sorry for asking this stupid question, my knowledge about
vbscript is very limited. I like powershell actually -- but from search
Google I found vbscript samples are more than those of powershell. :-)
Set objWMIService = GetObject("winmgmts:" _ &
regards,
George
Two simple and stupid questions after reading your comments. :-)
1.
How to generate such time stamp string like this automatically
"********143000.000000-420"?
I want to generate a time stamp which is 12:00pm in current time zone. Is
there any automatically way to generate information like -420?
(i.e. when I deliver the script to my friends in other time zone, I want the
script to automatically generate what should be -420 in their time zone other
than calculate manually.)
2.
> Note: That you can only list jobs that are also created via WMI. If the
> Windows Task Scheduler was used, you cannot view these via WMI.
> However, you can view WMI created jobs via the Windows Task Scheduler,
> but you should not modify them via the UI.
A little confused. Could you review whether my current understandings are
correct?
- In Windows Task Scheduler, I can change and see tasks setup by Windows
Task Scheduler?
- In Windows Task Scheduler, I can see tasks setup by WMI, but can not modify?
- From get-wmiobject win32_scheduledjob, I can only see tasks scheduled by
wmi and can not see the ones scheduled by Windows Task Scheduler?
regards,
George
about impersonation - in powershell it is not required, because it is
enabled by default:
[vPodans] $TS.PSBase.Scope.Options
Locale :
Username :
Password :
SecurePassword :
Authority :
Impersonation : Impersonate
Authentication : Unchanged
EnablePrivileges : False
Context : {}
Timeout : 10675199.02:48:05.4775807
[vPodans] $ts.PSBase.Scope.Options
--
WBR Vadims Podans
PowerShell blog: www.sysadmins.lv
About impersonation setting, I am still confused. My confusion is I just run
the script, and the script should use the same account (privilege) which is
used to run it, why needs impersonation setting here? Could you show me a
sample about the practical usage of impersonation please?
regards,
George
If Impersonation level is set to Impersonate, then script will be run in
current user security context, which launch script. And this is enabled in
PowerShell by default. you can change this level (for example, set to
Anonymous or System. And system will try to authenticate you as anonymous
user or LocalSystem user). More information about this can be found here:
http://msdn.microsoft.com/en-us/library/ms691341(VS.85).aspx
http://msdn.microsoft.com/en-us/library/aa378832(VS.85).aspx
In practise I never used other impersonation levels. Only one thing what you
perhaps will use - SeSecurity privileges.
--
WBR Vadims Podans
PowerShell blog: www.sysadmins.lv
I checked again about the script you written before. You never set any user
account which will be used to run the job. Once I use your script to schedule
a job which runs daily, which accounts will it be run under?
--------------------
$TS = [WMIClass] "Win32_ScheduledJob"
$starttime = "********143000.000000-120"
$TS.Create("notepad.exe",$starttime,$true,16,$true,"Test")
--------------------
regards,
George
Seems like that there is no way to change security account under which job
will run. And remember that Impersonation Level is required only when you
access object.
--
WBR Vadims Podans
PowerShell blog: www.sysadmins.lv
1.
> About your last question:
> The Win32_ScheduledJob class is derived from CIM_Job. On Windows 2000, tasks
> started through Win32_ScheduledJob run under the LocalSystem account.
> However, in Windows XP Service Pack 1 (SP1) and Windows Server 2003, such
> tasks run under the NetworkServiceHost Account. (from MSDN)
Could you share links which mentions the account which scheduled job is run
at please? :-)
2.
>
> Seems like that there is no way to change security account under which job
> will run. And remember that Impersonation Level is required only when you
> access object.
> --
Great description! Let me clarify, I think you mean if I set
impersonationLevel=impersonate, then inside the implementation code of the
job itself, I could impersonate to other account other than
localsystm/NetworkServiceHost? And if in my code I do not implement any
impersonation code, the scheduled job will use the account
localsystm/NetworkServiceHost to access other resources? :-)
regards,
George