$f = ${C:\Script\plgrowthgb.txt} $f[1]=$null ${C:\Script\plgrowthgb.txt} = $f
April 27, 2011
How to remove headers from table:
format-table -HideTableHeaders
April 4, 2011
$array1 = (Get-Content C:\Servers.csv) #no header in file $array2 = (Get-Content C:\backup.txt) #no header in file $array1 | where {$array2 -notcontains $_}
February 14, 2011
$ServiceList = Get-Service | Select-Object Name foreach ($item in $ServiceList) { $checkedlistbox1.Items.Add($item.Name) }
Or:
Get-Service | Select-Object Name | % { $checkedlistbox1.Items.Add($_.name) }
Special characters that works in PowerShell:
`0 Null `a Alert `b Backspace `f Form feed `n New line `r Carriage return `t Horizontal tab `v Vertical tab
$SmtpClient = new-object system.net.mail.smtpClient $MailMessage = New-Object system.net.mail.mailmessage $SmtpClient.Host = "smtprelay1.norr.se" $mailmessage.from = "bestallning_backup@norr.se" $mailmessage.To.add("catherina.holm@norr.se") $mailmessage.Subject = “Beställning Backup” $mailmessage.Body = “$valdserver $valdip” $smtpclient.Send($mailmessage)
February 10, 2011
$SelServer = $combobox1.SelectedItem foreach ($item in $list){ switch ($item.Server) {$SelServer { $textbox1.Text = $item.IP_adress $textbox2.Text = $item.iLoKort } } }
$list = $ServerTable | Where-Object {$_.Synlig -eq 'True'} | ` Select-Object Server,IP_adress,iLoKort | Sort-Object Server foreach ($item in $list) { $combobox1.items.add($item.Server) }
$SQLServerName="10.11.12.13" $SQLDatabase="Inventory" $DBConnection=New-Object System.Data.SQLClient.SQLConnection $DBConnection.ConnectionString="Server=$SQLServerName;Database=$SQLDatabase;` Trusted_Connection=False;User ID='sa';Password='password'" $DBConnection.Open() $DBCommand=New-Object System.Data.SQLClient.SQLCommand $DBCommand.Connection = $DBConnection $SelectStatement="SELECT *, Server AS Expr1 FROM tblServer" $DBCommand.CommandText=$SelectStatement $DBResult=$DBCommand.ExecuteReader() $ServerTable=New-Object system.data.datatable $ServerTable.load($DBResult) $list = $ServerTable | Where-Object {$_.Synlig -eq 'True'} | ` Select-Object Server,IP_adress | Sort-Object Server
foreach ($item in $list) {$item}
Subscribe to:
Posts (Atom)
Blog Archive
Tags
Links
About Me
- Catherina
- I took the PowerShell Master Class for Thomas Lee in Stockholm in march 2010.