This script set a cluster resource dependency on a file server clustered resource Script : Get-Cluster -Name ClusterName |` Get-ClusterResource -Name “FileServer-(FileserverResourceHostname)(Cluster Disk 10)” |` Set-ClusterResourceDependency -Dependency [“FileserverResourceHostname”][and [“Cluster Disk 10”]] Reference (http://technet.microsoft.com/en-us/library/ee461029.aspx) Set-ClusterResourceDependency Specify the resources that a particular
Robocopy process management
Restart a service on remote servers
This script restart the service name “SMS Agent Host” on the servers listed in the file C:\temp\BOOK1.txt Script : ForEach($MachineName In $hosts){ $service = Get-Service -ComputerName $MachineName -name “sms agent host” Write-Host $MachineName, $service.status, $service.name (new-Object System.ServiceProcess.ServiceController(‘sms agent host’,$MachineName)).Stop() (new-Object
Rehost an Active Directory partition on one or more Global Catalog servers
Query tool GUI (Active Directory and SQL)
Query a SQL database
This script can be used to query an SQL database Script : $SqlConnection = New-Object System.Data.SqlClient.SqlConnection $SqlConnection.ConnectionString = “Server=DBServerHostname;Database=master;Integrated Security=True” $SqlConnection.Open() $SqlCmd = New-Object System.Data.SqlClient.SqlCommand $SqlCmd.CommandText = “select * from DatabaseName” $SqlCmd.Connection = $SqlConnection $reader = $SqlCmd.ExecuteReader() $Counter = $Reader.FieldCount
Query a DNS zone
Query and retrieve all A records of a specific DNS zone Script : $dns_entries = Get-WmiObject -namespace “root\MicrosoftDNS” -class MicrosoftDNS_Atype -ComputerName dnsServerName -Filter “DomainName = ‘domain.local.net'” foreach ($dnsrecord in $dns_entries) { $dnsrecord.IPAddress + “`t” + $dnsrecord.OwnerName.split(“.”)[0] + “`t” + $dnsrecord.OwnerName
Ping computers in a host file
Just fill the host file with host names you want to ping. Script : $PingMachines = Gc “C:\folder\hosts.txt” ForEach($MachineName In $PingMachines){ $PingStatus = Gwmi Win32_PingStatus -Filter “Address = ‘$MachineName'” | Select-Object StatusCode If ($PingStatus.StatusCode -eq 0){ Write-Host $MachineName ” :
Network file unlocker
Move computer objects to another Active Directory OU
This script will be useful if you want to move computer objects in the Active Directory filtered by name to a destination OU Script : $computerstomove = Get-ADComputer -LDAPFilter “(name=Desktop00*)” -SearchBase “CN=computers,DC=domain,DC=local,DC=net” foreach ($computertomove in $computerstomove) { Move-ADObject $computertomove -TargetPath