本文整理汇总了C#中System.Management.Automation.PSObject类的典型用法代码示例。如果您正苦于以下问题:C# PSObject类的具体用法?C# PSObject怎么用?C# PSObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PSObject类属于System.Management.Automation命名空间,在下文中一共展示了PSObject类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ConvertToCanPackAsPSObjectArray
public void ConvertToCanPackAsPSObjectArray()
{
var result = LanguagePrimitives.ConvertTo(3, typeof(PSObject[]));
var expected = new PSObject[] { PSObject.AsPSObject(3) };
Assert.AreEqual(expected.GetType(), result.GetType());
Assert.AreEqual(expected, result);
}
开发者ID:jagrem,项目名称:Pash,代码行数:7,代码来源:LanguagePrimitivesTests.cs
示例2: ConvertToReturnObject
private Object ConvertToReturnObject(object currentObject)
{
List<Object> currentAsArray = currentObject as List<Object>;
if(currentAsArray != null)
{
PSObject[] result = new PSObject[currentAsArray.Count];
for(int currentIndex = 0; currentIndex < currentAsArray.Count; currentIndex++)
{
result[currentIndex] = (PSObject) ConvertToReturnObject(currentAsArray[currentIndex]);
}
return result;
}
OrderedDictionary currentAsDictionary = currentObject as OrderedDictionary;
if (currentAsDictionary != null)
{
PSObject result = new PSObject();
foreach (string key in currentAsDictionary.Keys)
{
result.Properties.Add(new PSNoteProperty(key, ConvertToReturnObject(currentAsDictionary[key])));
}
return result;
}
return currentObject;
}
开发者ID:JamesHabben,项目名称:PowerForensics,代码行数:29,代码来源:BinShredCommand.cs
示例3: Deserialize
internal override void Deserialize(PSObject so, FormatObjectDeserializer deserializer)
{
base.Deserialize(so, deserializer);
this.leftIndentation = deserializer.DeserializeIntMemberVariable(so, "leftIndentation");
this.rightIndentation = deserializer.DeserializeIntMemberVariable(so, "rightIndentation");
this.firstLine = deserializer.DeserializeIntMemberVariable(so, "firstLine");
}
开发者ID:nickchal,项目名称:pash,代码行数:7,代码来源:FrameInfo.cs
示例4: ProcessRecord
protected override void ProcessRecord()
{
base.ProcessRecord();
if (Globals.authToken != null)
{
_serverProxy = new ServerCommandProxy(Globals.ComputerName, Globals.Port, Globals.authToken);
try
{
_serverProxy.AddAdminAccessUser(UserName);
PSObject returnAddPcutAdminAccessUser = new PSObject();
returnAddPcutAdminAccessUser.Properties.Add(new PSNoteProperty("Username", UserName));
returnAddPcutAdminAccessUser.Properties.Add(new PSNoteProperty("AdminAccess", true));
WriteObject(returnAddPcutAdminAccessUser);
}
catch (XmlRpcFaultException fex)
{
ErrorRecord errRecord = new ErrorRecord(new Exception(fex.Message, fex.InnerException), fex.FaultString, ErrorCategory.NotSpecified, fex);
WriteError(errRecord);
}
}
else
{
WriteObject("Please run Connect-PcutServer in order to establish connection.");
}
}
开发者ID:Polgy,项目名称:mod-posh,代码行数:25,代码来源:PcutCmdlets.cs
示例5: UpdateGroupingKeyValue
/// <summary>
/// compute the string value of the grouping property
/// </summary>
/// <param name="so">object to use to compute the property value</param>
/// <returns>true if there was an update</returns>
internal bool UpdateGroupingKeyValue(PSObject so)
{
if (_groupingKeyExpression == null)
return false;
List<MshExpressionResult> results = _groupingKeyExpression.GetValues(so);
// if we have more that one match, we have to select the first one
if (results.Count > 0 && results[0].Exception == null)
{
// no exception got thrown, so we can update
object newValue = results[0].Result;
object oldValue = _currentGroupingKeyPropertyValue;
_currentGroupingKeyPropertyValue = newValue;
// now do the comparison
bool update = !(IsEqual(_currentGroupingKeyPropertyValue, oldValue) ||
IsEqual(oldValue, _currentGroupingKeyPropertyValue));
if (update && _label == null)
{
_groupingKeyDisplayName = results[0].ResolvedExpression.ToString();
}
return update;
}
// we had no matches or we could not get the value:
// NOTICE: we need to do this to avoid starting a new group every time
// there is a failure to read the grouping property.
// For example, for AD, there are objects that throw when trying
// to read the "distinguishedName" property (used by the brokered property "ParentPath)
return false;
}
开发者ID:dfinke,项目名称:powershell,代码行数:39,代码来源:FormatGroupManager.cs
示例6: Deserialize
internal override void Deserialize(PSObject so, FormatObjectDeserializer deserializer)
{
base.Deserialize(so, deserializer);
this.label = deserializer.DeserializeStringMemberVariable(so, "label");
this.propertyName = deserializer.DeserializeStringMemberVariable(so, "propertyName");
this.formatPropertyField = (FormatPropertyField) deserializer.DeserializeMandatoryMemberObject(so, "formatPropertyField");
}
开发者ID:nickchal,项目名称:pash,代码行数:7,代码来源:ListViewField.cs
示例7: SetupActiveProperties
internal static List<MshResolvedExpressionParameterAssociation> SetupActiveProperties(List<MshParameter> rawMshParameterList,
PSObject target, MshExpressionFactory expressionFactory)
{
// check if we received properties from the command line
if (rawMshParameterList != null && rawMshParameterList.Count > 0)
{
return AssociationManager.ExpandParameters(rawMshParameterList, target);
}
// we did not get any properties:
//try to get properties from the default property set of the object
List<MshResolvedExpressionParameterAssociation> activeAssociationList = AssociationManager.ExpandDefaultPropertySet(target, expressionFactory);
if (activeAssociationList.Count > 0)
{
// we got a valid set of properties from the default property set..add computername for
// remoteobjects (if available)
if (PSObjectHelper.ShouldShowComputerNameProperty(target))
{
activeAssociationList.Add(new MshResolvedExpressionParameterAssociation(null,
new MshExpression(RemotingConstants.ComputerNameNoteProperty)));
}
return activeAssociationList;
}
// we failed to get anything from the default property set
// just get all the properties
activeAssociationList = AssociationManager.ExpandAll(target);
// Remove PSComputerName and PSShowComputerName from the display as needed.
AssociationManager.HandleComputerNameProperties(target, activeAssociationList);
return activeAssociationList;
}
开发者ID:40a,项目名称:PowerShell,代码行数:34,代码来源:MshParameterAssociation.cs
示例8: ToPSObjectForRemoting
internal static void ToPSObjectForRemoting(CommandInfo commandInfo, PSObject psObject)
{
RemotingEncoder.ValueGetterDelegate<CommandTypes> valueGetter = null;
RemotingEncoder.ValueGetterDelegate<string> delegate3 = null;
RemotingEncoder.ValueGetterDelegate<string> delegate4 = null;
RemotingEncoder.ValueGetterDelegate<SessionStateEntryVisibility> delegate5 = null;
if (commandInfo != null)
{
if (valueGetter == null)
{
valueGetter = () => commandInfo.CommandType;
}
RemotingEncoder.AddNoteProperty<CommandTypes>(psObject, "CommandInfo_CommandType", valueGetter);
if (delegate3 == null)
{
delegate3 = () => commandInfo.Definition;
}
RemotingEncoder.AddNoteProperty<string>(psObject, "CommandInfo_Definition", delegate3);
if (delegate4 == null)
{
delegate4 = () => commandInfo.Name;
}
RemotingEncoder.AddNoteProperty<string>(psObject, "CommandInfo_Name", delegate4);
if (delegate5 == null)
{
delegate5 = () => commandInfo.Visibility;
}
RemotingEncoder.AddNoteProperty<SessionStateEntryVisibility>(psObject, "CommandInfo_Visibility", delegate5);
}
}
开发者ID:nickchal,项目名称:pash,代码行数:30,代码来源:RemoteCommandInfo.cs
示例9: ToPsObject
/// <summary>
/// Converts a <see cref="JObject"/> to a <see cref="PSObject"/>
/// </summary>
/// <param name="jtoken">The <see cref="JObject"/></param>
/// <param name="objectType">The type of the object.</param>
internal static PSObject ToPsObject(this JToken jtoken, string objectType = null)
{
if (jtoken == null)
{
return null;
}
if (jtoken.Type != JTokenType.Object)
{
return new PSObject(JTokenExtensions.ConvertPropertyValueForPsObject(propertyValue: jtoken));
}
var jobject = (JObject)jtoken;
var psObject = new PSObject();
if (!string.IsNullOrWhiteSpace(objectType))
{
psObject.TypeNames.Add(objectType);
}
foreach (var property in jobject.Properties())
{
psObject.Properties.Add(new PSNoteProperty(
name: property.Name,
value: JTokenExtensions.ConvertPropertyValueForPsObject(propertyValue: property.Value)));
}
return psObject;
}
开发者ID:Azure,项目名称:azure-powershell,代码行数:34,代码来源:JTokenExtensions.cs
示例10: PSEventArgs
internal PSEventArgs(string computerName, Guid runspaceId, int eventIdentifier, string sourceIdentifier, object sender, object[] originalArgs, PSObject additionalData)
{
if (originalArgs != null)
{
foreach (object obj2 in originalArgs)
{
EventArgs args = obj2 as EventArgs;
if (args != null)
{
this.sourceEventArgs = args;
break;
}
if (ForwardedEventArgs.IsRemoteSourceEventArgs(obj2))
{
this.sourceEventArgs = new ForwardedEventArgs((PSObject) obj2);
break;
}
}
}
this.computerName = computerName;
this.runspaceId = runspaceId;
this.eventIdentifier = eventIdentifier;
this.sender = sender;
this.sourceArgs = originalArgs;
this.sourceIdentifier = sourceIdentifier;
this.timeGenerated = DateTime.Now;
this.data = additionalData;
this.forwardEvent = false;
}
开发者ID:nickchal,项目名称:pash,代码行数:29,代码来源:PSEventArgs.cs
示例11: ExecutableNodeFactory
public ExecutableNodeFactory(Executable executable,Executables collection)
{
_collection = collection;
_executable = (DtsContainer)executable;
_host = _executable as TaskHost;
_seq = _executable as Sequence;
_foreachloop = _executable as ForEachLoop;
_forloop = _executable as ForLoop;
_psExecutable = PSObject.AsPSObject(_executable);
if (null != _host)
{
_psExecutable.Properties.Add( new PSNoteProperty( "IsTaskHost", true ));
_mainPipe = _host.InnerObject as MainPipe;
}
if (null != _mainPipe)
{
_psExecutable.Properties.Add(new PSNoteProperty("IsDataFlow", true));
}
if (null != _seq)
{
_psExecutable.Properties.Add(new PSNoteProperty("IsSequence", true));
}
if (null != _foreachloop)
{
_psExecutable.Properties.Add(new PSNoteProperty("IsForEachLoop", true));
}
if (null != _forloop)
{
_psExecutable.Properties.Add(new PSNoteProperty("IsForLoop", true));
}
}
开发者ID:beefarino,项目名称:bips,代码行数:32,代码来源:ExecutableNodeFactory.cs
示例12: ExpandAll
internal static List<MshResolvedExpressionParameterAssociation> ExpandAll(PSObject target)
{
List<string> propertyNamesFromView = GetPropertyNamesFromView(target, PSMemberViewTypes.Adapted);
List<string> list2 = GetPropertyNamesFromView(target, PSMemberViewTypes.Base);
List<string> collection = GetPropertyNamesFromView(target, PSMemberViewTypes.Extended);
List<string> list4 = new List<string>();
if (propertyNamesFromView.Count != 0)
{
list4 = propertyNamesFromView;
}
else
{
list4 = list2;
}
list4.AddRange(collection);
Dictionary<string, object> dictionary = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
List<MshResolvedExpressionParameterAssociation> list5 = new List<MshResolvedExpressionParameterAssociation>();
foreach (string str in list4)
{
if (!dictionary.ContainsKey(str))
{
dictionary.Add(str, null);
MshExpression expression = new MshExpression(str, true);
list5.Add(new MshResolvedExpressionParameterAssociation(null, expression));
}
}
return list5;
}
开发者ID:nickchal,项目名称:pash,代码行数:28,代码来源:AssociationManager.cs
示例13: ProcessRecord
protected override void ProcessRecord()
{
base.ProcessRecord();
string Filter = "(&(objectCategory=group)(name=" + Name + "))";
string Scope = "Subtree";
string[] Properties = null;
SearchResultCollection AdGroupObject = Utilities.Functions.QueryAD(Path, Filter, Scope, Properties);
foreach (SearchResult Group in AdGroupObject)
{
foreach (string Member in Group.Properties["member"])
{
foreach (SearchResult AdObject in (Utilities.Functions.QueryAD("LDAP://" + Member, "", "Base", null)))
{
WriteVerbose("Create PowerShell object to hold return values");
PSObject objReturn = new PSObject();
WriteVerbose("Add AdObject.Properties to PowerShell object");
foreach (string AdProperty in AdObject.Properties.PropertyNames)
{
WriteDebug("Add property : " + AdProperty);
objReturn.Properties.Add(new PSNoteProperty(AdProperty, (AdObject.Properties[AdProperty])[0]));
}
WriteObject(objReturn);
}
}
}
}
开发者ID:Polgy,项目名称:mod-posh,代码行数:27,代码来源:cmdLets.cs
示例14: AddProperties
private void AddProperties(PSObject psobj)
{
foreach (var keyObj in Property.Keys)
{
var key = keyObj.ToString(); // should be a string anyway
var member = psobj.Members[key];
if (member == null)
{
if (psobj.BaseObject is PSCustomObject)
{
var noteProperty = new PSNoteProperty(key, Property[key]);
AddMemberToCollection(psobj.Properties, noteProperty, false);
AddMemberToCollection(psobj.Members, noteProperty, false);
}
else
{
var msg = String.Format("A member with the name {0} doesn't exist", key);
WriteError(new PSInvalidOperationException(msg).ErrorRecord);
}
}
else if (member is PSMethodInfo)
{
var method = member as PSMethodInfo;
method.Invoke(Property[key]);
}
else if (member is PSPropertyInfo)
{
var psproperty = member as PSPropertyInfo;
psproperty.Value = Property[key];
}
}
}
开发者ID:Ventero,项目名称:Pash,代码行数:32,代码来源:NewObjectCommand.cs
示例15: ProcessRecord
public IEnumerable<String> ProcessRecord(PSObject record)
{
if (record == null)
{
yield break;
}
if (_raw)
{
yield return record.ToString();
}
else
{
if (_pipeline == null)
{
_pipeline = CreatePipeline();
_pipeline.InvokeAsync();
}
_pipeline.Input.Write(record);
foreach (PSObject result in _pipeline.Output.NonBlockingRead())
{
yield return result.ToString();
}
}
}
开发者ID:nickchal,项目名称:pash,代码行数:27,代码来源:OutStringFormatter.cs
示例16: GetActiveWideControlEntryDefinition
private WideControlEntryDefinition GetActiveWideControlEntryDefinition(WideControlBody wideBody, PSObject so)
{
ConsolidatedString internalTypeNames = so.InternalTypeNames;
TypeMatch match = new TypeMatch(base.expressionFactory, base.dataBaseInfo.db, internalTypeNames);
foreach (WideControlEntryDefinition definition in wideBody.optionalEntryList)
{
if (match.PerfectMatch(new TypeMatchItem(definition, definition.appliesTo)))
{
return definition;
}
}
if (match.BestMatch != null)
{
return (match.BestMatch as WideControlEntryDefinition);
}
Collection<string> typeNames = Deserializer.MaskDeserializationPrefix(internalTypeNames);
if (typeNames != null)
{
match = new TypeMatch(base.expressionFactory, base.dataBaseInfo.db, typeNames);
foreach (WideControlEntryDefinition definition2 in wideBody.optionalEntryList)
{
if (match.PerfectMatch(new TypeMatchItem(definition2, definition2.appliesTo)))
{
return definition2;
}
}
if (match.BestMatch != null)
{
return (match.BestMatch as WideControlEntryDefinition);
}
}
return wideBody.defaultEntryDefinition;
}
开发者ID:nickchal,项目名称:pash,代码行数:33,代码来源:WideViewGenerator.cs
示例17: BuildHostLevelPSObjectArrayList
private PSObject BuildHostLevelPSObjectArrayList(object objSessionObject, string uri, bool IsWsManLevel)
{
PSObject obj2 = new PSObject();
if (IsWsManLevel)
{
foreach (string str in WSManHelper.GetSessionObjCache().Keys)
{
obj2.Properties.Add(new PSNoteProperty(str, "Container"));
}
return obj2;
}
if (objSessionObject != null)
{
foreach (XmlNode node in this.GetResourceValue(objSessionObject, uri, null).ChildNodes)
{
foreach (XmlNode node2 in node.ChildNodes)
{
if ((node2.ChildNodes.Count == 0) || node2.FirstChild.Name.Equals("#text", StringComparison.OrdinalIgnoreCase))
{
obj2.Properties.Add(new PSNoteProperty(node2.LocalName, node2.InnerText));
}
}
}
}
foreach (string str2 in WinRmRootConfigs)
{
obj2.Properties.Add(new PSNoteProperty(str2, "Container"));
}
return obj2;
}
开发者ID:nickchal,项目名称:pash,代码行数:30,代码来源:WSManConfigProvider.cs
示例18: GetStream
/// <summary>
/// A function which returns a Stream object which encapsulates an IStream interface
/// This makes it much easier to get the file contents in managed code / powershell
/// </summary>
/// <param name="parentObject">This will be the PSObject that encapsulates a IFsrmPropertyBag</param>
/// <returns>A stream which wraps the parentObject's IStream</returns>
public static StreamWrapperForIStream GetStream(PSObject parentObject)
{
IFsrmPropertyBag propertyBag = (IFsrmPropertyBag)parentObject.BaseObject;
IStream istream = (IStream)propertyBag.GetFileStreamInterface(_FsrmFileStreamingMode.FsrmFileStreamingMode_Read, _FsrmFileStreamingInterfaceType.FsrmFileStreamingInterfaceType_IStream );
return new StreamWrapperForIStream(istream);
}
开发者ID:dbremner,项目名称:Windows-classic-samples,代码行数:13,代码来源:PowerShellRuleHoster.cs
示例19: EnsurePropertyInfoPathExists
internal static void EnsurePropertyInfoPathExists(PSObject psObject, string[] path)
{
if (path.Length > 0)
{
for (int i = 0; i < path.Length; i++)
{
string name = path[i];
PSPropertyInfo member = psObject.Properties[name];
if (member == null)
{
object obj2 = (i < (path.Length - 1)) ? new PSObject() : null;
member = new PSNoteProperty(name, obj2);
psObject.Properties.Add(member);
}
if (i == (path.Length - 1))
{
return;
}
if ((member.Value == null) || !(member.Value is PSObject))
{
member.Value = new PSObject();
}
psObject = (PSObject) member.Value;
}
}
}
开发者ID:nickchal,项目名称:pash,代码行数:26,代码来源:MamlUtil.cs
示例20: PSObjectProxy
public PSObjectProxy(PSObject target)
{
if (target == null)
throw new ArgumentNullException("target");
m_target = target;
}
开发者ID:urasandesu,项目名称:Pontine,代码行数:7,代码来源:PSObjectProxy.cs
注:本文中的System.Management.Automation.PSObject类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论