How to Schedule remote reboot for a list of Computer

This task can be easly done not only via batch but also with powershell. This is the string to add on scheduler task:

powershell -Command "& {Restart-Computer -ComputerName (Get-Content D:\Scripts\Clients_Reboot_List.txt) -Force}"

 

Advertisements

How to Disable Network Card from CMD

If you need to disable a NIC from command line on windows this is the path:

WMI:

wmic nic get name, index

Check then index of the NIC you want to disable and run:

wmic path win32_networkadapter where index=[NIC number] call disable

…change the [NIC Number] with the index of the wanted network card.

Now in the control panel, you should see that the desired network connection is now disabled.

To enable it again:

wmic path win32_networkadapter where index=[NIC number] call enable

If you what to disable some type of devices (like WiFi), type this command to check the NetConnectionID attribute:

wmic nic get name, index, NetConnectionID

WMI_NIC

and disable it selecting by NetConnectionID:

wmic path win32_networkadapter where 'NetConnectionID like "%Wi-Fi%" ' call disable

or

wmic path win32_networkadapter where NetConnectionID="Wi-Fi" call disable

All these tasks can be done with netsh or powershell.

Netsh:

netsh interface show interface
netsh interface set interface "Wi-Fi" disabled

Powershell:

Get-NetAdapter
Get-NetAdapter -Name wi-fi | Disable-NetAdapter -Confirm:$false

How to Write on the same line with Write-Output

Powershell cmdlet Write-Output on some case is preferable instead of Write-Host; I need to use Start-Transcript and (probably a bug) Write-Host do not make any entry on transcript file.

But Write-Output is missing some nice features like -nonewline.. I need to append a string on the same line of previous output:

try {
    start-transcript -path C:\transcript.txt -Append
    # My Job
    Write-Output "1 - Job one"
    [console]::setcursorposition($([console]::Cursorleft + 25),$([console]::CursorTop - 1))
    Move-Item C:\Test.txt C:\TestDone.txt -force -ea Stop
    Write-Output "    [OK]"
}
catch [Exception] {
    Write-Output "    [FAIL]"
    $ScriptError = $_.Exception.Message
    Write-Warning $ScriptError
}
finally {
    Stop-Transcript
}

The trick was done by:

[console]::setcursorposition

[console]::Cursorleft is your current column
[console]::CursorTop is you current line

Probably with the same trick you can overwrite the previews output…

How to Disable SMB1

WannaCry and Co. suggest that it’s time to remove some old protocol, and SMB1 it’s one of that.

Here you find a script that is usefull for that; run it as admin rights:

Disable-SMB1.cmd

This batch call a powershell script (check that all the scripts is stored on the same folder and that the execution path is where you store the scripts)

I used a batch to bypass the powershell signature and make easier for helpdesk to runas as admin.

For disable it with GPO, check this:
https://support.microsoft.com/en-us/help/2696547/how-to-enable-and-disable-smbv1-smbv2-and-smbv3-in-windows-and-windows

How to Delete WSD printer Port

I had a Windows 2012 R2 printserver where a WSD port was still there after printer deletion. Delete only the port was not possible (operation not permit).

The spooler will delete the port only if it is assigned to a printer and you are deleting the printer. As workaround you can create a fake printer using this port and a preinstalled driver, then delete the printer.

But using powershell is possible to work less…

List all the WSD Printer Port:

Get-PrinterPort -Name wsd*

Delete the WSD Printer Port (PortName):

Remove-PrinterPort -Name PortName

or if you have only one WSD port:

Remove-PrinterPort -Name (Get-PrinterPort -Name wsd*).name