mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-08 17:14:28 +01:00
Improved both scripts
This commit is contained in:
parent
cb6c6a3dec
commit
b8d42c207b
@ -2,6 +2,7 @@
|
|||||||
<#
|
<#
|
||||||
.SYNTAX ./set-wallpaper.ps1 [<image-file>] [<style>]
|
.SYNTAX ./set-wallpaper.ps1 [<image-file>] [<style>]
|
||||||
.DESCRIPTION sets the given image file as wallpaper
|
.DESCRIPTION sets the given image file as wallpaper
|
||||||
|
(style is either Fill, Fit, Stretch, Tile, Center, or Span)
|
||||||
.LINK https://github.com/fleschutz/PowerShell
|
.LINK https://github.com/fleschutz/PowerShell
|
||||||
.NOTES Author: Markus Fleschutz / License: CC0
|
.NOTES Author: Markus Fleschutz / License: CC0
|
||||||
#>
|
#>
|
||||||
@ -9,78 +10,45 @@
|
|||||||
param([string]$ImageFile = "", [string]$Style = "Fit")
|
param([string]$ImageFile = "", [string]$Style = "Fit")
|
||||||
|
|
||||||
function SetWallPaper {
|
function SetWallPaper {
|
||||||
<#
|
param([string]$Image, [ValidateSet('Fill', 'Fit', 'Stretch', 'Tile', 'Center', 'Span')][string]$Style)
|
||||||
|
|
||||||
.SYNOPSIS
|
$WallpaperStyle = switch($Style) {
|
||||||
Applies a specified wallpaper to the current user's desktop
|
"Fill" {"10"}
|
||||||
|
"Fit" {"6"}
|
||||||
.PARAMETER Image
|
"Stretch" {"2"}
|
||||||
Provide the exact path to the image
|
"Tile" {"0"}
|
||||||
|
"Center" {"0"}
|
||||||
|
"Span" {"22"}
|
||||||
|
}
|
||||||
|
|
||||||
.PARAMETER Style
|
if ($Style -eq "Tile") {
|
||||||
Provide wallpaper style (Example: Fill, Fit, Stretch, Tile, Center, or Span)
|
New-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name WallpaperStyle -PropertyType String -Value $WallpaperStyle -Force
|
||||||
|
New-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name TileWallpaper -PropertyType String -Value 1 -Force
|
||||||
|
} else {
|
||||||
|
New-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name WallpaperStyle -PropertyType String -Value $WallpaperStyle -Force
|
||||||
|
New-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name TileWallpaper -PropertyType String -Value 0 -Force
|
||||||
|
}
|
||||||
|
Add-Type -TypeDefinition @"
|
||||||
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
.EXAMPLE
|
public class Params
|
||||||
Set-WallPaper -Image "C:\Wallpaper\Default.jpg"
|
{
|
||||||
Set-WallPaper -Image "C:\Wallpaper\Background.jpg" -Style Fit
|
[DllImport("User32.dll",CharSet=CharSet.Unicode)]
|
||||||
|
public static extern int SystemParametersInfo (Int32 uAction,
|
||||||
|
Int32 uParam,
|
||||||
|
String lpvParam,
|
||||||
|
Int32 fuWinIni);
|
||||||
|
}
|
||||||
|
"@
|
||||||
|
|
||||||
#>
|
$SPI_SETDESKWALLPAPER = 0x0014
|
||||||
|
$UpdateIniFile = 0x01
|
||||||
param (
|
$SendChangeEvent = 0x02
|
||||||
[parameter(Mandatory=$True)]
|
|
||||||
# Provide path to image
|
|
||||||
[string]$Image,
|
|
||||||
# Provide wallpaper style that you would like applied
|
|
||||||
[parameter(Mandatory=$False)]
|
|
||||||
[ValidateSet('Fill', 'Fit', 'Stretch', 'Tile', 'Center', 'Span')]
|
|
||||||
[string]$Style
|
|
||||||
)
|
|
||||||
|
|
||||||
$WallpaperStyle = Switch ($Style) {
|
|
||||||
|
|
||||||
"Fill" {"10"}
|
$fWinIni = $UpdateIniFile -bor $SendChangeEvent
|
||||||
"Fit" {"6"}
|
|
||||||
"Stretch" {"2"}
|
|
||||||
"Tile" {"0"}
|
|
||||||
"Center" {"0"}
|
|
||||||
"Span" {"22"}
|
|
||||||
|
|
||||||
}
|
$ret = [Params]::SystemParametersInfo($SPI_SETDESKWALLPAPER, 0, $Image, $fWinIni)
|
||||||
|
|
||||||
If($Style -eq "Tile") {
|
|
||||||
|
|
||||||
New-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name WallpaperStyle -PropertyType String -Value $WallpaperStyle -Force
|
|
||||||
New-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name TileWallpaper -PropertyType String -Value 1 -Force
|
|
||||||
|
|
||||||
}
|
|
||||||
Else {
|
|
||||||
|
|
||||||
New-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name WallpaperStyle -PropertyType String -Value $WallpaperStyle -Force
|
|
||||||
New-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name TileWallpaper -PropertyType String -Value 0 -Force
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Add-Type -TypeDefinition @"
|
|
||||||
using System;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
public class Params
|
|
||||||
{
|
|
||||||
[DllImport("User32.dll",CharSet=CharSet.Unicode)]
|
|
||||||
public static extern int SystemParametersInfo (Int32 uAction,
|
|
||||||
Int32 uParam,
|
|
||||||
String lpvParam,
|
|
||||||
Int32 fuWinIni);
|
|
||||||
}
|
|
||||||
"@
|
|
||||||
|
|
||||||
$SPI_SETDESKWALLPAPER = 0x0014
|
|
||||||
$UpdateIniFile = 0x01
|
|
||||||
$SendChangeEvent = 0x02
|
|
||||||
|
|
||||||
$fWinIni = $UpdateIniFile -bor $SendChangeEvent
|
|
||||||
|
|
||||||
$ret = [Params]::SystemParametersInfo($SPI_SETDESKWALLPAPER, 0, $Image, $fWinIni)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
#!/snap/bin/powershell
|
#!/snap/bin/powershell
|
||||||
<#
|
<#
|
||||||
.SYNTAX ./smart-data2csv.ps1 [<wildcard>]
|
.SYNTAX ./smart-data2csv.ps1 [<directory>]
|
||||||
.DESCRIPTION converts the given S.M.A.R.T. data files (.json) to a CSV table for analysis
|
.DESCRIPTION converts the S.M.A.R.T. JSON files in the current/given directory to a CSV table for analysis
|
||||||
(use query-smart-data.ps1 to generate those .json files)
|
(use query-smart-data.ps1 to generate those JSON files)
|
||||||
.LINK https://github.com/fleschutz/PowerShell
|
.LINK https://github.com/fleschutz/PowerShell
|
||||||
.NOTES Author: Markus Fleschutz / License: CC0
|
.NOTES Author: Markus Fleschutz / License: CC0
|
||||||
#>
|
#>
|
||||||
|
|
||||||
param([string]$Wildcard = "")
|
param([string]$Directory = "")
|
||||||
|
|
||||||
function WriteCsvHeader { param([PSCustomObject]$File)
|
function WriteCsvHeader { param([PSCustomObject]$File)
|
||||||
foreach($Entry in $File.ata_smart_attributes.table) {
|
foreach($Entry in $File.ata_smart_attributes.table) {
|
||||||
@ -42,11 +42,11 @@ function WriteCsvDataRow { param([PSCustomObject]$File)
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($Wildcard -eq "" ) {
|
if ($Directory -eq "" ) {
|
||||||
$Wildcard = read-host "Enter path to S.M.A.R.T data (.json file)"
|
$Directory = "$PWD"
|
||||||
}
|
}
|
||||||
|
|
||||||
$Filenames = get-childitem -path $Wildcard
|
$Filenames = get-childitem -path "$Directory/SMART*.json"
|
||||||
$ModelFamily = $ModelName = $SerialNumber = ""
|
$ModelFamily = $ModelName = $SerialNumber = ""
|
||||||
|
|
||||||
[int]$Row = 1
|
[int]$Row = 1
|
||||||
|
Loading…
Reference in New Issue
Block a user