当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 13 号星期五 PowerShell 乐趣

作者:精品下载站 日期:2024-12-14 07:40:48 浏览:13 分类:玩电脑

13 号星期五 PowerShell 乐趣


[玩转系统] 13 号星期五 PowerShell 乐趣

今天的集合应该主要在 PowerShell 3.0 上运行。大多数项目也可以在 PowerShell 2.0 上运行。有些项目肯定需要 PowerShell 4.0。


#requires -version 3.0

<#
Most of these will also work on v2. A few are v4 examples

  ****************************************************************
  * DO NOT USE IN A PRODUCTION ENVIRONMENT UNTIL YOU HAVE TESTED *
  * THOROUGHLY IN A LAB ENVIRONMENT. USE AT YOUR OWN RISK.  IF   *
  * YOU DO NOT UNDERSTAND WHAT THIS SCRIPT DOES OR HOW IT WORKS, *
  * DO NOT USE IT OUTSIDE OF A SECURE, TEST SETTING.             *
  ****************************************************************
 #>

#1 Get 13 to the 13th power
[math]::Pow(13,13)

#2 Create a 13 character string with PowerShell 4.0
-join (33..123 | Get-Random -count 13).ForEach{$_ -as [CHAR]}

#for v3
-join (33..123 | Get-Random -count 13 | ForEach{$_ -as [CHAR]})

#3 Get the 13th process
Get-Process | Select -Skip 12 -first 1

#4 Get 13 odd numbers
1..50 | where { $_%2} | Select -first 13

#or in v4
(1..50).where{ $_%2} | Select -first 13

#5 Get 13!
1..13 | foreach -begin {$x=1} -Process {$x*=$_} -end {$x}

#6 Count by 13s
for ($i=13; $i -lt 100; $i+=13) {$i}

#7 Get 13 oldest temp files
dir $env:temp -file | Sort LastWriteTime | Select -first 13

#8 Get the square root of 13
[math]::Sqrt(13)

#9 Get the date and time in 13 days 13 hours 13 min and 13 seconds
(Get-Date).Add("13:13:13:13")

#10 Get the date and time that was 13 days 13 hours 13 min and 13 seconds in the past
(Get-Date).Subtract([timespan]"13:13:13:13")

#11 Open the 13th most recent post on PowerShell.org in a browser
Start-Process (Invoke-RestMethod -Uri http://powershell.org/wp/feed/)[12].Link

#12 Create 13 dummy test accounts in your domain
1..13 | foreach { net user "TEST$_" P@sswOrd123 /add /domain }

#or remove
1..13 | foreach { net user "TEST$_" /delete /domain}

#13 Get the next Friday the 13th.
$i=0
do {
 $i++
 $next = (Get-Date).AddDays($i)
} until ($next.DayOfWeek -eq "Friday" -AND $next.Day -eq 13)

Write-Host "The next Friday the 13th is in $i days on $($next.ToShortDateString())." -ForegroundColor Red

我什至不会向你展示任何结果。我会让你自己尝试一下。今天享受并远离湖。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