Post

Visualizzazione dei post con l'etichetta Powershell

Solve server not reporting to WSUS

$updateSession = new-object -com "Microsoft.Update.Session"; $updates=$updateSession.CreateupdateSearcher().Search($criteria).Updates wuauclt /reportnow

Reboot is needed, check registry key value with Powershell and send email

 # the script is scheduled every morning at 9:00, by calling  #powershell -executionpolicy Bypass -File \\AD-DOMAIN-FQDN-OR-NETBIOS\sysvol\DOMAIN\scripts\SCRIPT.PS1 # $rebootcheck = Get-ItemProperty "HKLM:\Software\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" -Name RebootCheckRequired if ($rebootcheck.RebootCheckRequired -eq 1) { write-output "reboot needed" $mailfrom = "email@email.com" $mailto = "email@email.com" $mailserver = "SmtpSERVER.email.com" $mailusername = "domain\username" $subject = "$(hostname) need reboot for updates" $body = "reboot asap" [System.Net.ServicePointManager]::SecurityProtocol = 'Tls,TLS11,TLS12' $getpw = ConvertTo-SecureString 'PLAINTEXTPASSWORD' -AsPlainText -Force $mycreds = New-Object System.Management.Automation.PSCredential($mailusername, $getpw) [System.Net.ServicePointManager]::ServerCertificateValidationCallback = { return $t...

Powershell screenshot sketch

$i=0  [Reflection.Assembly]::LoadWithPartialName("System.Drawing") function screenshot([Drawing.Rectangle]$bounds, $path) {    $bmp = New-Object Drawing.Bitmap $bounds.width, $bounds.height    $graphics = [Drawing.Graphics]::FromImage($bmp)    $graphics.CopyFromScreen($bounds.Location, [Drawing.Point]::Empty, $bounds.size)    $bmp.Save($path)    $graphics.Dispose()    $bmp.Dispose() } $bounds = [Drawing.Rectangle]::FromLTRB(0, 0, 1894, 895) screenshot $bounds "C:\screen\screenshot$i.png" $i++

Create Natted virtual switch on Hyper-V

on Powershell  New-VMSwitch -SwitchName "NAT_192-168-140-0" -SwitchType Internal get-netadapter # prendi l'interfaceIndex del vswitch per il comando dopo New-NetIPAddress -IPAddress 192.168.140.1 -PrefixLength 24 -InterfaceIndex XX # preso da prima New-NetNAT -Name "NATnetwork_192-168-140-0" -InternalIPInterfaceAddressPrefix 192.168.140.0/24  

Cannot connect to RDP after enabling Group Policy (in my case "SSL Cipher Suites order Policy")

preface: A Windows Server 2012 R2 domain joined, I'm not a Domain Admin on the customer AD, I'm a Local Server Administrator.    After enabling the SSL Cipher Suites order policy and a reboot, RDP connection getting refused, "an internal error occurred" and other error messages. I just realized that I didn't followed the instructions correctly, closing me out: 1. Open a blank notepad document. 2. Copy and paste the list of available suites into it. 3. Arrange the suites in the correct order; remove any suites you don't want to use. 4. Place a comma at the end of every suite name except the last. Make sure there are NO embedded spaces. 5. Remove all the line breaks so that the cipher suite names are on a single, long line. 6. Copy the cipher-suite line to the clipboard, then paste it into the edit box. The maximum length is 1023 characters. I completely miss the 4 and 5 points.  following a way to solve the mistake:  from another Domain joined Server, open MMC ...