Skip to content

Instantly share code, notes, and snippets.

@JohnRoos
Last active August 29, 2015 14:24
Show Gist options
  • Save JohnRoos/293a5f093cd2927f5e07 to your computer and use it in GitHub Desktop.
Save JohnRoos/293a5f093cd2927f5e07 to your computer and use it in GitHub Desktop.
Scripts
### Which AD groups do I manage?
get-adgroup -LD "(ManagedBy=$((Get-ADUser -id $env:username).distinguishedname))" | select name
### Edit the ISE profile
if (Test-Path -Path $profile){
psedit $profile
}else{
New-Item -Path $profile -ItemType file -Force -Value
psedit $profile
}
### Change ISE tab to "Untitled1.ps1*"
$psISE.CurrentPowerShellTab.Files.SetSelectedFile( ($psISE.CurrentPowerShellTab.Files | Where-Object {$_.DisplayName -eq "Untitled1.ps1*"}) )
### Database connection (SQL Server)
$Server = 'localhost\sqlexpress'
$Database = 'MyDB'
$query = 'select * from table'
$connection = New-Object -TypeName System.Data.SqlClient.SqlConnection
$connection.ConnectionString = "Server=$Server;Database=$Database;Trusted_Connection=True;"
$connection.Open()
$command = $connection.CreateCommand()
$command.CommandText = $query
$adapter = New-Object -TypeName System.Data.SqlClient.SqlDataAdapter $command
$dataset = New-Object -TypeName System.Data.DataSet
$rowCount = $adapter.Fill($dataset)
$connection.Close()
$result = $dataset.Tables
Return $result.rows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment