[Solved] Parse existing CSV file and strip certain columns

[ad_1] If you want the columns removed completely: $CSV = Import-Csv $Path | Select-Object -Property User1, Name, Gender $CSV | Export-Csv $NewPath -NoTypeInformation Or this, if it’s easier: $CSV = Import-Csv $Path | Select-Object -Property * -ExcludeProperty Age, Location, HairColor $CSV | Export-Csv $NewPath -NoTypeInformation If you want the columns to remain but be empty: … Read more

[Solved] Extract data from a log that contains certain pattern

[ad_1] [replaced code using not-really-there asterisks in sample data.] [powershell v5.1] this will match any line that contains “login” and then extract the requested info using basic string operators. i tried to use regex, but got bogged down in the pattern matching. [blush] regex would almost certainly be faster, but this is easier for me … Read more

[Solved] PowerShell batch rename with regex?

[ad_1] try this (remove whatif) Get-ChildItem “c:\temp” -file -Filter “*.txt” | where BaseName -Match “.-.” | %{ $newname=”{0}{1}” -f ($_.BaseName -split ‘-‘)[1], $_.Extension Rename-Item $_.FullName $newname -WhatIf } 4 [ad_2] solved PowerShell batch rename with regex?

[Solved] Delete specific subfolder under unknown folders from anywhere

[ad_1] I created a short powershell solution using this- $targetName=”ss s”; foreach ($file in Get-Childitem “G:\Project\Projects\” ) { $fname=$file.name; if (Test-Path “G:\Project\Projects\$fname\$targetName\”) { $shell = new-object -comobject “Shell.Application” $item = $shell.Namespace(0).ParseName(“G:\Project\Projects\$fname\$targetName”) $item.InvokeVerb(“delete”) } } This powershell script sends that folder to recycle bin after confirmation popup. (this won’t send any file named ‘ss s’) this … Read more

[Solved] Having trouble getting a list of users profiles [closed]

[ad_1] You’ll want to query WMI for Win32_UserProfile instances – each profile will be linked to the security identifier of the user owning the profile, which can in turn be translated to an account object with the user name: Get-CimInstance win32_userprofile |ForEach-Object { # Convert SID string to SecurityIdentifier object $SID = $_.SID -as [System.Security.Principal.SecurityIdentifier] … Read more

[Solved] How to get the value from NoteProperty?

[ad_1] I do not have a way to test it right now, but one way to do that might be like this: Get-Mailbox | select EmailAddresses, UserPrincipalName, DisplayName, PrimarySmtpAddress, @{Name=”SIPAddress”;Expression={$PSItem.EmailAddresses -match “sip:”}} [ad_2] solved How to get the value from NoteProperty?

[Solved] Split a logfile

[ad_1] the following casts the selected string as double and then returns only those which are less than 5 $results = Foreach ($line in $list) { $val = [double]$line.Split(‘=’)[3].Trim().TrimEnd(‘s’) if($val -lt 5) { $val } } 1 [ad_2] solved Split a logfile

[Solved] I want to convert following text file foo.txt to HTML file with table with column heading as status,displayname,name line using PowerShell?

[ad_1] I want to convert following text file foo.txt to HTML file with table with column heading as status,displayname,name line using PowerShell? [ad_2] solved I want to convert following text file foo.txt to HTML file with table with column heading as status,displayname,name line using PowerShell?

[Solved] PowerShell parsing JSON

[ad_1] Not that straight forward if you want to group by rows of Value names. I took liberty of thinking the logic for you. Below code will output to csv what you need: $jsonContent = Get-Content .\release.json | ConvertFrom-Json; $environmentsArray = $jsonContent.environments; # Create an array of data we will be putting into Excel $arrData … Read more

[Solved] Batch file v PowerShell script

[ad_1] The following code executes the same code via both processes: internal class Program { private static void Main() { const string COMMAND = @”SCHTASKS /QUERY /XML ONE”; Collection<PSObject> psObjects; using (var ps = PowerShell.Create()) { ps.AddScript(COMMAND); psObjects = ps.Invoke(); } var process = new Process { StartInfo = new ProcessStartInfo { UseShellExecute = false, … Read more