send magic packet from windows with one click - windows

WOL works perfectly well via the Router, but that requires logging in to the control and browse trought the menus. I want to wake up the machine with one (double) click.
I tried
https://www.itprotoday.com/compute-engines/q-how-can-i-easily-send-magic-packet-wake-machine-my-subnet
(link from PowerShell - If/Else Statement Doesn't Work Properly)
Running a WOL PowerShell script through a batch file
Both throw Syntax Errors, wether I try them with cmd or the PowerShell.
Bash one-line command to send wake on LAN magic packet without specific tool
probably works in linux, but definitely not on windows
Is there a one-liner for Windows or anything that I can put in a bash batch file that actually works?
edit:
I got the second script to run (rename to .ps1, changed execution policy in PowerShell), but not to work.
Tried https://www.itnator.net/wake-lan-script-wol/ but this throws an exception:
Send-Packet : Ausnahme beim Aufrufen von "Parse" mit 1 Argument(en): "Die angegebene physikalische Adresse ist
ungültig."
In C:\wol-script.ps1:38 Zeichen:1
+ Send-Packet <mac-address>
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Send-Packet
Fehler beim Durchlaufen einer Auflistung: Die Sammlung wurde geändert. Der Enumerationsvorgang kann möglicherweise
nicht ausgeführt werden..
In C:\wol-script.ps1:29 Zeichen:3
+ $Error | Write-Error;
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Collecti...numeratorSimple:ArrayListEnumeratorSimple) [], Runt
imeException
+ FullyQualifiedErrorId : BadEnumeration

https://www.gammadyne.com/cmdline.htm#wol works, and it´s "only" 193K (go-wol is around 5MB).
I will put a batch script around it and then I´m done.
A deep link into the router setup would be smaller, but I guess that the AVM software does not allow that.
Only wish remaining is to hibernate the machine via Magic Packet, but my NIC is probably too old for that. I think I will use PuTTY for that.
Thanks everyone for digging!

Related

How to use Powershell to download and pipe to execution with arguments

I am trying to use powershell to download and execute a file with arguments:
. { iwr -useb https://github.com/int0x33/nc.exe/blob/master/nc64.exe?raw=true } | iex; <IP> 9001
I get this error:
Unexpected token '9001' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken
Any help appreciated.
Invoke-Expression (ie) is for interpreting and executing text as PowerShell code[1] - you can't use it to execute a binary download directly (which PowerShell fundamentally doesn't support).
Instead, use Invoke-WebRequest's (iwr's) -OutFile parameter to download the binary content to a local file and execute the latter:
iwr -useb https://github.com/int0x33/nc.exe/blob/master/nc64.exe?raw=true -OutFile ./nc64.exe
./nc64.exe $someIp 9001
[1] The obligatory warning: Invoke-Expression (iex) should generally be avoided and used only as a last resort, due to its inherent security risks. Superior alternatives are usually available. If there truly is no alternative, only ever use it on input you either provided yourself or fully trust - see this answer.

About MicrosoftTeams-TeamFunSettings

Today I found that the MicrosoftTeams powershell command Get-TeamFunSettings failed to run when the property GiphyContentRating value is "Allow all content".
Error info:
Get-TeamFunSettings : Error converting value "unknownFutureValue" to
type
'System.Nullable`1[Microsoft.TeamsCmdlets.PowerShell.Custom.Model.GiphyRatingType]'.
Path 'funSettings.giphyContentRating', line 1, position 844. At line:1
char:1
+ Get-TeamFunSettings -GroupId a3f33284-82a5-4643-a43d-401f2568177c
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-TeamFunSettings], JsonSerializationException
+ FullyQualifiedErrorId : Newtonsoft.Json.JsonSerializationException,Microsoft.TeamsCmdlets.PowerShell.Custom.GetF
unSettings
We are actively investigating this issue and a fix is expected shortly. Note this commend is in beta so instability is not unexpected.
Maybe it's just very new but according to the documentation of the command "Allow all content" is not an option. (I do think it should be one, though)
https://learn.microsoft.com/en-us/powershell/module/teams/set-teamfunsettings

