Answered by:
Powershell command get-job gives inconsistent results

Question
-
Hi
I am doing som estorage migrations and trying to schedule a script to alert when the miration is complete. Im trying to run the following:
get-job -vmmserver server1 | where {$_.Description -like "*Move*"}Sometimes when i run it i get the VM Name as the ResultName. Other times it just says Object Deleted. Any idea why?
Thanks
RichardThursday, May 19, 2011 8:09 AM
Answers
-
Hi Richard,
The ResultName field is calculated from a pointer to the job's result object. In order to display the name of the result object, we try to resolve the pointer to an object that exists in the client's local cache. The "Object Deleted" text will be displayed whenever we fail to find the result object in the cache.
We can fail to find the object in the client's cache for two reasons: 1) the object no longer exists; or 2) the object has not yet been pushed to the client's cache. The cache is empty when you first open the PowerShell window, and it accumulates as you call Get-* cmdlets, or when the server decides to send a notification for an object.
I believe the behaviour you're seeing is due to the VM objects not existing in the cache at the time you call Get-Job. Try calling Get-VM before Get-Job to verify that this is the case. For example:
PS> Get-VM
PS> get-job -vmmserver scvmmserver01 | where {$_.Description -like "*Move*"} | sele
ct Description,ResultName- Marked as answer by Carmen SummersMicrosoft employee Tuesday, June 7, 2011 9:35 PM
Tuesday, June 7, 2011 6:13 PM
All replies
-
A perfect example just happened. See below!!!!
PS C:\Users\me> get-job -vmmserver scvmmserver01 | where {$_.Description -like "*Move*"} | sele
ct Description,ResultNameDescription ResultName
----------- ----------
Move virtual machine from server-B05.msvs.n... Object Deleted
Move virtual machine from server-B05.msvs.n... Object Deleted
Move virtual machine from server-B05.msvs.n... Object Deleted
Move virtual machine from server-B05.msvs.n... Object Deleted
Move virtual machine from server-b07.msvs.n... Object Deleted
Move virtual machine from server-b07.msvs.n... Object Deleted
Move virtual machine from server-b06.msvs.n... Object Deleted
Move virtual machine from server-B02.msvs.n... Object Deleted
PS C:\Users\me> get-job -vmmserver scvmmserver01 | where {$_.Description -like "*Move*"} | sele
ct Description,ResultNameDescription ResultName
----------- ----------
Move virtual machine from server-B05.msvs.n... VM166np
Move virtual machine from server-B05.msvs.n... VM189nc
Move virtual machine from server-B05.msvs.n... VM188nw
Move virtual machine from server-B05.msvs.n... VM180nc
Move virtual machine from server-b07.msvs.n... VM166np
Move virtual machine from server-b07.msvs.n... VM189nc
Move virtual machine from server-b06.msvs.n... VM188nw
Move virtual machine from server-B02.msvs.n... VM180nc
PS C:\Users\me>Thursday, May 19, 2011 8:17 AM -
The GUI has results like this as well, they just don't show "object deleted"
I would like a MSFT persion to jump in, but I think what you are seeing is the result of hte last command executed within the job workflow. ResultName is the result of the last action - the return code, not the current status.
In the case of a Move, there are new objects being created, objects copied, and objects deleted. So, I would expect a return of 'something deleted' at some point in the process.
It is really the peorson who wrote or tested the cmdlet that can truely explain the result. I am hoping they will jump in.
Brian Ehlert (hopefully you have found this useful) http://ITProctology.blogspot.comThursday, May 19, 2011 2:51 PM -
Thanks for the response Brian.
If what i was seeing was the result of the last action, then why would it change randomly?
What i seem to be seeing is that it will show object deleted for most of the time. Then will randomly change to the vm name. After this point it will give me the vmname each time. Please note that i have not tested this exhaustivly as i too would like someone from MS to get involved first.
Monday, May 23, 2011 10:23 AM -
Hi Richard,
The ResultName field is calculated from a pointer to the job's result object. In order to display the name of the result object, we try to resolve the pointer to an object that exists in the client's local cache. The "Object Deleted" text will be displayed whenever we fail to find the result object in the cache.
We can fail to find the object in the client's cache for two reasons: 1) the object no longer exists; or 2) the object has not yet been pushed to the client's cache. The cache is empty when you first open the PowerShell window, and it accumulates as you call Get-* cmdlets, or when the server decides to send a notification for an object.
I believe the behaviour you're seeing is due to the VM objects not existing in the cache at the time you call Get-Job. Try calling Get-VM before Get-Job to verify that this is the case. For example:
PS> Get-VM
PS> get-job -vmmserver scvmmserver01 | where {$_.Description -like "*Move*"} | sele
ct Description,ResultName- Marked as answer by Carmen SummersMicrosoft employee Tuesday, June 7, 2011 9:35 PM
Tuesday, June 7, 2011 6:13 PM