Power Shell stuff

1.  Replacing characters in csv file using below sample code:

$csv001 = import-csv "C:\Users\sumeet.kumar\Desktop\Services\Scripts\Power Shell Scripts\Sending reboot notification\Computers with last logged on user from collection Username0.csv"
$csv001 | foreach-object {

$_.username0 = $_.username0.replace("Domain\","")
}
$csv001 | export-csv  "C:\Users\sumeet.kumar\Desktop\Services\Scripts\Power Shell Scripts\Sending reboot notification\Computers with last logged on user from collection Username001.csv" -notype


Reference: http://social.technet.microsoft.com/Forums/windowsserver/en-US/0ad9ad37-b99b-418a-b139-34752b0927dc/powershell-importcsv-then-replace-character-then-exportcsv


2.  Appending characters in csv file using below code:

$csv003 = import-csv "C:\Users\sumeet.kumar\Desktop\Services\Scripts\Power Shell Scripts\Sending reboot notification\Computers with last logged on user from collection Username001.csv"
$csv003 | foreach-object {
$_.username0 = $_.username0 + '@domain.com'
$EMails += $_.username0 + ","


3. Removing header from csv file:

$csv004 = Get-content "C:\Users\sumeet.kumar\Desktop\Services\Scripts\Power Shell Scripts\Sending reboot notification\Computers with last logged on user from collection Username002.csv"
$csv004=$csv004[1], $csv004[2..($csv004.count - 0)]
$csv004>"C:\Users\sumeet.kumar\Desktop\Services\Scripts\Power Shell Scripts\Sending reboot notification\Computers with last logged on user from collection Username003.csv"

Comments

Popular posts from this blog

The install4j wizard could not find a Java Runtime Environment on your system. Please locate a suitable JRE...

Clients Unable to update - "Cached cookie has expired or new PID is available"

Java Control Panel Icon "Application Not Found"