Powershell Set Wallpaper

From WikiWiki
Revision as of 23:45, 21 August 2020 by Mendel (talk | contribs)
(change visibility) (diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Get all info from azure, and put it as screensaver :-)

function getAllVMOptionsasync()
{
    #PSComputerName, RunspaceId, PSShowComputerName, DeploymentName, Name, Label, VM, InstanceStatus, IpAddress, InstanceStateDetails, PowerState, InstanceErrorCode, InstanceFaultDomain, InstanceName, InstanceUpgradeDomain, InstanceSize, AvailabilitySetName, DNSName, ServiceName, OperationDescription, OperationId, OperationStatus
	
	#$running=$false
    #$templist=@()
    $templist=$null
    $scriptblock={
        param($subscriptionName,$proxycreds)
		
		[System.Net.WebRequest]::DefaultWebProxy.Credentials = $proxycreds 

        #select-azuresubscription -SubscriptionName $subscriptionName
        (Get-AzureService).servicename | foreach {Get-AzureVM -ServiceName $_ }
    }
    $id = Start-Job –Name getAllVMOptions –Scriptblock $scriptblock -ArgumentList @($subscriptionName, $global:proxycreds) | select id

	$time=0
    while((Get-Job -id $id.id).State -ne "completed" )
    {
        $time++
		if($time -ge 100)
		{$time=0}
		#write-host "running"
		Write-Progress -activity "Waiting..." -status "Time: $time"  -PercentComplete ($time)
        Start-Sleep 1 
    }
    $templist = Receive-Job -Id $id.id
    $finallist = $templist
   # $list | ft



    #Get-Job -id $id.id
    Remove-Job  -id $id.id

    return $finallist

}

Function Set-WallPaper($Value)
{
write-host "setting wall to $Value"
Set-ItemProperty 'HKCU:\Control Panel\Desktop' -Name "WallpaperStyle" -Value 6 
Set-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name wallpaper -value $value
 rundll32.exe user32.dll, UpdatePerUserSystemParameters
}

$array=getAllVMOptionsasync

Add-Type -AssemblyName System.Drawing
$bmp = new-object System.Drawing.Bitmap 800,600 
$font = new-object System.Drawing.Font Consolas,12 
$brushBg = [System.Drawing.Brushes]::LightSkyBlue 
$brushFg = [System.Drawing.Brushes]::Black 
$graphics = [System.Drawing.Graphics]::FromImage($bmp) 
$graphics.FillRectangle($brushBg,0,0,$bmp.Width,$bmp.Height)

$hight=10
foreach($var in $array)
{
	$string=$var.Name +" - "+ $var.PowerState +" - "+ $var.InstanceSize
	write-host $string - $hight
	$graphics.DrawString($string,$font,$brushFg,300,$hight) 
	$hight += 20
} 
$graphics.Dispose() 
$bmp.Save(".\foo.png" )

$wall="$home\foo.png"
Set-WallPaper $wall