Advertisement
Guest User

Untitled

a guest
Jul 29th, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. ### Which AD groups do I manage?
  2. get-adgroup -LD "(ManagedBy=$((Get-ADUser -id $env:username).distinguishedname))" | select name
  3.  
  4. ### Edit the ISE profile
  5. if (Test-Path -Path $profile){
  6. psedit $profile
  7. }else{
  8. New-Item -Path $profile -ItemType file -Force -Value
  9. psedit $profile
  10. }
  11.  
  12. ### Change ISE tab to "Untitled1.ps1*"
  13. $psISE.CurrentPowerShellTab.Files.SetSelectedFile( ($psISE.CurrentPowerShellTab.Files | Where-Object {$_.DisplayName -eq "Untitled1.ps1*"}) )
  14.  
  15. ### Database connection (SQL Server)
  16. $Server = 'localhost\sqlexpress'
  17. $Database = 'MyDB'
  18. $query = 'select * from table'
  19.  
  20. $connection = New-Object -TypeName System.Data.SqlClient.SqlConnection
  21. $connection.ConnectionString = "Server=$Server;Database=$Database;Trusted_Connection=True;"
  22. $connection.Open()
  23.  
  24. $command = $connection.CreateCommand()
  25. $command.CommandText = $query
  26.  
  27. $adapter = New-Object -TypeName System.Data.SqlClient.SqlDataAdapter $command
  28. $dataset = New-Object -TypeName System.Data.DataSet
  29. $rowCount = $adapter.Fill($dataset)
  30. $connection.Close()
  31. $result = $dataset.Tables
  32.  
  33. Return $result.rows
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement