powershell-3.0

Powershell Import-CSV how to skip until particular line based on string?

淺唱寂寞╮ 提交于 2020-01-11 13:15:28
问题 Hi My CSV file is like this #BEGINPROPERTIES total.candidate.create=2 duration=0:00:00.433 internal.audit.session.id=1397055568 internal.cluster.node.info=(product:enterprise,id:node796599_796601,http:"10.111.233.79:19788",jgroups:"chprapk11406-44186",contextPath:/enterprise,isCoordinator:false) processing.batching.size=1 total.candidate=2 non.updatable.fields=error.different internal.cluster.node.id=node796599_796601 progress.interval=1 CSVLineCount=2 default.operation=merge total.status

Recursively set permissions on folders using Powershell?

≯℡__Kan透↙ 提交于 2020-01-11 11:04:57
问题 I have a directory which I want to go through recursively and set permissions on all the folders. So the order of operations should be: Remove all ACL from folder Add ACL to folder Set ACL I tried the below code, but I am getting the error Cannot set the ACL because the method that it needs to invoke, SetSecurityDescriptor, does not exist. foreach ($folder in Get-ChildItem -Path c:\perms -Recurse -Directory) { $AccessRule = New-Object System.Security.Accesscontrol.FileSystemAccessRule ("user"

How can I extract “Path to executable” of all services with PowerShell

随声附和 提交于 2020-01-10 08:03:05
问题 Get-Service *sql* | sort DisplayName | out-file c:/servicelist.txt I have a one line PowerShell script to extract list of all services running on my local machine, now, in addition to displaying "Status", "Name" and "DisplayName" I also want to display "Path to executable" 回答1: I think you'll need to resort to WMI: Get-WmiObject win32_service | ?{$_.Name -like '*sql*'} | select Name, DisplayName, State, PathName Update If you want to perform some manipulation on the selected data, you can use

Using PowerShell Invoke-RestMethod to POST large binary multipart/form-data

眉间皱痕 提交于 2020-01-09 10:51:28
问题 I'm trying to use the Invoke-RestMethod cmdlet in PowerShell 3 and 4, to upload a large binary file using a REST API's multipart/form-data upload. Here is a working cURL example on how to perform what I want to do in PowerShell: curl -i -k -H "accept: application/json" -H "content-type: multipart/form-data" -H "accept-language: en-us" -H "auth: tokenid" -F file="@Z:\large_binary_file.bin" -X POST "https://server/rest/uri2" I would love to see a working example on how to use Invoke-RestMethod

Powershell split csv column value into two seperate column values

落爺英雄遲暮 提交于 2020-01-07 02:40:10
问题 Lets say I have a csv file with 5 records (in reality it's about 80,000). Csv File: column1,columnICareAbout,column2 someRandomValue,John Doe - Generic,someRandomValue someRandomValue,Captain Teemo - pocketPet,someRandomValue someRandomValue,Pinky Brain - Fictional,someRandomValue someRandomValue,Miyamoto Musashi - swordsman,someRandomValue someRandomValue,Kato yasunori - troubleMaker - Extreme,someRandomValue Given the following code: Note: I know the array values are correct, I just need to

Filter out users that contains a word or character with Get-ADUser

大城市里の小女人 提交于 2020-01-06 15:03:45
问题 I am trying to get a list of AD-Users in different domains but cannot find a way to exclude users that has "Health" in their name for an example. This is how my query looks like as of now: #$excludedusers = @('HealthMailbox123456') Get-ADUser -Server $test -Credential $1cred -Filter{enabled -eq $true} | Where-Object { $_.DistinguishedName -notlike '*OU=.Service Accounts,*' } | Select-object Samaccountname,surname,givenname | Where { $excludedusers -NotContains$_.Samaccountname } As of now,

Powershell number notation matches and rename-item logic

↘锁芯ラ 提交于 2020-01-06 08:43:46
问题 In the below solution for renaming files taken from an answer to my question Rename-Item error, what do the following bits of code do? ^\d{4} e={$Matches[1]} Rename-item -Newname {"{0:D4} - sp - C - {1}" -f ++$Count.Value,$_.Name} For 1. I think this is saying a four digit number but I would like to understand the notation used. For 2. $Matches hasn't been set anywhere, is this a variable specific to Select-Object ? For 3. what is {0:D4} doing and the {1} at the end of the same string. Also,

How to compare, match, and append multiple values in multiple CSV files?

非 Y 不嫁゛ 提交于 2020-01-06 04:03:06
问题 I'm trying to figure out the best way to do this, and I'm not sure how to Import-Csv with 2 different files through the same pipeline and export a value found... So lets start with CSV file 1: I only want the values for LoginNumber where Type = H and (ContractorDomain -ne $null -or ContractorDomain -ne "") . For example, this should only pull values 0031482 and 2167312 from below. Note: I only added spaces and arrows to make it easier to read as columns here. The csv files have no spaces

Changes last name, first name to first name, last name in last column CSV powershell

≯℡__Kan透↙ 提交于 2020-01-05 10:30:29
问题 I am a newbie to powershell. I was trying to change last name, first name to first name, last name in the last column in CSV file and export all of the changes I have made to a new csv file. The data looks like this. Sport, Gender, Zip, Recruiter "Baseball","Male", "12345", "John, Wayne" I tried using Get-Content "C:\import.csv" | ForEach-Object {$_.Recruiter -replace ",", ""} | ForEach-Object {$_.Sport -replace ",", ""} | Set-content "C:\export.csv" This is a sample code, which, of course,

Returning a Row Count for a DataRow in PowerShell

做~自己de王妃 提交于 2020-01-04 15:46:13
问题 My script is populating a datarow from a stored procedure in SQL Server. I then reference specific columns in this datarow throughout the script. What I'm trying to do is add functionality that takes action X if the row count = 0, action Y if the row count = 1, and action Z if the row count > 1. -- PowerShell script snippet # $MyResult is populated earlier; # GetType() returns Name=DataRow, BaseType=System.Object # this works ForEach ($MyRow In $MyResult) { $MyFile = Get-Content $MyRow