Italian (IT)

Const ADS_SCOPE_SUBTREE = 2

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 

objCommand.CommandText = "SELECT SamAccountName FROM 'LDAP://dc=MyDomain,dc=it' WHERE givenName='MyUser'"
Set objRecordSet = objCommand.Execute

If objRecordset.RecordCount = 1 Then
 WScript.Echo "Found"
Else
 WScript.Echo "Not found"
End If
objRecordset.Close

 

/* Quick Transaction */
BEGIN TRAN
 UPDATE myTable SET myField = 'Test' WHERE myId = 1
ROLLBACK TRAN
COMMIT TRAN

/* Extended Transaction */
BEGIN TRANSACTION CandidateDelete
GO
USE AdventureWorks2008R2
GO
UPDATE myTable SET myField = 'Test' WHERE myId = 1
GO
COMMIT TRANSACTION CandidateDelete
GO
ROLLBACK TRANSACTION CandidateDelete
GO

 

$Type = "Error"
$LogFile = "c:\LogFile.txt"
$NewestLogID = 500

Out-File $LogFile

Out-File $LogFile -append -inputobject "      >>@[email protected]< <"
Out-File $LogFile -append -inputobject "      >>@---   System EventLog   [email protected]< <"
Out-File $LogFile -append -inputobject "      >>@[email protected]< <"

$Log = "System"
Get-EventLog -computername MyComputer -logname $Log -newest $NewestLogID | ForEach-Object {
  If ($_.EntryType -eq $Type) {
   Out-File $LogFile -append -inputobject $_.timewritten
   Out-File $LogFile -append -inputobject $_.Source
   Out-File $LogFile -append -inputobject $_.Message
  }
}

Out-File $LogFile -append -inputobject " "
Out-File $LogFile -append -inputobject "      >>@[email protected]< <"
Out-File $LogFile -append -inputobject "      >>@---   Application EventLog   [email protected]< <"
Out-File $LogFile -append -inputobject "      >>@[email protected]< <"

$Log = "Application"
Get-EventLog -computername MyComputer -logname $Log -newest $NewestLogID | ForEach-Object {
  If ($_.EntryType -eq $Type) {
   Out-File $LogFile -append -inputobject $_.timewritten
   Out-File $LogFile -append -inputobject $_.Source
   Out-File $LogFile -append -inputobject $_.Message
  }
}

 

[void][reflection.assembly]::LoadWithPartialName("System.Windows.Forms")
$form = New-Object Windows.Forms.Form
$form.Text = "My first form"
$button = New-Object Windows.Forms.Button
$button.text="Click here!"
$button.Dock="fill"
$button.add_click({$form.close()})
$form.controls.add($button)
$form.Add_Shown({$form.Activate()})
$form.ShowDialog()

 

Come molti prima di me, anch'io inizierò a pubblicare alcuni snippets che ho conservato durante la mia attività di sviluppatore dotnet. Spero possano esservi di aiuto nella vostra attività di scrittura del codice.

Like many before me, I begin to publish some snippets that I kept in my dotnet development activities. I hope its can help you in your writing code activities.

Page 4 of 8

© 2007 - 2019 Bruno Tessaro. My life in the web. All right reserved.

This website uses cookies to ensure you get the best experience on our website.