Solved

PS 3 unexpected results shown on screen

Posted on 2013-12-26
2
245 Views
Last Modified: 2013-12-29
While my program is running (uses invoke-sql, export-csv) it periodically spits this information out to the console and I do not know what is causing it???

Module                     : CommonLanguageRuntimeLibrary
Assembly                   : mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
TypeHandle                 : System.RuntimeTypeHandle
DeclaringMethod            :
BaseType                   : System.Object
UnderlyingSystemType       : System.Exception
FullName                   : System.Exception
AssemblyQualifiedName      : System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Namespace                  : System
GUID                       : a1c0a095-df97-3441-bfc1-c9f194e494db
IsEnum                     : False
GenericParameterAttributes :
IsSecurityCritical         : False
IsSecuritySafeCritical     : False
IsSecurityTransparent      : True
IsGenericTypeDefinition    : False
IsGenericParameter         : False
GenericParameterPosition   :
IsGenericType              : False
IsConstructedGenericType   : False
ContainsGenericParameters  : False
StructLayoutAttribute      : System.Runtime.InteropServices.StructLayoutAttribute
Name                       : Exception
MemberType                 : TypeInfo
DeclaringType              :
ReflectedType              :
MetadataToken              : 33554437
GenericTypeParameters      : {}
DeclaredConstructors       : {Void .ctor(), Void .ctor(System.String), Void .ctor(System.String, System.Exception), Void
                             .ctor(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)...}
DeclaredEvents             : {System.EventHandler`1[System.Runtime.Serialization.SafeSerializationEventArgs] SerializeObjectState}
DeclaredFields             : {_className, _exceptionMethod, _exceptionMethodString, _message...}
DeclaredMembers            : {System.String get_Message(), Void
                             add_SerializeObjectState(System.EventHandler`1[System.Runtime.Serialization.SafeSerializationEventArgs]), Void
                             remove_SerializeObjectState(System.EventHandler`1[System.Runtime.Serialization.SafeSerializationEventArgs]), System.Collections.IDictionary
                             get_Data()...}
DeclaredMethods            : {System.String get_Message(), Void
                             add_SerializeObjectState(System.EventHandler`1[System.Runtime.Serialization.SafeSerializationEventArgs]), Void
                             remove_SerializeObjectState(System.EventHandler`1[System.Runtime.Serialization.SafeSerializationEventArgs]), System.Collections.IDictionary
                             get_Data()...}
DeclaredNestedTypes        : {System.Exception+__RestrictedErrorObject, System.Exception+ExceptionMessageKind}
DeclaredProperties         : {System.String Message, System.Collections.IDictionary Data, System.Exception InnerException, System.Reflection.MethodBase TargetSite...}
ImplementedInterfaces      : {System.Runtime.Serialization.ISerializable, System.Runtime.InteropServices._Exception}
TypeInitializer            : Void .cctor()
IsNested                   : False
Attributes                 : AutoLayout, AnsiClass, Class, Public, Serializable, BeforeFieldInit
IsVisible                  : True
IsNotPublic                : False
IsPublic                   : True
IsNestedPublic             : False
IsNestedPrivate            : False
IsNestedFamily             : False
IsNestedAssembly           : False
IsNestedFamANDAssem        : False
IsNestedFamORAssem         : False
IsAutoLayout               : True
IsLayoutSequential         : False
IsExplicitLayout           : False
IsClass                    : True
IsInterface                : False
IsValueType                : False
IsAbstract                 : False
IsSealed                   : False
IsSpecialName              : False
IsImport                   : False
IsSerializable             : True
IsAnsiClass                : True
IsUnicodeClass             : False
IsAutoClass                : False
IsArray                    : False
IsByRef                    : False
IsPointer                  : False
IsPrimitive                : False
IsCOMObject                : False
HasElementType             : False
IsContextful               : False
IsMarshalByRef             : False
GenericTypeArguments       : {}
CustomAttributes           : {[System.SerializableAttribute()],
                             [System.Runtime.InteropServices.ClassInterfaceAttribute((System.Runtime.InteropServices.ClassInterfaceType)0)],
                             [System.Runtime.InteropServices.ComDefaultInterfaceAttribute(typeof(System.Runtime.InteropServices._Exception))],
                             [System.Runtime.InteropServices.ComVisibleAttribute((Boolean)True)]...}
0
Comment
Question by:johnj_01201
2 Comments
 
LVL 1

Author Comment

by:johnj_01201
ID: 39742482
This appears to have been caused by a line that reads:
$CSVRecord
which is inside a foreach($CSVRecord in $CSV) loop, and $CSV is the result of an invoke-sql statement.

It seems that sometimes the $CSVRecord is NULL and displays the above information, however I thought that was impossible seeing how I was in a foreach loop...
0
 
LVL 40

Accepted Solution

by:
footech earned 500 total points
ID: 39745238
however I thought that was impossible seeing how I was in a foreach loop
Not at all.  If $CSV is an array which includes elements that are null, then $CSVRecord will sometimes be null.
Best way around this is to filter or perform some validation of the results before they are stored in $CSV.
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question