cmdlets

Get a list of all Resources in my Azure Subscription (Powershell Preferably)

我们两清 提交于 2019-11-28 01:52:03
I have an azure subscription and I'm trying to write a powershell script to automatically get a list of all the resources (VMs, Storage Accounts, Databases, etc) that I currently have in my subscription. Is there a way to do this using the azure management REST API or the Azure Cmdlets? If you are using the new Resource Manager model (introduced in 2014) you can use the following PowerShell script. Login-AzureRmAccount Get-AzureRmResource | Export-Csv "c:\Azure Resources.csv" To use the Resource Manager PowerShell commands you will need the AzureRM PowerShell module ( https://docs.microsoft

Objects with no '.Count' Property - use of @() (array subexpression operator) vs. [Array] cast

十年热恋 提交于 2019-11-28 00:58:58
问题 I am trying to perform some simple if statements, but all of the newer cmdlets that are based upon [Microsoft.Management.Infrastructure.CimInstance] don't seem to expose a .count method? $Disks = Get-Disk $Disks.Count Doesn't return anything. I found that I can cast this as an [array], which makes it returns a .NET .count method as expected. [Array]$Disks = Get-Disk $Disks.Count This works without directly casting it as an array for previous cmdlets: (Get-Services).Count What is the

Can we see the source code for PowerShell cmdlets?

邮差的信 提交于 2019-11-27 12:47:16
问题 I'm learning some PowerShell. Is it possible to see the source code for a built-in cmdlet like Get-ChildItem? 回答1: Actually, your best bet is to go check out PowerShell Community Extensions. This open source software community project is "aimed at providing a widely useful set of additional cmdlets...". The developers on the project are PowerShell MVPs and know their stuff. As far as using reflection on the existing PowerShell cmdlets, PowerShell MVP Oisin Grehan made a handy function titled

MSOnline can't be imported on PowerShell (Connect-MsolService error)

亡梦爱人 提交于 2019-11-27 12:25:54
I had this issue and couldn´t find any answer. The issue was that I was trying to use Azure cdmlets to connect to O365 via c# code, but I couldn´t get the connect-msolservice . ""The term is not recognized" error when you try to run administrative Windows PowerShell cmdlets in Office 365" After reviewing Microsoft's TechNet article "Azure Active Directory Cmdlets" -> section "Install the Azure AD Module" , it seems that this process has been drastically simplified, thankfully. As of 2016/06/30, in order to successfully execute the PowerShell commands Import-Module MSOnline and Connect

How do you support PowerShell's -WhatIf & -Confirm parameters in a Cmdlet that calls other Cmdlets?

限于喜欢 提交于 2019-11-27 12:14:08
问题 I have a PowerShell script cmdlet that supports the -WhatIf & -Confirm parameters. It does this by calling the $PSCmdlet.ShouldProcess() method before performing the change. This works as expected. The problem I have is that my Cmdlet is implemented by calling other Cmdlets and the -WhatIf or -Confirm parameters are not passed along to the Cmdlets I invoke. How can I pass along the values of -WhatIf and -Confirm to the Cmdlets I call from my Cmdlet? For example, if my Cmdlet is Stop

How to properly use the -verbose and -debug parameters in a custom cmdlet

主宰稳场 提交于 2019-11-27 10:15:54
问题 By default, any named function that has the [CmdletBinding()] attribute accepts the -debug and -verbose (and a few others) parameters and has the predefined $debug and $verbose variables. I'm trying to figure out how to pass them on to other cmdlet's that get called within the function. Let's say I have a cmdlet like this: function DoStuff() { [CmdletBinding()] PROCESS { new-item Test -type Directory } } If -debug or -verbose was passed into my function, I want to pass that flag into the new

How to extract specific tables from html file using native powershell commands?

只谈情不闲聊 提交于 2019-11-27 07:03:21
问题 I make use of the PAL tool (https://pal.codeplex.com/) to generate HTML reports from perfmon logs within Windows. After PAL processes .blg files from perfmon it dumps the information into an HTML document that contains tables with various data points about how the system performed. I am currently writing a script that looks at the contents of a directory for all HTML files, and does a get-content on all the HTML files. What I would like to do is scrape the dump of this get-content blob for

For PowerShell cmdlets, can I always pass a script block to a string parameter?

为君一笑 提交于 2019-11-27 05:32:33
I'm looking at the document of Rename-Item and there is an example like this. PS C:\>Get-ChildItem *.txt | Rename-Item -NewName { $_.name -Replace '\.txt','.log' } This example shows how to use the Replace operator to rename multiple files, even though the NewName parameter does not accept wildcard characters. This command renames all of the .txt files in the current directory to .log. The command uses the Get-ChildItem cmdlet to get all of the files in the current folder that have a .txt file name extension. Then, it uses the pipeline operator (|) to send those files to Rename-Item . The

Calling Powershell functions from C#

痞子三分冷 提交于 2019-11-27 02:15:22
问题 I have a PS1 file with multiple Powershell functions in it. I need to create a static DLL that reads all the functions and their definitions in memory. It then invokes one of these functions when a user calls the DLL and passes in the function name as well as the parameters for the function. My question is, is it possible to do this. ie call a function that has been read and stored in memory? Thanks 回答1: Here's the equivalent C# code for the code mentioned above string script = "function Test

How do I host a Powershell script or app so it's accessible via WSManConnectionInfo? (like Office 365)

Deadly 提交于 2019-11-27 01:34:44
问题 The only ways I know to connect to a remote runspace include the following parameters WSManConnectionInfo connectionInfo = new WSManConnectionInfo(false, "localhost", 80, "/Powershell", "http://schemas.microsoft.com/powershell/Microsoft.Exchange", credential); or WSManConnectionInfo connectionInfo = new WSManConnectionInfo(false, "localhost", 5985, "/wsman", "http://schemas.microsoft.com/powershell/Microsoft.Powershell", credential); How do I set up my own custom Powershell object so I can