The Follow script worked fine under win 7 with no issues, but when I loaded my app on windows 8 to see what all was broken I found that this script would no longer work correctly. Its a very simple script to load up user exchange Mailbox for searching if the user has a mailbox within a larger app. It’s actually written in python because I use IronPython as a plugin system.
password = SecureString()
str_password = "PASSWORD"
str_user = "EXCHUSER"
uri = "http://" + exchangeServerIP + "/PowerShell"
for c in str_password:
password.AppendChar(c)
creds = PSCredential(str_user, password)
connectionInfo = WSManConnectionInfo(Uri(uri), "http://schemas.microsoft.com/powershell/Microsoft.Exchange", creds)
connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Basic
runspace = RunspaceFactory.CreateRunspace(connectionInfo)
runspace.Open()
powershell = PowerShell.Create()
powershell.AddCommand("Get-Mailbox")
if self.txtUsername.Text != "*":
powershell.AddParameter("Identity", self.txtUsername.Text)
powershell.AddParameter("ResultSize", "Unlimited")
powershell.Runspace = runspace
results = powershell.Invoke()
if results == None or results.Count <= 0:
MessageBox.Show("No mailboxes can be found!")
runspace.Close()
runspace.Dispose()
powershell.Dispose()
return
self.dataGridView1.Rows.Clear()
for result in results:
>>>>>>> if result.Properties != None: (ERROR HERE) <<<<<<<
if result.Properties["Name"] != None:
if result.Properties["Name"].Value != None:
System.Console.WriteLine(result.Properties["Name"].Value.ToString())
runspace.Dispose()
runspace.Close()
runspace = None
powershell.Dispose()
powershell = None
connectionInfo = None
I have marked where I get the error saying the result.Properties is NoneType which when debugging I can see that it is populated and the correct results are there. Not sure if windows 8 / .net 4.5 is the cause of the issue but works fine under win 7 exact code no null value. Any Suggestions would help greatly.
Updated (Answer):
After constant digging I finally found that the issue was with Powershell 3. Access the Members on using Powershell 2 with IronPython I could use result.Members[“Name”].Value but with Powershell 3 and the DLR, IronPython will return null value on result.Members Collection so I have to call it as result.Name. (Where result = PSObject)
Let me know what error you are getting during compilation of ur above code.
Also
1.First check whether your code sdk version matches with your current software version.
2.The code/app which are developed using visual studio 2008/09/10/11 wont work in visual studio 2012.
3.If you copied the windows 7 app files to compile it in win8,it wont work.just create/code it from first in vs 2012.