cmdlets

Powershell String Length Validation

孤人 提交于 2020-03-03 09:18:46
问题 I created a really simple HelloWorld.ps1 Power-shell script which accepts a Name parameter, validates its length and then prints a hello message, for example if you pass John as Name , it's supposed to print Hello John! . Here is the Power-shell script: param ( [parameter(Mandatory=$true)] [string] $Name ) # Length Validation if ($Name.Length > 10) { Write-Host "Parameter should have at most 10 characters." Break } Write-Host "Hello $Name!" And here is the command to execute it: .\HelloWorld

Set Folder, Subfolder and File Permission Set-ACL Powershell Script. Setting File Inherititance does not work

杀马特。学长 韩版系。学妹 提交于 2020-01-24 00:49:28
问题 I need some help with my Powershell Script. my customer got a huge directory and i need to change the Security Settings. I made this code below and It works but i got one problem: The inheritance on the Files does not work so the Security permissions on any File in the directory is not set. Maybe Someone will find my error. XML File: <?xml version="1.0" encoding="utf-8"?> <Pfade> <pfad name="E:\Share\TEST"> <gruppe name="Domain Admins"> <rechte>FullControl</rechte> <aktion>allow</aktion>

Reading event log remotely with Get-EventLog in Powershell

拟墨画扇 提交于 2020-01-11 04:33:12
问题 I've a powershell script which runs on server(test-server) and reads the log file of his client(DC1). Both sides can ping to each other. On both sides, firewalls are disabled. Remote Desktop and Remote Assistance are enabled on DC1. Get-EventLog System -ComputerName test-server -Source Microsoft-Windows-Winlogon # WORKS Get-EventLog System -ComputerName DC1 -Source Microsoft-Windows-Winlogon # DOESN'T WORK I run this script on test-server. As you see when I read the local log file on test

Get implementation of sharepoint powershell cmdlets

房东的猫 提交于 2020-01-07 03:47:46
问题 How to find managed code SharePoint (whichever version) cmdlets implementations? MSDN does not specify where and how cmdlets are implemented. There is only information how to use them. Is this done for some reason? 回答1: So I started digging… Let’s for example take SharePoint 2013 15 Hive. 15 Hive folder structure explained: SharePoint 2013: The 15 Hive and other important directories CMDLET Registration files location 15/Config/Powershell/Registration folder contains XML cmdlet registration

Filtering for strings in PowerShell

荒凉一梦 提交于 2020-01-07 02:25:09
问题 I would like to implement some custom cmdlets that filter some object by name, and I would like to use wild-card enabled search like for common cmdlets (Get-ChildItem and Get-Process). How can I implement this kind of search? Are there some examples or even some reusable components? Any examples? 回答1: For the most part, these types of cmdlets leverage the WildcardPattern class. Here's an example of how to use it directly from the PowerShell prompt: PS>$w = New-Object System.Management

Redirect error to file

十年热恋 提交于 2020-01-06 15:29:14
问题 I'm writing a PowerShell script and one of its parts should add a new user to Active Directory. I'm using the New-ADUser cmdlet and I want to redirect any errors (if it will produce any) to a file. So I write New-ADUser -smth -smth 2>> ./log.txt But it creates only a blank log.txt file when I simulate error. What did I do wrong? 回答1: Errors that are thrown by the cmdlet itself can be redirected like you tried: New-Item -Type File C:\Windows\WinSxS\foo.txt 2>> error.log Errors thrown by the

Send multiple outputs to the same HTML file in Powershell

对着背影说爱祢 提交于 2020-01-02 19:36:49
问题 Trying to figure out how to convert to HTML multiple service checks: I have this script: Get-service -Computername SERVER1 -Name *SERVICE1* | ConvertTo-Html -Body "<H2>Service 1 Check</H2> " -Property Name,Status Get-Service -Computername SERVER2 -name *SERVICE2* | ConvertTo-Html -Body "<br><H2>Service 2 Check</H2> " -Property Name,Status | Out-File c:\servicecheck.htm Is this possible? 回答1: May be you can do something like this - $Event = Get-EventLog -LogName Security -newest 100 |

Use PowerShell to create instance of COM object

浪尽此生 提交于 2019-12-25 09:27:10
问题 I'm trying to use SAP/BusinessObjects' Universe Design Tool (UDT) in a PowerShell session. I registered the type library: C:\> C:\Windows\Microsoft.NET\Framework\v4.0.30319\regtlibv12.exe "C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\win32_x86\designer.tlb I attempted to create an instance of the Designer in PowerShell directly: PS> $app = New-Object -ComObject Designer.Application System.__ComObject The instance doesn't have any of the expected properties

cmdlet says parameter cannot be retrieved: expression must be readable

冷暖自知 提交于 2019-12-25 01:50:39
问题 My cmdlet has a Get-Deal command, which will receive value from pipeline: [Cmdlet(VerbsCommon.Get, "Deal")] public class GetDealCmdlet : InsightBaseCmdlet { private List<Object> _legalentities = new List<Object>(); [Parameter(Position = 0, Mandatory = true, ValueFromPipeline = true,ValueFromPipelineByPropertyName = true)] public List<Object> Legalentity { set { _legalentities = value; } } protected override void ProcessRecord() {...} } It works fine if I passed a list of string or other types

Run entityframework cmdlets from my code

强颜欢笑 提交于 2019-12-24 23:35:31
问题 I am creating a small program over entityframework which allows to edit the POCOs with a UI. as part of the process i would like to call the "add-migration" command from my code to save the interaction of the rest of the programmers with the program manager console. is it possible at all? thanks 回答1: Add-Migration cmdlet is defined in separate EF 4.3 Powershell assembly used by Package manager console. This assembly references a real EF 4.3 assembly. The core logic exposed from that assembly