Exemplo n.º 1
0
        public IEnumerable <VMSwitch> Post(VMSwitch sw)
        {
            string str = string.Format("$sw = Get-VMSwitch -Id {0}\r\nRemove-VMSwitch $sw -Force", sw.Id);

            PSHelper.RunScript(str);
            return(base.Get());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Process record
        /// </summary>
        protected override void ProcessRecord()
        {
            using (var powerShell = PowerShell.Create())
            {
                if (!PrincipalHelper.IsAdminRole)
                {
                    throw new AuthenticationException(
                              @"You do not have the required permission to complete this task. Contact the administrator of the
                    authorization policy for the computer");
                }

                var command = powerShell.AddCommand("Get-VMSwitch");

                WriteVerbose($"Current parameter set name {ParameterSetName}");

                this.SetParameters(command);

                var results = command.Invoke();

                foreach (var item in results)
                {
                    // Mess convertion
                    dynamic t = item.BaseObject;

                    var result = new VMSwitch
                    {
                        Name       = t.Name,
                        SwitchType = t.SwitchType.ToString(),
                        NetAdapterInterfaceDescription = t.NetAdapterInterfaceDescription
                    };

                    WriteObject(result);
                }
            }
        }
Exemplo n.º 3
0
        public IEnumerable <VMSwitch> Post(VMSwitch sw)
        {
            string empty = string.Empty;

            string[] strArrays = new string[] { "Private", "Internal" };
            if (strArrays.Contains <string>(sw.SwitchType))
            {
                string   str        = "New-VMSwitch -Name {1} -ComputerName {0} -Notes {3} -SwitchType {4}";
                object[] hyperVHost = new object[] { sw.HyperVHost, sw.Name, sw.Notes, sw.SwitchType };
                empty = string.Format(str, hyperVHost);
            }
            else if (!string.IsNullOrWhiteSpace(sw.NetAdapterInterfaceDescription))
            {
                string   str1     = "New-VMSwitch -Name {1} -ComputerName {0} -Notes {3} -InterfaceDecription {4}";
                object[] objArray = new object[] { sw.HyperVHost, sw.Name, sw.Notes, sw.NetAdapterInterfaceDescription };
                empty = string.Format(str1, objArray);
            }
            if (!string.IsNullOrWhiteSpace(empty))
            {
                PSHelper.RunScript(empty);
            }
            return(base.Get());
        }