Jump to content

Recommended Posts

Posted

Morning all,

 

My Powershell knowledge is fairly basic. I have a little script that provides the user with a single text box. The data that they enter here is saved as $x

 

I now want to create a CSV file that has the value of $x in it, but i'm struggling a little bit.

 

Does anybody know how to do this? I imagine it would actually be fairly simple!

 

Many thanks

Posted

Wrap it up as an object :

 

$A = "Hello";

$ObjA = New-Object PSObject -Property @{ FirstColumn = $A }
Export-Csv -InputObject $ObjA -Path C:\tmp\test.csv -NoTypeInformation

Posted
Is $x a variable or an array? Makes a difference to the answer!

 

You know as much as I do haha, here's the script

 

[void] [system.Reflection.Assembly]::LoadWithPartialName("System.Drawing") [void] [system.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") 


$objForm = New-Object System.Windows.Forms.Form 
$objForm.Text = "Update Special Password"
$objForm.Size = New-Object System.Drawing.Size(300,200) 
$objForm.StartPosition = "CenterScreen"


$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter") 
   {$x=$objTextBox.Text;$objForm.Close()}})
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape") 
   {$objForm.Close()}})


$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(75,120)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.Add_Click({$x=$objTextBox.Text;$objForm.Close()})
$objForm.Controls.Add($OKButton)


$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(150,120)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.Add_Click({$objForm.Close()})
$objForm.Controls.Add($CancelButton)


$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,20) 
$objLabel.Size = New-Object System.Drawing.Size(280,20) 
$objLabel.Text = "Enter the new Special Password and press OK"
$objForm.Controls.Add($objLabel) 


$objTextBox = New-Object System.Windows.Forms.TextBox 
$objTextBox.Location = New-Object System.Drawing.Size(10,40) 
$objTextBox.Size = New-Object System.Drawing.Size(260,20) 
$objForm.Controls.Add($objTextBox) 


$objForm.Topmost = $True


$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()

Posted

So you could add :

 

$A=$ObjTextBox.Text
$ObjA = New-Object PSObject -Property @{ FirstColumn = $A }
Export-Csv -InputObject $ObjA -Path C:\tmp\test.csv -NoTypeInformation

  • Thanks 1
Posted
So you could add :

 

$A=$ObjTextBox.Text
$ObjA = New-Object PSObject -Property @{ FirstColumn = $A }
Export-Csv -InputObject $ObjA -Path C:\tmp\test.csv -NoTypeInformation

 

Good stuff, all working. Thanks guys!

Posted
So you could add :

 

$A=$ObjTextBox.Text
$ObjA = New-Object PSObject -Property @{ FirstColumn = $A }
Export-Csv -InputObject $ObjA -Path C:\tmp\test.csv -NoTypeInformation

 

Yes. You beat me to the response both times!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...