PoshCode Archive  Artifact [9717b883ce]

Artifact 9717b883ce002708848a7fda181aded8868533a9b083b47caa58ac25116d1d82:

  • File IADsDNWithBinary-Cmdlet.ps1 — part of check-in [9fa30cd0df] at 2018-06-10 12:56:47 on branch trunk — I cooked this up to configure OCS user policy, but it should work for other attributes of this type as well. Added example for the read operation since it is picky about casting. (user: Ecmaster76 size: 2867)

# encoding: ascii
# api: csharp
# title: IADsDNWithBinary Cmdlet
# description: I cooked this up to configure OCS user policy, but it should work for other attributes of this type as well. Added example for the read operation since it is picky about casting.
# version: 0.1
# type: class
# author: Ecmaster76
# license: CC0
# x-poshcode-id: 1281
# x-archived: 2009-08-25T01:00:22
#
#
//Adapted from code @ http://mow001.blogspot.com/2006/01/msh-snap-in-to-translate.html Thanks!

using System;
using System.ComponentModel;
using System.Management.Automation;
using System.Reflection;
using System.Diagnostics;


namespace space
{
    // This class defines the properties of a snap-in 
    [RunInstaller(true)]
    public class readIADsDNWithBinary : PSSnapIn
    {
        /// Creates instance of Snapin class. 
        public readIADsDNWithBinary() : base() { }
        ///Snapin name is used for registration 
        public override string Name
        { get { return "readIADsDNWithBinary"; } }
        /// Gets description of the snap-in.  
        public override string Description
        { get { return "Reads a IADsDNWithBinary"; } }
        public override string Vendor
        { get { return "Andrew"; } } 

    }
    /// Gets a IADsDNWithBinary ex: Read-IADsDNWithBinary $user.directoryentry."msRTCSIP-UserPolicy"[0]
    [Cmdlet("Read", "IADsDNWithBinary")]
    public class readIADsDNWithBinaryCommand : Cmdlet
    {
        [Parameter(Position = 0, Mandatory = true)]
        public object DNWithBinary
        {
            get { return DNWithBin; }
            set { DNWithBin = value; }
        }

        private object DNWithBin;

        protected override void EndProcessing()
        {
            ActiveDs.IADsDNWithBinary DNB = (ActiveDs.IADsDNWithBinary)DNWithBin;
            ActiveDs.DNWithBinary boink = new ActiveDs.DNWithBinaryClass();
            boink.BinaryValue = (byte[])DNB.BinaryValue;
            boink.DNString = DNB.DNString;
            WriteObject(boink);
        }
    }
    /// Sets a IADsDNWithBinary
    [Cmdlet("Write", "IADsDNWithBinary")]
    public class writeIADsDNWithBinaryCommand : Cmdlet
    {
        [Parameter(Mandatory = true)]
        public byte[] Bin
        {
            get { return bin; }
            set { bin = value; }
        }
        private byte[] bin;

        [Parameter(Mandatory = true)]
        public string DN
        {
            get { return dn; }
            set { dn = value; }
        }
        private string dn;
          

        protected override void EndProcessing()
        {
            ActiveDs.DNWithBinary boink2 = new ActiveDs.DNWithBinaryClass();
            boink2.BinaryValue = bin;
            boink2.DNString = dn;
            WriteObject(boink2);
        }
    }    
}