cmdlets

Missing Help Files in Powershell V5.0

家住魔仙堡 提交于 2019-12-23 21:58:39
问题 Powershell Version: 5.0.10586.494 I just began working with powershell this weekend and I discovered that I cannot find any help files when using the shell, for example, I was looking to read the about_Comparison_Operators help file but it seems as though the console cannot find it. When doing: Get-Help About_* the only result I get is About_CimSession ... it seems like there are no other help files? This TechNet article suggests that in Powershell v3 the module must be imported, To download

How do I find the Azure PowerShell version?

◇◆丶佛笑我妖孽 提交于 2019-12-23 07:19:13
问题 I need to find the installed Azure PowerShell version through cmdlets code. How do I find the Azure PowerShell version? Note: Other than cmdlets code is also welcome. 回答1: This PowerShell cmdlet will get the Azure PowerShell version. Get-Module -ListAvailable -Name Azure -Refresh It has a major advantage in which it will be able to return the expected outcome even if the Azure module has not been loaded into the current PowerShell session. On the contrary, (Get-Module Azure).Version will only

Is there a way to add Alias to Powershell Cmdlet programmatically?

匆匆过客 提交于 2019-12-22 09:18:15
问题 I am writing custom Powershell cmdlets for my application and I need to provide Aliases to some cmdlets. So lets say I have cmdlet Get-DirectoryListing and I want to add Alias (say 'gdl') to this cmdlet. How can I do this? The AliasAttribute doesn't work here, since it works only with Properties, Indexers or Field declarations. Also I know we can use Set-Alias command, but don't know where to put it. Is it possible to programmatically add multiple aliases to a cmdlet? 回答1: You need to create

How do I move files from an old folder structure to new?

懵懂的女人 提交于 2019-12-21 21:43:01
问题 I want to modify my existing folder structure. I had a file tree that was organized in the following way: Client Name State/Province City Order Number But I have modified it to add an address before the order number separated by a hyphen, as such: Client Name State/Province City Order Number - Address I created the new folder structure with a macro I had that generated the original, and I figured this was much easier than renaming the existing folders. So now I want to upload the empty

Start-Job including custom cmdlet terminates with strange error

半腔热情 提交于 2019-12-20 02:23:33
问题 I developed some custom cmdlets that serve for different importing tasks to a SharePoint system. Currently all those cmdlets are being run in a serial kind in a single PowerShell script. I want to change this so that each cmdlet gets executed in a separate task (job). The main script starts a new job with Start-Job relating to a separate script that contains the call to the cmdlet. The script starts and executes the cmdlet. I also debugged the code of the cmdlet that gets executed. So far so

Start-Job including custom cmdlet terminates with strange error

此生再无相见时 提交于 2019-12-20 02:23:06
问题 I developed some custom cmdlets that serve for different importing tasks to a SharePoint system. Currently all those cmdlets are being run in a serial kind in a single PowerShell script. I want to change this so that each cmdlet gets executed in a separate task (job). The main script starts a new job with Start-Job relating to a separate script that contains the call to the cmdlet. The script starts and executes the cmdlet. I also debugged the code of the cmdlet that gets executed. So far so

PowerShell cmdlet parameter validation

纵饮孤独 提交于 2019-12-20 01:09:13
问题 I'm writing a custom PowerShell cmdlet, and I would like to know which is the proper way to validate a parameter. I thought that this could be done either in the property set accessor or during Cmdlet execution: [Cmdlet(VerbsCommon.Add,"X")] public class AddX : Cmdlet { private string _name; [Parameter( Mandatory=false, HelpMessage="The name of the X")] public string name { get {return _name;} set { // Should the parameter be validated in the set accessor? if (_name.Contains(" ")) { // call

Using Powershell's Invoke-Command to call a batch file with arguments

北战南征 提交于 2019-12-19 06:03:10
问题 I want to use Powershell in order to call a batch file on remote machines. This batch file has arguments. Here's what I have so far: $script = "\\fileshare\script.cmd" $server = $args[0] $args [string]::join(',',$args[1 .. ($args.count-1)]) Invoke-Command -computername $server {$script + ' ' + $args} After a bit of searching, I found that the Invoke-Command function runs its scriptblock in a whole new process, so you can't put variables in it (they won't get expanded). That's what the

How to propagate -Verbose to module functions?

六月ゝ 毕业季﹏ 提交于 2019-12-18 08:49:19
问题 According to answers like this one and my own experience, Powershell can take care of propagating -Verbose (and -Debug) automatically, which is very convenient. However this stops working when the functions which I want to propagate verbosity to are in a module. Code used for testing this: Create a directory called Mod somewhere, suppose in c:, and add 2 files: File c:\Mod\Functions.ps1 : function Show-VerbosityB { [cmdletbinding()]Param() Write-Output "Show-VerbosityB called" Write-Verbose

How to get all details from Installed Updates Window

风流意气都作罢 提交于 2019-12-14 03:54:07
问题 I want to get all of this information (including non-windows updates) in any text format... Please share if you have any way to fetch these infos. For more details please see attached image... 回答1: Edit: To get all the updates (installed via Windows Update only, even for 3rd party) and then export the result to a text file, you can use below script: $session = [activator]::CreateInstance([type]::GetTypeFromProgID(“Microsoft.Update.Session”,$ComputerName)) $us = $session.CreateUpdateSearcher()