Powershell 3.0: Save posters from TMDb

очень простой листинг для сохранения постеров (на входе — имя файла, скачивание через Invoke-WebRequest, нужен api_key)


Param(
[Parameter(Mandatory=$true,Position=0,ValueFromPipeline=$true,HelpMessage="Provide a full path to movie files")]
[alias("p")]
[ValidateScript({ $_.Replace("[", "“[").Replace("]", "“]"); Test-Path -Path $_ -PathType 'Container'})]
[System.String]$path,
[Parameter(Position=1,ValueFromPipeline=$true)]
[alias("api")]
[int]$apikey = "098f6bcd4621d373cade4e832627b4f6" # Get your own! https://developers.themoviedb.org/3/getting-started/authentication
)
Add-Type -AssemblyName System.Web
Get-ChildItem -Path $path -Force | ?{!$_.PSIsContainer -and $_.Name -match "\.(avi|mkv|mp4|xvid)$"} | Select -First 10 | %{
$dir = $_.Directory.Fullname
$imdburi = "https://api.themoviedb.org/3/search/movie?query={0}&language=ru-RU&api_key={1}" -f [System.Web.HttpUtility]::UrlEncode([System.IO.Path]::GetFileNameWithoutExtension($_.Name)), $apikey
$movie = Invoke-WebRequest -Uri $imdburi
(ConvertFrom-Json $movie.Content).results | Select -First 1 | %{
#$r = Invoke-WebRequest -Uri ("https://api.themoviedb.org/3/movie/{0}/images?api_key={1}" -f $_.id, $apikey)
#$images = (ConvertFrom-Json $r).backdrops
$filename = "{0} – {1} ({2}){3}" -f $_.original_title, $_.title, ([datetime]::Parse($_.release_date)).Year, [System.IO.Path]::GetExtension($_.poster_path)
$filename = $filename -replace ":",' – ' -replace ' {2}', ' '
$filename = ([char[]]$filename | ?{[IO.Path]::GetinvalidFileNameChars() -notcontains $_ }) -join ''
Invoke-WebRequest -Uri ("https://image.tmdb.org/t/p/w640"+$_.poster_path) -OutFile "$dir\$filename"
}
}

How to switch off display with PowerShell

Define new static type Utilities.Display

# Turn display off by calling WindowsAPI.
 
# SendMessage(HWND_BROADCAST,WM_SYSCOMMAND, SC_MONITORPOWER, POWER_OFF)
# HWND_BROADCAST  0xffff
# WM_SYSCOMMAND   0x0112
# SC_MONITORPOWER 0xf170
# POWER_OFF       0x0002
 
Add-Type -TypeDefinition '
using System;
using System.Runtime.InteropServices;
 
namespace Utilities {
   public static class Display
   {
      [DllImport("user32.dll", CharSet = CharSet.Auto)]
      private static extern IntPtr SendMessage(
         IntPtr hWnd,
         UInt32 Msg,
         IntPtr wParam,
         IntPtr lParam
      );
 
      public static void PowerOff ()
      {
         SendMessage(
            (IntPtr)0xffff, // HWND_BROADCAST
            0x0112,         // WM_SYSCOMMAND
            (IntPtr)0xf170, // SC_MONITORPOWER
            (IntPtr)0x0002  // POWER_OFF
         );
      }
   }
}
'

Run
[Utilities.Display]::PowerOff()

or via func

function Switch-DisplayOff
{
[Utilities.Display]::PowerOff()
}

©2013 Jakub Jareš

Windows 10 does not reconnect to mapped network drives

Netlogon service doesn’t affect.

Solution:

as Startup script:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -WindowStyle Hidden -NonInteractive -NoLogo -File C:\Users\Vady\Documents\ReconnectNetworkDrivesAtStartup.ps1

Oneliner to Create Task via PowerShell 3.0+ (Grant Elevated Privileges):

$PS1file = '{0}\ReconnectNetworkDrivesAtStartup.ps1' -f [Environment]::GetFolderPath("MyDocuments");Invoke-WebRequest -Uri 'https://gist.github.com/anderssonjohan/8d3f958f29b4ae5c7802/raw' -OutFile $PS1file;Register-ScheduledTask -TaskName 'ReconnectNetworkDrivesAtStartup' -Description 'http://stackoverflow.com/a/29373760' -Trigger (New-ScheduledTaskTrigger -AtLogOn -User "$env:USERDOMAIN\$env:USERNAME") -Action (New-ScheduledTaskAction -Execute "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -Argument "-WindowStyle Hidden -NonInteractive -NoLogo -File $PS1file")

PS. For Win7/8 via app: MapDrive.exe (.NET Framework 2.0)

Powershell: Mirror [Win] builds of Adobe’s Flash Player

or a bit simpler one-line:
$out = [Environment]::GetFolderPath("Desktop") + "\Adobe Flash Player"; $c = New-Object System.Net.WebClient; @('install_flash_player_ax.exe','install_flash_player.exe','install_flash_player_ppapi.exe') | %{ $c.DownloadFile("https://fpdownload.macromedia.com/pub/flashplayer/latest/help/$_", "$out\$_") }

UPD: Adobe to remove direct Flash download links on January 22, 2016

Transliterate files and folders on Windows PC

этот Powershell скрипт позволяет автоматически переименовать файлы и папки содержащие юникод символы в их ANSI-синонимы (допустим ?, ?, ?, ?, ? станут e, a, c, u, u), Adi?s problemas de aplicaci?n! Continue reading Transliterate files and folders on Windows PC

Save logged user current Windows connections (VPN, Dialup, etc.)

сохранить Windows RAS-подключения в powershell: @("${env:PROGRAMDATA}\Microsoft\Network\Connections", "${env:USERPROFILE}\AppData\Roaming\Microsoft\Network\Connections") | ForEach-Object { Copy-Item -Force -Recurse -Path $_ -Destination $_.Replace(${env:SystemDrive}, 'c:\Backup\PBK') -ErrorAction "SilentlyContinue" | Out-Null }