here goes..
Below are the scripts that are Power Shell (.ps1) files ( I have attached the files in the "AndyScript.zip" that should be attached to this post)
you will need to set the permissions for these scripts to run.
Search for Powershell, right click and run as administrator.
>From the admin-enabled Powershell prompt, type "Set-ExecutionPolicy
RemoteSigned" (you can press tab to auto-complete these)
This will tell Powershell that any scripts that come from somewhere else
need to be digitally signed, but that scripts created locally can run
without being signed.
to get the Task Scheduler to work I found this link....
http://community.spiceworks.com/how_to/ ... -schedulerIn the Task Scheduler under the "Actions" tab I had to put the path of the script in the "start in" field for it to work.
There are two text files that are associated with this one is for logging, the other stores some commands, I think I have attached the files but I am a newbe when it comes to Posting on this forum.
Attachment:
AndyScript.zip [2.91 KiB]
Downloaded 2149 times
also you will need to edit the -hostname, -user, and the -password to fit your setup, this is done in the shut down script.
Well I hope I got most of this correct, again I mess with the server so little I forget how to administer it!
Good Luck! Andy
wake on lan...# Script to wake up a computer.
#
# v1.0 - 2012-07-30 Pedro Castro
# usage:
# .\Ligar-Maquina.ps1 -mac 00:1D:92:51:4C:41
param(
[string]$mac = '00-27-0e-32-f1-83' #address of the network card (MAC address)
)
#checks the syntax of MAC address
if (!(($mac -like "*:*:*:*:*:*") -or ($mac -like "*-*-*-*-*-*"))){
write-error "mac address not in correct format"
break
}
#build magic package
http://en.wikipedia.org/wiki/Wake-on-LAN#Magic_packet $string=@($mac.split(":""-") | foreach {$_.insert(0,"0x")})
$target = [byte[]]($string[0], $string[1], $string[2], $string[3], $string[4], $string[5])
# The magic packet is a broadcast frame containing anywhere within its payload 6 bytes of all 255 (FF FF FF FF FF FF in hexadecimal)
$packet = [byte[]](,0xFF * 102)
# followed by sixteen repetitions of the target computer's 48-bit MAC address, for a total of 102 bytes.
6..101 |% { $packet[$_] = $target[($_%6)]}
# .NET framework lib para sockets
$UDPclient = new-Object System.Net.Sockets.UdpClient
$UDPclient.Connect(([System.Net.IPAddress]::Broadcast),4000)
$UDPclient.Send($packet, $packet.Length) | out-null
Write-Host "magic packet sent to"$mac
Here is the Shut down code....#."scriptable telnet client"
function read-stream ([parameter(position=0,mandatory=$true)][validatenotnull()]
[System.Net.Sockets.NetworkStream]$stream,
[String]$expect = "")
{
$buffer = new-object system.byte[] 1024
$enc = new-object system.text.asciiEncoding
## Read all the data available from the stream, writing it to the
## screen when done.
## Allow data to buffer
start-sleep -m 1000
$output = ""
#while($stream.DataAvailable -or $output -notmatch $expect)
while($stream.DataAvailable)
{
$read = $stream.Read($buffer, 0, 1024)
$output = "$output$($enc.GetString($buffer, 0, $read))"
## Allow data to buffer for a bit
start-sleep -m 1000
}
$output.split("`n")
}
function send-command ([parameter(position=0,Mandatory=$true)][validatenotnull()]
[String]$hostname,
[parameter(position=1, mandatory=$true)][validatenotnull()]
[String]$User,
[parameter(position=2, mandatory=$true)][validatenotnull()]
[String]$Password,
[parameter(position=3, mandatory=$true, valuefrompipeline=$true)][validatenotnull()]
[String]$InputObject,
[string]$expect = "")
{
begin
{
$sock = new-object system.net.sockets.tcpclient($hostname,23)
$str = $sock.GetStream()
$wrt = new-object system.io.streamwriter($str)
read-stream($str)
$wrt.writeline($user)
$wrt.flush()
read-stream($str)
$wrt.writeline($password)
$wrt.flush()
read-stream($str)
}
process
{
$wrt.writeline($InputObject)
$wrt.flush()
#read-stream($str, $expect)
read-stream($str)
}
end
{
$wrt.writeline("exit")
$wrt.flush()
read-stream($str)
## Close the streams
$wrt.Close()
$str.Close()
$sock.close()
}
}
Get-content cmdList.txt | send-command -hostname 192.168.1.200 -user "admin" -password "nas" | Tee-Object -Variable teeToAppend
out-file .\log.txt -InputObject $teeToAppend -append