TA的每日心情 | 奋斗 2022-8-5 08:00 |
---|
签到天数: 265 天 [LV.8]以坛为家I
|
本帖最后由 zyfsky666 于 2022-2-4 11:28 编辑
简单说,自动修改桌面背景图显示硬件信息,并可添加水印图片,祝大家虎年大吉,马到成功!
- cls
- Add-Type -AssemblyName System.Windows.Forms
- Add-Type -AssemblyName System.Drawing
- Add-Type -AssemblyName System.IO
- Add-Type -AssemblyName Microsoft.VisualBasic
- $SPI_SETDESKWALLPAPER = 20
- $API = Add-Type -memberDefinition @"
- [DllImport("user32.dll")]public static extern Int32 SystemParametersInfo(Int32 uAction, Int32 uParam, string lpvparam, Int32 fuwinIni);
- "@ -passthru -name WindowAPI ###引用系统API
- $Currentpath=Split-Path -parent $MyInvocation.MyCommand.Definition #获取脚本目录
- function Mypcinfo
- {
- param([string]$savepath)
- cls
- $system = Get-WmiObject -Class Win32_ComputerSystem
- #获取计算机域名、型号
- $domainname = $system.Domain
- $model = $system.Model
- $user=$system.UserName
- #获取计算机IP地址,取IP不为空的网卡IP地址
- $ips = gwmi Win32_NetworkAdapterConfiguration |?{ $_.IPAddress -ne $null}
- $ipdata=$null
- foreach ($ip in $ips )
- {
- #查找对应网速
- $ok=Get-WmiObject -Class Win32_NetworkAdapter -Filter "Description='$($ip.Description)'"|Select-Object Description,speed,MACAddress
- $ipdata+="网卡名称:$($ip.Description) IP地址:$($ip.IPAddress[0])`r`n 速率:$($ok.speed/1000/1000)M MAC地址:$($ok.MACAddress)`n`r"
- }
- $ipdata=$ipdata.Substring(0,$ipdata.Length-2)
- #获取操作系统版本
- $os = Get-WmiObject -Class Win32_OperatingSystem
- #获取操作系统版本
- $os_caption = $os.Caption
- If ($os_caption.Contains("Server 2008 R2 Enterprise"))
- {$os_caption_s = "Win2008"}
- ElseIf ($os_caption.Contains("Server 2003 Enterprise"))
- {$os_caption_s = "Win2003"}
- Else {$os_caption_s = $os.Caption}
- $osversion = $os_caption_s + " " + $os.OSArchitecture.Substring(0,2) + "bit"
- #获取CPU名称、单颗CPU核心数量*CPU个数
- $cpus = Get-WmiObject -Class win32_processor
- $cpunamecore=$null
- Foreach ($cpu in $cpus)
- {
- $cpunamecore += "$($cpu.name) $($cpu.NumberOfCores)核 $($cpu.NumberOfLogicalProcessors)线程`n`r"
- }
- $cpunamecore = $cpunamecore.Substring(0, $cpunamecore.Length-2)
- #获取内存大小
- $memorys = Get-WmiObject -Class Win32_PhysicalMemory
- $memorylist = $null
- $memorysize_sum = $null
- $memorysize_sum_n=0
- Foreach ($memory in $memorys)
- {
- #$memory|Select-Object * |fc
- $memorylist +="品牌:$($memory.Manufacturer.Trim()),"+"主频:$($memory.Speed)MZ,容量:" +($memory.capacity/1024/1024/1024).tostring("F1")+"GB`n`r"
-
- }
- $memorylist=$memorylist.Substring(0,$memorylist.Length-2)
- #获取磁盘信息
- $disks = Get-WmiObject -Class Win32_Diskdrive
- $disklist = $null
- #$disksize_sum = $null
- Foreach ($disk in $disks)
- {
-
- $disklist += ($disk.deviceid.replace("\\.\PHYSICALDRIVE","Disk") +":型号,$($disk.model) 容量," + [int]($disk.size/1024/1024/1024)+"GB`n`r")
- #$disksize_sum+=$disk.size
- }
- $disklist= $disklist.Substring(0, $disklist.Length-2)
- #获取计算机序列号、制造商
- $bios = Get-WmiObject -Class Win32_BIOS
- $sn = $bios.SerialNumber
- If ($sn.Substring(0,6) -eq "VMware")
- {$sn = "VMware"}
- If ($bios.Manufacturer.contains("Dell"))
- {$manufacturer = "Dell"}
- Elseif ($bios.Manufacturer.contains("HP"))
- {$manufacturer = "HP"}
- Elseif ($bios.Manufacturer.contains("Microsoft"))
- {
- $manufacturer = "Microsoft"
- $sn = ""
- }
- Else {$manufacturer = $bios.Manufacturer}
- $type = $manufacturer + " " + $model
- if ($type.contains("Microsoft Virtual Machine"))
- {$type = "Hyper-V"}
- #获取声卡信息
- $sound=Get-WmiObject -Class Win32_SoundDevice
- $soundnew=$null
- foreach ($i in $sound)
- {
- $soundnew+="$($i.name)`n`r"
- }
- $soundnew=$soundnew.Substring(0,$soundnew.Length-2)
- $soundnew=($soundnew -split '\n\r'|Sort-Object -Unique) -join "`n`r"
- #获取显卡信息
- $view=Get-WmiObject -Class Win32_VideoController
- $viewnew=$null
- foreach ($item in $view)
- {
- #判断是否小于1G,显示M
- $xc=$item.AdapterRAM/1024/1024/1024
- switch ($xc)
- {
-
- {$_ -lt 1} {$xcdata="$([math]::Ceiling($item.AdapterRAM/1024/1024))M"}
-
- Default {$xcdata="$([math]::Ceiling($item.AdapterRAM/1024/1024/1024))G"}
- }
- $viewnew+= "名称:$($item.Caption),显存大小:$($xcdata)`n`r"
- }
- $viewnew=$viewnew.Substring(0,$viewnew.Length-2)
- #获取主板信息
- $basebord=Get-WmiObject -Class Win32_BaseBoard -Property *
- $basebordnew="$($basebord.Manufacturer) $($basebord.Product)"
- #获取打印机信息
- $aa=Get-WmiObject -Class win32_printer -Filter "PortName like '%USB%' and Local=True"|select @{N="printer";e={
- if($_.WorkOffline -eq $true){return "$($_.DriverName)(离线)"} else{ return "$($_.DriverName)(在线)"}
- }}
- $pris=$aa.printer -join ','
- #获取显示器信息
- $Screen=Get-WmiObject -Class Win32_DesktopMonitor|Select-Object @{l="显示器";e={$($_.PNPDeviceID -split '\\')[1]}}
- $Scr=$Screen.显示器 -join ','
- $Infors= [ordered]@{计算机名=$env:ComputerName;当前用户=$user;网络=$ipdata;系统版本= $osversion;工作组或域=$domainname;内存=$memorylist;
- CPU=$cpunamecore;硬盘=$disklist;BIOS版本=$type;主板制造商=$basebordnew;声卡=$soundnew;显卡=$viewnew;显示器=$Scr;打印机=$pris}
- $news=[pscustomobject]$Infors
- #更新CSV
- if(Test-Path $savepath){
- $list=Import-Csv $savepath -Encoding Default
- if($list.计算机名.IndexOf($news.计算机名) -eq -1){
- $news|Export-Csv -NoTypeInformation $savepath -Encoding Default -Append -Force
- }
- }else{
- $news|Export-Csv -NoTypeInformation $savepath -Encoding Default -Force}
- return ($news.psobject.Members|?{$_.MemberType -eq "NoteProperty"}|%{"$($_.Name):$($_.Value)"}) -join "`r`n"
- #Write-Host "你的主机最大支持内存:$((Get-WmiObject -Class Win32_PhysicalMemoryarray).MaxCapacity/1024/1024)G" -ForegroundColor Red
- }
- $txt=mypcinfo -savepath C:\统计.csv
- $txt
- function showmybackpic
- {
- param(
- [string]$txt="恭迎寅虎乾坤啸,贺送金牛耕耘勤。新年飘下世纪雪,春风遍拂华夏人",
- [validatescript({if([System.IO.File]::Exists($_)){return $true}else { throw "找不到背景文件$($_)"}})][string]$picpath,
- [string]$fontkind="宋体",
- [int]$fontsize=9,
- [System.Drawing.Color]$color=[System.Drawing.Color]::White,
- [string]$logo
- )
- $image=[System.Drawing.Image]::FromFile($picpath)
- $pic=New-Object -TypeName System.Drawing.Bitmap($image)
- #$pic=[System.Drawing.Bitmap]::new($image)
- #$g=[System.Drawing.Graphics]::FromImage($pic)
- $sourceWidth = $pic.Width
- $sourceHeight=$pic.Height
- $size=New-Object -TypeName System.Drawing.Size([System.Windows.Forms.Screen]::PrimaryScreen.WorkingArea.Width,[System.Windows.Forms.Screen]::PrimaryScreen.WorkingArea.Height)
- #$size=[System.Drawing.Size]::new([System.Windows.Forms.Screen]::PrimaryScreen.WorkingArea.Width,[System.Windows.Forms.Screen]::PrimaryScreen.WorkingArea.Height)
- #计算宽度的缩放比例
- $nPercentW = ([float]$size.Width / [float]$sourceWidth);
- #计算高度的缩放比例
- $nPercentH = ([float]$size.Height / [float]$sourceHeight);
- #期望的宽度
- $destWidth = [int]($sourceWidth * $nPercentW);
- #期望的高度
- $destHeight=[int]($sourceHeight * $nPercentH);
- $bitmap=New-Object -TypeName System.Drawing.Bitmap($destWidth, $destHeight)
- #$bitmap = [System.Drawing.Bitmap]::new($destWidth, $destHeight);
- $g = [System.Drawing.Graphics]::FromImage([System.Drawing.Image]$bitmap)
- $g.InterpolationMode=[System.Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic
- #绘制图像
- $g.DrawImage($pic, 0, 0, $destWidth, $destHeight)
- #绘制文字
- #$S=[System.Drawing.SolidBrush]::new([System.Drawing.Color]::Chocolate)
- #$F=[System.Drawing.Font]::new("宋体",9,[System.Drawing.FontStyle]::Bold)
- $S=New-Object -TypeName System.Drawing.SolidBrush($color)
- $F=New-Object -TypeName System.Drawing.Font($fontkind,$fontsize,[System.Drawing.FontStyle]::Bold)
- $XMaxSize= $g.MeasureString($txt, $F)
- $Fwidth = [int]$XMaxSize.Width;
- $Fheight = [int]$XMaxSize.Height;
- $G.DrawString($txt,$F,$S,$destWidth-$Fwidth-50,20)
- #绘制logo
- if( ($PSBoundParameters.Keys -contains "logo") -and (Test-Path -Path $logo) ){
- $logoimage=[System.Drawing.Image]::FromFile($logo)
- #$logopic=[System.Drawing.Bitmap]::new($logoimage)
- $logopic=New-Object -TypeName System.Drawing.Bitmap($logoimage)
- $g.DrawImage($logoimage,$destWidth-$logopic.Width/2, $destHeight-$logopic.Height/2)
- $logopic.Dispose()
- }
- $info=New-Object -TypeName System.IO.FileInfo($picpath)
- $backpic=$info.Directory.FullName +'\' + [System.IO.Path]::GetFileNameWithoutExtension($picpath) +'.bmp'
- $bitmap.Save($backpic,[System.Drawing.Imaging.ImageFormat]::Bmp)
- $g.Dispose()
- $bitmap.Dispose()
- #更换桌面背景
- $API::SystemParametersInfo($SPI_SETDESKWALLPAPER,0,$backpic,1)
- }
- showmybackpic -txt $txt -fontsize 10 -color ([System.Drawing.Color]::Blue) -picpath "$($Currentpath)\一马当先.png" -logo "$($Currentpath)\logo.png"
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|