Exemplo n.º 1
0
        /// <summary>
        /// Gets raw bytes of a file on the remote file system.
        /// </summary>
        /// <param name="remoteFilePath">The path to the file.</param>
        public byte[] GetFileBytes(string remoteFilePath)
        {
            byte[] results = null;

            if (PathExists(remoteFilePath, true, false))
            {
                remoteFilePath = PSUtils.EscapeString(remoteFilePath);
                var script = $@"[System.Convert]::ToBase64String([System.IO.File]::ReadAllBytes({remoteFilePath}))";

                var data = PSClient.InvokeScript <string>(script).Single();
                results = Convert.FromBase64String(data);
            }

            return(results);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Invokes a PowerShell command.
 /// </summary>
 /// <typeparam name="T">The type of results to return from the output stream.</typeparam>
 /// <param name="cmdlet">The name of the cmdlet to invoke.</param>
 /// <param name="parameters">An anonymous object containing the parameters for the cmdlet.</param>
 /// <param name="switches">A collection of switches for the cmdlet.</param>
 public ICollection <T> InvokeCommand <T>(string cmdlet, object parameters = null, params string[] switches)
 {
     return(InvokeCommand <T>(PSUtils.CreateCommand(cmdlet, parameters, switches)));
 }
Exemplo n.º 3
0
 /// <summary>
 /// Invokes a PowerShell command.
 /// </summary>
 /// <param name="cmdlet">The name of the cmdlet to invoke.</param>
 /// <param name="parameters">An anonymous object containing the parameters for the cmdlet.</param>
 /// <param name="switches">A collection of switches for the cmdlet.</param>
 public void InvokeCommand(string cmdlet, object parameters = null, params string[] switches)
 {
     InvokeCommand(PSUtils.CreateCommand(cmdlet, parameters, switches));
 }
Exemplo n.º 4
0
 /// <summary>
 /// When overridden in a derived class, writes a progress report to be displayed to the user.
 /// </summary>
 /// <param name="sourceId">A unique identifier of the source of the record.</param>
 /// <param name="record">
 /// A ProgressRecord object that contains the progress record to be displayed.
 /// </param>
 public override void WriteProgress(long sourceId, ProgressRecord record)
 {
     Debug.WriteLine($"[PROGRESS(Id: {sourceId})] " + PSUtils.Stringify(record));
     WriteProgressCallback?.Invoke(sourceId, record);
 }