[Solved] Parse existing CSV file and strip certain columns

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: $CSV … Read more

[Solved] PowerShell batch rename with regex?

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 solved PowerShell batch rename with regex?

[Solved] Delete specific subfolder under unknown folders from anywhere

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 seems … Read more

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

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] try … Read more

[Solved] How to get the value from NoteProperty?

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:”}} solved How to get the value from NoteProperty?

[Solved] Split a logfile

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 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?

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 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

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

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, RedirectStandardOutput … Read more