@lakshmana
I'll say I'm not good with excel in powershell. I always avoid dealing with excel just because there are too many area that could goes wrong in the long term.
Posts made by stess
-
RE: Mail Allignment Issue
-
RE: Powershell Filter Data and Copy Data to new .csv file
@lakshmana said in Powershell Filter Data and Copy Data to new .csv file:
@stess said in Powershell Filter Data and Copy Data to new .csv file:
Hmmm.. I don't know how to post code here.$csvFile = ".\etc.csv" #dummy file. Change it to whereevery your file is at. $csvImport = Import-Csv $csvFile # Create Array for Exporting out data $csvArray = "" #this clear for testing purpose. But it works in production environment as well.. so I didn't bother to remove it. $csvArray = [System.Collections.ArrayList]@() # Entry count $lineCounter = 1 # Foreach Loop Foreach ($csvImportedItem in $csvImport){ $lineCounter++ #this let me know which line in the entry is the problem. $importedName = $csvImportedItem.Name $importedID = $csvImportedItem.ID $importedDept = $csvImportedItem.Department $importedNote = $csvImportedItem.Note if($importedNote -eq "C"){ $csvArray += $csvImportedItem "[$lineCounter] $importedName $importedID $importedDept $importedNote`n" #For outputing result. Testing purpose $csvImportedItem #For outputing result. Testing purpose } } $csvArray #For outputing result before exporting to new CSV #$csvArray | Export-Csv $NEWPATH -NoTypeInformation #destinate new path.
Name ID Department Note Caroline Bates 10035 Sales A Danny Harrison 11523 Customer Service B Armando Kelley 16423 Sales C Dorothy Colon 10245 HR B Joanna Sutton 19853 Accounting C Neat!
if there "ticket id" and "Assigned date" is there in heading means??
use " "
So$importedID = $csvImportedItem.ID
becomes
$importedID = $csvImportedItem."ticket id"
Keep the variable simple and easy to understand.
-
RE: Mail Allignment Issue
@lakshmana
Is the file XLSX or CSV? If it is CSV then the example I provided in an other thread works just fine. XLSX is a lot more trickier as you have to target the cells and what not. -
RE: Powershell Filter Data and Copy Data to new .csv file
@lakshmana
You should look more into technet articles. There are plenty of guide, tips and tricks, etc. -
RE: Powershell Filter Data and Copy Data to new .csv file
You mean send mail using whatever the data in the CSV is?
$SmtpServer = "smtp.com" $SmtpServerPort = "25 or 587" $SmtpFrom = "[email protected]" $SmtpTo = "[email protected]" $SmtpBody = "$csvArray" $SmtpSubject = "Subject" Send-MailMessage -SmtpServer $SmtpServer -Port $SmtpServerPort -From $SmtpFrom -To $SmtpTo -subject $SmtpSubject -body $SmtpBody
-
RE: Powershell Filter Data and Copy Data to new .csv file
@tim_g
Thanks! site bookmarked -
RE: Powershell Filter Data and Copy Data to new .csv file
Hmmm.. I don't know how to post code here.$csvFile = ".\etc.csv" #dummy file. Change it to whereevery your file is at. $csvImport = Import-Csv $csvFile # Create Array for Exporting out data $csvArray = "" #this clear for testing purpose. But it works in production environment as well.. so I didn't bother to remove it. $csvArray = [System.Collections.ArrayList]@() # Entry count $lineCounter = 1 # Foreach Loop Foreach ($csvImportedItem in $csvImport){ $lineCounter++ #this let me know which line in the entry is the problem. $importedName = $csvImportedItem.Name $importedID = $csvImportedItem.ID $importedDept = $csvImportedItem.Department $importedNote = $csvImportedItem.Note if($importedNote -eq "C"){ $csvArray += $csvImportedItem "[$lineCounter] $importedName $importedID $importedDept $importedNote`n" #For outputing result. Testing purpose $csvImportedItem #For outputing result. Testing purpose } } $csvArray #For outputing result before exporting to new CSV #$csvArray | Export-Csv $NEWPATH -NoTypeInformation #destinate new path.
Name ID Department Note Caroline Bates 10035 Sales A Danny Harrison 11523 Customer Service B Armando Kelley 16423 Sales C Dorothy Colon 10245 HR B Joanna Sutton 19853 Accounting C Neat!
-
RE: Powershell Filter Data and Copy Data to new .csv file
I use Foreach loop and pass the value to an Array if it meeds if() criteria. Then output the $true result back to the same CSV. I'll post the code later today.
Edit: can you post your csv data? Other wise I'll give you my data which has 4 column
Edit2: Also, for my script to works you need to manually change the if() statement manually each run. Easier to use Powershell ISE or any other powershell IDE. If you want to make it fancy then a custom textbox to return the value you are looking for is not a bad idea.
-
RE: What is it with people forcing their preferred Antivirus to other?
@scottalanmiller
I treat Windows Defender like iOS mail on iPhone. It's there.. and it works... but I'll be using MS Outlook instead of native mail app. Nothing wrong with it, but it doesn't have a lot of features other competitor offers (as you have mentioned). Still, I have no intention to disable it. -
What is it with people forcing their preferred Antivirus to other?
So I have a conversation with my colleague and the conversation somehow lead to asking what Antivirus I have installed on my computer. I said I have Malwarebytes and Windows Defender. He then proceed to say Windows Defender sucks (I'm not arguing with that since I rarely use it), and out of no where he said I should get rid of both of them and get ESET. [...] I'm like.. WTH. I would understand if he says he use ESET and how good it is, but to tell me what to do with my computer is a bit much. Beside, I've never use ESET before
What's your thought? What's your recommended (based on your experience)?
For me I am waiting for Malwarebytes' license to run out in November, and I'm going over to BitDefender. -
RE: Creating GUI for DateTime Picker output to CSV file
Old school style it is then.
Thanks! -
RE: Creating GUI for DateTime Picker output to CSV file
@dustinb3403 said in Creating GUI for DateTime Picker output to CSV file:
You can easily change the colors of this time picker from the script. Try the below.
###########################################################
TimeFramePicker.ps1
MeneerB 29/07/2015
###########################################################
Add-Type -AssemblyName System.Windows.FormsMain Form
$mainForm = New-Object System.Windows.Forms.Form
$font = New-Object System.Drawing.Font(“Consolas”, 13)
$mainForm.Text = ” Pick Time Frame”
$mainForm.Font = $font
$mainForm.ForeColor = “Black”
$mainForm.BackColor = “White”
$mainForm.Width = 300
$mainForm.Height = 200DatePicker Label
$datePickerLabel = New-Object System.Windows.Forms.Label
$datePickerLabel.Text = “date”
$datePickerLabel.Location = “15, 10”
$datePickerLabel.Height = 22
$datePickerLabel.Width = 90
$mainForm.Controls.Add($datePickerLabel)MinTimePicker Label
$minTimePickerLabel = New-Object System.Windows.Forms.Label
$minTimePickerLabel.Text = “min-time”
$minTimePickerLabel.Location = “15, 45”
$minTimePickerLabel.Height = 22
$minTimePickerLabel.Width = 90
$mainForm.Controls.Add($minTimePickerLabel)MaxTimePicker Label
$maxTimePickerLabel = New-Object System.Windows.Forms.Label
$maxTimePickerLabel.Text = “max-time”
$maxTimePickerLabel.Location = “15, 80”
$maxTimePickerLabel.Height = 22
$maxTimePickerLabel.Width = 90
$mainForm.Controls.Add($maxTimePickerLabel)DatePicker
$datePicker = New-Object System.Windows.Forms.DateTimePicker
$datePicker.Location = “110, 7”
$datePicker.Width = “150”
$datePicker.Format = [windows.forms.datetimepickerFormat]::custom
$datePicker.CustomFormat = “dd/MM/yyyy”
$mainForm.Controls.Add($datePicker)MinTimePicker
$minTimePicker = New-Object System.Windows.Forms.DateTimePicker
$minTimePicker.Location = “110, 42”
$minTimePicker.Width = “150”
$minTimePicker.Format = [windows.forms.datetimepickerFormat]::custom
$minTimePicker.CustomFormat = “HH:mm:ss”
$minTimePicker.ShowUpDown = $TRUE
$mainForm.Controls.Add($minTimePicker)MaxTimePicker
$maxTimePicker = New-Object System.Windows.Forms.DateTimePicker
$maxTimePicker.Location = “110, 77”
$maxTimePicker.Width = “150”
$maxTimePicker.Format = [windows.forms.datetimepickerFormat]::custom
$maxTimePicker.CustomFormat = “HH:mm:ss”
$maxTimePicker.ShowUpDown = $TRUE
$mainForm.Controls.Add($maxTimePicker)OD Button
$okButton = New-Object System.Windows.Forms.Button
$okButton.Location = “15, 130”
$okButton.ForeColor = “Black”
$okButton.BackColor = “White”
$okButton.Text = “OK”
$okButton.add_Click({$mainForm.close()})
$mainForm.Controls.Add($okButton)[void] $mainForm.ShowDialog()
Not the color, the the whole scrolling thing. instead of clicking up and down or type in, I like it to be all mouse like in the second picture.
-
Creating GUI for DateTime Picker output to CSV file
Hi, I am creating a GUI for end user to input date & time which will be output to CSV.
I am currently coding this on PowerShell since I am using $env:username so to identify who's requesting for audit purpose.While PowerShell has DateTimePicker, it looks old. This is what I found on a quick search
However, I want something more cleaner like this Time Picker
Any idea how can I use this XAML(not sure what this mean.. still researching more on it) in PowerShell?
-
Noobish question regarding automation email -> powershell
Hi guys,
Is there something like... powershell that read attachment then output the content to csv/excel file?
edit: something of an on-demand. Like.. an email come in and the script triggered immediately. -
powershell - delete row in csv file
Hi again,
I have a script that will loop through (ForEach-loop) the csv file. The script will test some criteria and if it is a match it will execute the command. Afterward, I want the script to delete that row as it is no longer valid. However, any other row that does not match the criteria should be left alone.This is what I have so far...
$CsvPath = "E:\Docs\Documents\Scripts\OOO.csv"
$CsvImport = Import-Csv $CsvPath
$CsvDate = Get-Date -Format 'M/d/yyy'
$CsvTime = Get-Date -Format 'hh:mm tt'
foreach ($CsvItem in $CsvImport)
{
$CsvEmailFrom = $csvItem.emailfrom
$CsvEmailTo = $csvitem.emailto
$CsvStartDate = [datetime]$CsvItem.startdate
$CsvStartDate = $CsvStartDate.ToShortDateString()
$CsvStartTime = [datetime]$CsvItem.starttime
$CsvStartTime = $CsvStartTime.ToString('hh:mm tt')
$CsvEndDate = [datetime]$CsvItem.enddate
$CsvEndDate = $CsvEndDate.ToString('hh:mm tt')
$CsvEndTime = [datetime]$CsvItem.endtime
$CsvEndTime = $CsvEndTime.ToString('hh:mm tt')
$customTime = [datetime]"09:59AM"
$customTime = $customTime.ToString('hh:mm tt')
#Invalid start/enddate
#($CsvStartDate -gt $CsvEndDate)if ($CsvDate -eq $CsvStartDate -and $CsvDate -le $CsvEndDate){
if ($CsvTime -gt $CsvStartTime){
$CsvStartDate.Remove($CsvStartDate)
Export-Csv $CsvPath
}}
}The table is a simple table
Edit: I did found couple ways to do this, but the script they provided is a lot more complicate than I like it to be. I am trying to avoid my future self from going crazy trying to understand WTF my past self has wrote.
-
RE: [help?] powershell - fixed credential for prompforcredential
@dustinb3403 said in [help?] powershell - fixed credential for prompforcredential:
@stess said in [help?] powershell - fixed credential for prompforcredential:
@dustinb3403 said in [help?] powershell - fixed credential for prompforcredential:
@stess you can pass credentials as a parameter within powershell.
After reading the article, and tinkering with the script, I found that I am passing the credential in the wrong function. I try to pass it in the testing, but I should have pass it in the connection phase.
Also, I'm surprised this article is so easy to understand.
So I guess I get the "Best answer"
Yes you did :winking_face:
-
RE: [help?] powershell - fixed credential for prompforcredential
@dafyre said in [help?] powershell - fixed credential for prompforcredential:
I can't find any documentation hardly at all about PSUtils.CredMan... If you know of a page, I'd be interested in seeing it.
What do you get if you do
$cred.gettype()
?This is how I convert a username / password into a PSCredential object... (My code is tested in WIndows 10 / PowerShell 5.1).
$username="blahblah" $password="youreallydontwantoknow" $password=convertto-securestring $password -asplaintext -force $adCred=New-Object System.Management.Automation.PSCredential -ArgumentList $username,$password
PSUtils is an in-house function written by the dev. It's about 400 lines of code. I'm not even bother to decipher it.
The problem I has is not the $cred parameters, but where it's being called. In the Test-Credential, it called another function. When I put the $cred = new-object... in that function it just works.
Basically, It has 5 functions working together: Platform, UserType, Credential, Connection, and Testing. I was trying to pass the $cred in Testing and Credential, but it didn't work. So I pass it in Connection and it works.
-
RE: [help?] powershell - fixed credential for prompforcredential
@dustinb3403 said in [help?] powershell - fixed credential for prompforcredential:
@stess you can pass credentials as a parameter within powershell.
After reading the article, and tinkering with the script, I found that I am passing the credential in the wrong function. I try to pass it in the testing, but I should have pass it in the connection phase.
Also, I'm surprised this article is so easy to understand.
-
[help?] powershell - fixed credential for prompforcredential
Hi guys,
I have a bit of a hiccup with a script I am trying to decode. The code is written by another company to use with their system. I am trying to make an automation where the powershell will read a script from CSV file then execute it on the same PSsession. The challenge I am facing is trying to put a fixed credential when it promp for credential.
This is the code in question. I am trying to put a fixed credential.
$cred = [PsUtils.CredMan]::PromptForCredential("Please enter credentials", "Please enter your credentials.", [Environment]::UserName, $target, "Generic", "None", [ref] $save);
I stumbled across [Creating a PS Credential from a Clear Text Password in Powershell] which seem to be the answer, but somehow it's not.
Under the same script there is a call function to test the credential. I believed this is what flagging the credential as invalid.
function Test-Credential([string]$plat, [Management.Automation.PSCredential]$cred)
NOTE: I tried to reached out to the dev that wrote this code, but the official answer is they will not assist me in modifying the code. The code is "as-is".
-
RE: [Help] Windows 10 lost AD profile [remote user]
@black3dynamite said in [Help] Windows 10 lost AD profile [remote user]:
@stess said in [Help] Windows 10 lost AD profile [remote user]:
Are you referred to the "Interactive logon: Number of previous logons to cache (in case domain controller is not available)
" ?Yes.
I just checked all the GPOs. We do not have this enabled. Should I enable it?