cmdlet

Download Multiple Files from http using Powershell with proper names

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-07 16:16:47
问题 I have searched for something similar and I keep running across the FTP download answers. This is helpful information, but ultimately proving to be difficult to translate. I have found a powershell script and it works, but I am wondering if it can be tweaked for my needs. I don't have much experience with powershell scripting, but I'm trying to learn. The need is this. I need to download and install a series of files to a remote machine, unattended. The files are distributed via email via

Download Multiple Files from http using Powershell with proper names

蹲街弑〆低调 提交于 2019-12-05 19:51:18
I have searched for something similar and I keep running across the FTP download answers. This is helpful information, but ultimately proving to be difficult to translate. I have found a powershell script and it works, but I am wondering if it can be tweaked for my needs. I don't have much experience with powershell scripting, but I'm trying to learn. The need is this. I need to download and install a series of files to a remote machine, unattended. The files are distributed via email via tinyurls. I currently throw those into a .txt file, then have a powershell script read the list and

How to capture a Powershell CmdLet's verbose output when the CmdLet is programmatically Invoked from C#

*爱你&永不变心* 提交于 2019-12-04 19:11:19
问题 BACKGROUND I am using Powershell 2.0 on Windows 7. I am writing a cmdlet in a Powershell module ("module" is new to Powershell 2.0). To test the cmdlet I am writing Unit tests in Visual Studio 2008 that programmatically invoke the cmdlet. REFERENCE This Article on MSDN called "How to Invoke a Cmdlet from Within a Cmdlet" shows how to call a cmdlet from C#. THE SOURCE CODE This is a distilled version of my actual code — I've made it as small as possible so that you can see the problem I am

Shorter versions of powershell cmdlet parameters

♀尐吖头ヾ 提交于 2019-12-04 09:32:31
Given my research, I don't believe the following is easily accomplished, if at all. As a last resort, however, I figured I'd check here. In Powershell 2.0, I'd like a way to reduce the (annoyingly) long names of parameters to various cmdlets. I would like absolute control over what the shorthand version looks like. (As opposed to being a slave to whatever parameter abbreviation scheme PS uses.) So, for example, I'd like to be able to do something like this: # Command goes on this first line to alias "-ForegroundColor" to "-fg" # Command goes on this second line to alias "-BackgroundColor" to "

How to convert .cs file to a PowerShell cmdlet?

做~自己de王妃 提交于 2019-12-03 13:21:15
问题 Can anyone help me to convert a C# .NET program to PowerShell cmdlet? I am very new to this area. Please help me to get out of this checkpoint! Regards, Arun 回答1: Add a reference to System.Management.Automation , create a class that inherits from Cmdlet and override the ProcessRecord method: [Cmdlet(VerbsCommon.Get, "Double")] public class GetDouble : Cmdlet { [Parameter] public int SomeInput { get; set; } protected override void ProcessRecord() { WriteObject(SomeInput * 2); } } Add an

Powershell commands from C# 'the term is not recognizes as cmdlet'

淺唱寂寞╮ 提交于 2019-12-02 03:19:12
问题 I'm having a problem to execute powershell commands from the C# application. I've found many things related to this issue, but none of them helped me to figured it out what might is going on. So I have this little test function: private void Button_Click_1(object sender, RoutedEventArgs e) { Runspace runspace = RunspaceFactory.CreateRunspace(); runspace.Open(); Pipeline pipeline = runspace.CreatePipeline(); pipeline.Commands.AddScript("msg * test"); pipeline.Invoke(); runspace.Close(); } The

Inline expansion of powershell variable as cmdlet parameter?

空扰寡人 提交于 2019-12-02 02:44:56
问题 When calling a cmdlet, is it possible to expand the value of a powershell variable somehow so it acts as a parameter (with associated values) for the cmdlet? Here's an example of what I'm trying: $CREDENTIALED_SECTION = "-Username $USER_NAME -Password $PASSWORD" . . . Invoke-Sqlcmd -ServerInstance "$SERVER_NAME" -Query "$SQL_STATEMENT" "$CREDENTIALED_SECTION" -Database "$DATABASE" The problem comes when Invoke-Sqlcmd runs. It tells me that a positional parameter cannot be found that accepts "

Powershell commands from C# 'the term is not recognizes as cmdlet'

痴心易碎 提交于 2019-12-02 02:20:46
I'm having a problem to execute powershell commands from the C# application. I've found many things related to this issue, but none of them helped me to figured it out what might is going on. So I have this little test function: private void Button_Click_1(object sender, RoutedEventArgs e) { Runspace runspace = RunspaceFactory.CreateRunspace(); runspace.Open(); Pipeline pipeline = runspace.CreatePipeline(); pipeline.Commands.AddScript("msg * test"); pipeline.Invoke(); runspace.Close(); } The problem is that in some computers it works just fine, but in others I receive the message that "the

Inline expansion of powershell variable as cmdlet parameter?

好久不见. 提交于 2019-12-02 01:46:54
When calling a cmdlet, is it possible to expand the value of a powershell variable somehow so it acts as a parameter (with associated values) for the cmdlet? Here's an example of what I'm trying: $CREDENTIALED_SECTION = "-Username $USER_NAME -Password $PASSWORD" . . . Invoke-Sqlcmd -ServerInstance "$SERVER_NAME" -Query "$SQL_STATEMENT" "$CREDENTIALED_SECTION" -Database "$DATABASE" The problem comes when Invoke-Sqlcmd runs. It tells me that a positional parameter cannot be found that accepts "-Username my username -Password my password " So it's expanding the variable but not properly sending

PowerShell : GetNewClosure() and Cmdlets with validation

落花浮王杯 提交于 2019-12-02 01:22:44
问题 I'm trying to understand how .GetNewClosure() works within the context of a script cmdlet in PowerShell 2. In essence I have a function that returns an object like so: function Get-AnObject { param( [CmdletBinding()] [Parameter(....)] [String[]]$Id .. [ValidateSet('Option1','Option2')] [String[]]$Options ) ... $T = New-Object PSCustomObject -Property @{ ..... } $T | Add-Member -MemberType ScriptProperty -Name ExpensiveScriptProperty -Value { $this | Get-ExpensiveStuff }.GetNewClosure() .. }