开发者

C# Exchange Powershell specified cast not valid

开发者 https://www.devze.com 2022-12-22 23:52 出处:网络
I\'m getting a specified cast error trying to return a integer, example code below: results = pipeline.Invoke();

I'm getting a specified cast error trying to return a integer, example code below:

results = pipeline.Invoke();

foreach (PSObject ps in results)
{
int diff = 0;
Int32 exchcount = Convert.ToInt32(ps.Members["itemcount"].Value);
diff = itemcount - exchcount;
}

I'm trying to find out what the data type if for itemcount of the Get-Mailboxstatistics but i can't find the information, i assume it's I开发者_开发知识库nt, i've tried string but that does not work either. any ideas please let me know!

Thanks Steve


You can put breakpoin in the foreach cycle and see what type is ps.Members["itemcount"].Value (e.g. you can do ps.Members["itemcount"].Value.GetType() in the Immidiate window).


The error you are getting is at the foreach loop. The variable ps is declared of type PSObject while results might be something else (an array of object which are not of the correct type). Look at the type of the results variable.


i don't think it's the foreach statement, if i use a string type value like 'DisplayName' cmd value it works.. only for a value/int type it seems to fail. i'll try and check the break point to see the value type..

Thanks! ST

0

精彩评论

暂无评论...
验证码 换一张
取 消