cmdlet

PowerShell: Import-Module, but no “ExportedCommands” available

老子叫甜甜 提交于 2019-12-21 02:00:55
问题 When I use Import-Module -Name <path_to_local_dll> -Verbose the cmdlets contained in the DLL file are not exported. Thus, when I type Get-Module my imported module is listed, but without any ExportedCommands. Why? ModuleType Name ExportedCommands ---------- ---- ---------------- Binary MyModule On a second PC with the same software (PowerShell, .NET Framework, ...), the same imported DLL file works fine. There I get ExportedCommands. On what can this behaviour depend? Unfortunately, the

Set the encoding to ANSI in PowerShell 2.0

大城市里の小女人 提交于 2019-12-20 02:28:09
问题 I want to set the encoding of a file to ANSI using the parameter -Encoding of the Set-Content cmdlet, I tried this one but it didn't work: Set-Content -LiteralPath "$filePath" -Encoding Default 回答1: PowerShell v2 doesn't recognize an argument Default for the parameter -Encoding . Use the argument Ascii to save a file with ANSI encoding: Set-Content -LiteralPath "$filePath" -Encoding Ascii or omit the parameter entirely ( Set-Content defaults to ANSI encoding): Set-Content -LiteralPath "

imported c# cmdlet not working

自作多情 提交于 2019-12-12 04:39:29
问题 There are multiple project in my solution, one of which contains a class = basically a C# Module to be used via Power Shell console: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Management.Automation; using System.Management; using EDZ.DAL; using EDZ.Model; using System.Collections; namespace AddUser { [Cmdlet(VerbsCommon.Add, "User")] class AddUser : Cmdlet { protected override void ProcessRecord() {

PowerShell start-sleep cmdlet

做~自己de王妃 提交于 2019-12-12 04:08:47
问题 Hey I am very new to PowerShell and found one of Ed Wilson's helpful scripts on his blog: http://blogs.technet.com/b/heyscriptingguy/archive/2012/11/12/force-a-domain-wide-update-of-group-policy-with-powershell.aspx. I needed to customize it a little for my needs and just need some help getting the right code down. I will just use his code because all I did was replace it with my credentials and AD info: $cn = Get-ADComputer -filt * $cred = Get-Credential iammred\administrator $session = New

How can I process the content of a CSV file as Pipeline input in Powershell cmdlet

浪尽此生 提交于 2019-12-11 03:43:11
问题 I want to use a CSV file to feed the parameters of powershell cmdlet Role, email, fname, lname Admin, a@b.com, John, Smith I want to process a cmdlet as follows: import-csv myFile| mycmdlet | export-csv myresults I also want to be able to call the cmdlet like this mycmdlet -role x -email j@b.com -fname John -lname Smith and see a result as an object like: lname: "Smith" fname: "John" email: "j@b.com" role: "X" ResultData: "something else" I didn't want to have to do this: import-csv X.txt |

Get-AdComputer -filter parameter not accepting Get-Date output

走远了吗. 提交于 2019-12-10 22:17:43
问题 I've stumbled across an odd error in a PowerShell script that returns for me the computers in Active Directory in a specific OU (and sub OU's) that are enabled and logged on to within a certain date. The following snippet does work: $date = (get-date).AddDays(-100) Get-ADComputer -Filter {(enabled -eq "true") -and (lastLogonTimestamp -gt $date)} -Properties lastLogonTimestamp -SearchBase "CN=Computers,DC=some,DC=domain,DC=com" ... however I initially attempted to do this is one line: Get

How to get C# Cmdlet Parameter HelpMessage to show up in `Get-Help`

萝らか妹 提交于 2019-12-10 16:14:04
问题 I have started a PowerShell cmdlet and want to supply the help message for a parameter. I've tried using ParameterAttribute.HelpMessage for this: [Cmdlet(VerbsCommon.Get, "Workspace", SupportsShouldProcess = true)] public class GetWorkspace : PSCmdlet { [Parameter( Mandatory = true, Position = 1, HelpMessage = "The path to the root directory of the workspace.")] public string Path { get; set; } protected override void ProcessRecord() { base.ProcessRecord(); } } But when I use the PowerShell

Shorter versions of powershell cmdlet parameters

China☆狼群 提交于 2019-12-09 18:36:32
问题 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

Powershell scripting: recommended way to implement ShouldProcess when function calls are nested?

倾然丶 夕夏残阳落幕 提交于 2019-12-09 02:49:21
问题 Test script: function outer { [cmdletbinding(supportsshouldprocess=$true)] param($s) process { $pscmdlet.shouldprocess("outer $s", "ShouldProcess") | out-null "" | out-file "outer $s" inner ImplicitPassthru inner VerbosePassthru -Verbose:$Verbose inner WhatifPassthru -WhatIf:$WhatIf } } function inner { [cmdletbinding(supportsshouldprocess=$true)] param($s) process { $pscmdlet.shouldprocess("inner $s", "ShouldProcess") | out-null "" | out-file "inner $s" } } "`n** NORMAL **" outer normal "`n*

What's the difference between WriteObject(x, true) and multiple writeobjects when writing a PowerShell cmdlet?

早过忘川 提交于 2019-12-07 16:29:29
问题 I want to write a cmdlet that reads multiple records from a database and puts them onto the pipeline. I think I can do either a single WriteObject(Enumerable<rec>, true) or I can loop myself and call WriteObject multiple times. What's the difference between these two? 回答1: Here is the documentation: Cmdlet.WriteObject Method (Object, Boolean) And here is the example: # Writes objects one by one function Test1 { [CmdletBinding()]param() $data | %{ $PSCmdlet.WriteObject($_) } } # Writes the