Get-ChildItem -include “*.txt” -recur remove-item
otro método:
Get-ChildItem -rec -filter *.txt remove-item
Get-ChildItem -include “*.txt” -recur remove-item
otro método:
Get-ChildItem -rec -filter *.txt remove-item
$now = get-date
get-childitem . -recurse where-object {($now – $_.LastWriteTime).Days -lt 10} remove-item
Escrito en General
$fileName = “C:\File1.txt”
$provider = new-object -TypeName System.Security.Cryptography.SHA1CryptoServiceProvider
$fileContent = get-content $fileName
$fileContentBytes = [System.Text.Encoding]::UTF8.GetBytes($fileContent)
$hashBytes = $provider.ComputeHash($fileContentBytes)
$hashBytesEncoded = [System.Convert]::ToBase64String($hashBytes)
write-output $hashBytesEncoded
Escrito en General
$connectionString = “Server=(local);Database=AdventureWorks;Integrated Security=SSPI;”
$selectStatement = “select FirstName, LastName from Person.Contact;”
$connection = new-object System.Data.SqlClient.SqlConnection($connectionString)
$connection.Open()
$command = new-object System.Data.SqlClient.SqlCommand($selectStatement, $connection)
$reader = $command.ExecuteReader()
while ($reader.Read())
{
$firstName = $reader.GetString(0)
$lastName = $reader.GetString(1)
write-output “$firstName $lastName”
}
$connection.Close()
Escrito en General
$Table = new-object System.Data.DataTable
$sqlConn = new-object System.Data.SqlClient.SqlConnection(“Data Source=Server\sqlexpress;Initial Catalog=dbProducts;Integrated Security=True”)
$adapter = new-object System.Data.SqlClient.SqlDataAdapter(“Select * from Products”,$sqlConn)
$adapter.Fill($Table)
write-output $table
Escrito en General
Get-Service where {$_.Status -eq “Running”}
Escrito en General
$Dom = “LDAP://OU=Office,DC=powershellscripts,DC=domain,DC=com“
$Root = New-Object DirectoryServices.DirectoryEntry $Dom
$selector = New-Object DirectoryServices.DirectorySearcher
$selector.SearchRoot = $root
$adobj= $selector.findall() where {$_.properties.objectcategory -like “CN=Person*”}
foreach ($person in $adobj)
{
$prop=$person.properties
Write-host “First name: $($prop.givenname) Surname: $($prop.sn) User: $($prop.cn)”
}
Write-host “There are $($adobj.count) users in the $($root.name) domain”
Escrito en General
$Domain= New-Object DirectoryServices.DirectoryEntry “LDAP://DC=powershellscripts,DC=domain,DC=com“
$OU = $Domain.Create(“organizationalUnit”, “ou=PowerShell”)
$OU.SetInfo()
Escrito en General
$OU= New-Object DirectoryServices.DirectoryEntry “LDAP://OU=SampleMustExists,DC=powershellscripts,DC=domain,DC=com“
$User=$OU.Create(“user”,”CN=John”)
$User.put(“profilepath”,”\\server\share“)
$User.SetInfo()
Escrito en General
Hoy comienza un nuevo Blog sobre PowerShell. En los próximos días iremos agregando ejemplos para realizar todo tipo de tareas en nuestros equipos. Desde las más simples a las más complejas.

Escrito en General