PowerShell ISE vs Script

I am playing around powershell the idea is simple:
I want to verify if certain TCP port is open.
Now, I can run this as PowerShell script or I can run it in ISE.
Now, in ISE everything is fine, the script runs as supposed to.
When I run it as PowerShell Script however, I am getting error message:
Method invocation failed because [System.Net.Sockets.TcpClient] does not contain a method named 'ReceiveTimeout'.
At P:\checkTCP80.ps1:7 char:1
+ $tcpClient.ReceiveTimeout(5)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Code:
$servery = gc .\servers.txt
foreach ($server in $servery)
{
$tcpClient = New-Object System.Net.Sockets.TCPClient
$tcpClient.ReceiveTimeout(5)
$tcpClient.Connect($server,80)
Write-Host ($server, $tcpClient.Connected)
}
I have 2 questions:
How come, that the output parameter works just fine from ISE but does not work when this is launched as a script?
How to fix it?
According to the MS documentation on this class ReceiveTimeout is a property and not a method.
Try changing $tcpClient.ReceiveTimeout(5) to $tcpClient.ReceiveTimeout = 5

Copy files from corrupted HD using a powershell script

I am trying to use a script that ignores I/O errors on a HD, to copy whatever is good there into another HD.
I found this script here : http://81.165.15.172:1983/blog/2013/06/02/ignoring-device-io-errors-during-copy-with-powershell/comment-page-1/
(https://raw.github.com/DavorJ/PS-ForceCopy/master/Force-Copy.ps1)
that does just that...but i cant get it to work.
I am trying with command :
.\Force-Copy.ps1 -SourceFilePath "I:\Downloads\" -DestinationFilePath "H:\Downloads" -MaxRetries 6
but it gives me this weird error:
F:\SSDU\Desktop\Force-Copy.ps1 : Cannot validate argument on parameter 'SourceFilePath'. The "Test-Path -LiteralPath $_ -Type Leaf" validation script for the argument with value "I:\Downloads\" did not return true. Determine why the validation script failed and then try the command again.
At line:1 char:34
+ .\Force-Copy.ps1 -SourceFilePath "I:\Downloads\" -DestinationFilePath
"H:\Downlo ...
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Force-Copy.ps1], ParameterBind
ingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Force-Copy.ps1
Anyone knows how to use this in win-8 64-bit ?
-Thanks
So, it's not a PowerShell solution, but for getting whatever you can off a dying drive I recommend using Roadkil's Unstoppable Copier. You can download it from the author at:
http://www.roadkil.net/program.php/P29/Unstoppable%20Copier
I have had good success with that one.

PowerShell BITS to FTP :: Cannot Find Drive

Having seen examples of BITS being used to transfer files from http addresses as well as regular windows file shares, I thought I'd test pulling and pushing to/from ftp. I used the below powershell commands:
Start-BitsTransfer `
-Source ftp://username:password#ftp.somewhere.com/file.zip `
-Destination c:\temp\file.zip
Start-BitsTransfer `
-Source c:\temp\file2.zip `
-Destination ftp://username:password#ftp.somewhere.com/file2.zip
In both cases I got the error:
Start-BitsTransfer : Cannot find drive. A drive with the name 'ftp' does not exist.
At c:\temp\bits2ftp.ps1:3 char:1
+ Start-BitsTransfer `
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (ftp:String) [Start-BitsTransfer], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : DriveNotFound,Microsoft.BackgroundIntelligentTransfer.Management.NewBitsTransferCommand
As such, I assume this isn't possible... however thought I'd post on here in case there is a way to do this (e.g. does it work on certain ftp servers)?
Also posting on here since I've seen no mention of anyone attempting this before, so thought I'd provide a Google hit for the next person to wonder.
So far as I can tell, FTP is not currently supported.
HTTP and HTTPS Download Server Requirements: http://msdn.microsoft.com/en-us/library/aa362846(v=vs.85).aspx
HTTP and HTTPS Upload Server (IIS) Requirements: http://msdn.microsoft.com/en-us/library/aa363130(v=vs.85).aspx

Resources