52powershell
本帖最后由 dengshen 于 2023-12-24 02:02 编辑# 前言
本人自学powershell 一年了
用到了power shell的各种好处
好处一 可以装逼
可以尽情使用
看到吧友
本帖主要向吧友介绍 powershell,为吧友指明一条学习的道理,并寻找
powershell 简称 pwsh,是自win7 微软推出的一款开源终端,直接在运行里输入powershell 就能打开powershell了,非常简单,在Windows系统不用任何环境配置,在其他系统也能安装,但是以为没有net,功能不如Windows齐全。
,powershell 脚本搭载了大量cmdlet
分为基本cmdlet 如
## process 类(经常用于管理电脑process)
Name CategoryModule Synopsis
---- -------------- --------
Enter-PSHostProcess Cmdlet Microsoft.PowerShell.Core Connects to and enters into an interactive session with a local pro...
Exit-PSHostProcess Cmdlet Microsoft.PowerShell.Core Closes an interactive session with a local process.
Get-PSHostProcessInfo Cmdlet Microsoft.PowerShell.Core Gets process information about the PowerShell host.
Debug-Process Cmdlet Microsoft.PowerShell.M... Debugs one or more processes running on the local computer.
Get-Process Cmdlet Microsoft.PowerShell.M... Gets the processes that are running on the local computer or a remo...
Start-Process Cmdlet Microsoft.PowerShell.M... Starts one or more processes on the local computer.
Stop-Process Cmdlet Microsoft.PowerShell.M... Stops one or more running processes.
Wait-Process Cmdlet Microsoft.PowerShell.M... Waits for the processes to be stopped before accepting more input.
ConvertTo-ProcessMitigationPolicy Cmdlet ProcessMitigations ConvertTo-ProcessMitigationPolicy...
Get-ProcessMitigation Cmdlet ProcessMitigations Get-ProcessMitigation...
Set-ProcessMitigation Cmdlet ProcessMitigations Set-ProcessMitigation...
...
## object 类cmdlet(经常用于管理psobject)
Name CategoryModule Synopsis
---- -------------- --------
ForEach-Object Cmdlet Microsoft.PowerShell.Core Performs an operation against each item in a collection of input ob...
Where-Object Cmdlet Microsoft.PowerShell.Core Selects objects from a collection based on their property values.
Compare-Object Cmdlet Microsoft.PowerShell.U... Compares two sets of objects.
Group-Object Cmdlet Microsoft.PowerShell.U... Groups objects that contain the same value for specified properties.
Measure-Object Cmdlet Microsoft.PowerShell.U... Calculates the numeric properties of objects, and the characters, w...
New-Object Cmdlet Microsoft.PowerShell.U... Creates an instance of a Microsoft .NET Framework or COM object.
Register-ObjectEvent Cmdlet Microsoft.PowerShell.U... Subscribes to the events that are generated by a Microsoft .NET Fra...
Select-Object Cmdlet Microsoft.PowerShell.U... Selects objects or object properties.
Sort-Object Cmdlet Microsoft.PowerShell.U... Sorts objects by property values.
Tee-Object Cmdlet Microsoft.PowerShell.U... Saves command output in a file or variable and also sends it down t...
Get-WmiObject Cmdlet Microsoft.PowerShell.M... Gets instances of Windows Management Instrumentation (WMI) classes ...
Remove-WmiObject Cmdlet Microsoft.PowerShell.M... Deletes an instance of an existing Windows Management Instrumentati...
about_Objects HelpFile
about_Object_Creation HelpFile
about_PSCustomObject HelpFile
## invoke 类 (经常用于远程调用,或者远程请求)
Invoke-Command Cmdlet Microsoft.PowerShell.Core Runs commands on local and remote computers.
Invoke-History Cmdlet Microsoft.PowerShell.Core Runs commands from the session history.
Invoke-Expression Cmdlet Microsoft.PowerShell.U... Runs commands or expressions on the local computer.
Invoke-RestMethod Cmdlet Microsoft.PowerShell.U... Sends an HTTP or HTTPS request to a RESTful web service.
Invoke-WebRequest Cmdlet Microsoft.PowerShell.U... Gets content from a web page on the internet.
Invoke-Item Cmdlet Microsoft.PowerShell.M... Performs the default action on the specified item.
Invoke-WmiMethod Cmdlet Microsoft.PowerShell.M... Calls WMI methods.
Invoke-WSManAction Cmdlet Microsoft.WSMan.Manage... Invokes an action on the object that is specified by the Resource U...
Invoke-OperationValidation FunctionMicrosoft.PowerShell.O... Invokes Operation Validation Framework tests.
Invoke-Mock FunctionPester ...
Invoke-Pester FunctionPester ...
Invoke-CommandInDesktopPackage Cmdlet Appx Invoke-CommandInDesktopPackage...
Invoke-CimMethod Cmdlet CimCmdlets Invoke-CimMethod...
Invoke-DscResource Cmdlet PSDesiredStateConfigur... Invoke-DscResource...
Invoke-AsWorkflow FunctionPSWorkflowUtility ...
Invoke-TroubleshootingPack Cmdlet TroubleshootingPack Invoke-TroubleshootingPack...
## Azure 类 (AUZRE)
。。。
## job类(经常用于后台运行,或者周期运行)
Name CategoryModule Synopsis
---- -------------- --------
Debug-Job Cmdlet Microsoft.PowerShell.Core Debugs a running background, remote, or Windows PowerShell Workflow job.
Get-Job Cmdlet Microsoft.PowerShell.Core Gets PowerShell background jobs that are running in the current session.
Receive-Job Cmdlet Microsoft.PowerShell.Core Gets the results of the PowerShell background jobs in the current session.
Remove-Job Cmdlet Microsoft.PowerShell.Core Deletes a PowerShell background job.
Start-Job Cmdlet Microsoft.PowerShell.Core Starts a PowerShell background job.
Stop-Job Cmdlet Microsoft.PowerShell.Core Stops a PowerShell background job.
Wait-Job Cmdlet Microsoft.PowerShell.Core Waits until one or all of the PowerShell jobs running in the session are in a terminating state.
Resume-Job Cmdlet Microsoft.PowerShell.Core Restarts a suspended job.
Suspend-Job Cmdlet Microsoft.PowerShell.Core Temporarily stops workflow jobs.
Add-JobTrigger Cmdlet PSScheduledJob Adds job triggers to scheduled jobs.
Disable-JobTrigger Cmdlet PSScheduledJob Disables the job triggers of scheduled jobs.
Disable-ScheduledJob Cmdlet PSScheduledJob Disables a scheduled job.
Enable-JobTrigger Cmdlet PSScheduledJob Enables the job triggers of scheduled jobs.
Enable-ScheduledJob Cmdlet PSScheduledJob Enables a scheduled job.
Get-JobTrigger Cmdlet PSScheduledJob Gets the job triggers of scheduled jobs.
Get-ScheduledJob Cmdlet PSScheduledJob Gets scheduled jobs on the local computer.
Get-ScheduledJobOption Cmdlet PSScheduledJob Gets the job options of scheduled jobs.
New-JobTrigger Cmdlet PSScheduledJob Creates a job trigger for a scheduled job.
New-ScheduledJobOption Cmdlet PSScheduledJob Creates an object that contains advanced options for a scheduled job.
Register-ScheduledJob Cmdlet PSScheduledJob Creates a scheduled job.
Remove-JobTrigger Cmdlet PSScheduledJob Delete job triggers from scheduled jobs.
Set-JobTrigger Cmdlet PSScheduledJob Changes the job trigger of a scheduled job.
Set-ScheduledJob Cmdlet PSScheduledJob Changes scheduled jobs.
Set-ScheduledJobOption Cmdlet PSScheduledJob Changes the job options of a scheduled job.
Unregister-ScheduledJob Cmdlet PSScheduledJob Deletes scheduled jobs on the local computer.
Resume-PrintJob FunctionPrintManagement ...
Suspend-PrintJob FunctionPrintManagement ...
Restart-PrintJob FunctionPrintManagement ...
Get-PrintJob FunctionPrintManagement ...
Remove-PrintJob FunctionPrintManagement ...
Get-StorageJob FunctionStorage ...
Stop-StorageJob FunctionStorage ...
about_Jobs HelpFile
about_Job_Details HelpFile
about_Remote_Jobs HelpFile
about_Scheduled_Jobs HelpFile
about_Scheduled_Jobs_Advanced HelpFile
about_Scheduled_Jobs_Basics HelpFile
about_Scheduled_Jobs_Troublesh... HelpFile
## 基本类
get-help
new-item
get-childitem
move-item
get-content
add-content
remove-item
。。。
# powershell 文件有三种 ps1,psm1,psd1
ps1 powershell 脚本文件
psm1 powershell 模组文件
psd1 ps1 的 manifest
# 3
powershell 和 python一样也有powershellget 可以直接下载别人的moduel ,可以查看微软的的 如何安装 PowerShellGet - PowerShell | Microsoft LearnInstalling a PowerShell Module - PowerShell | Microsoft Learn
powershell Azure 可以用power shell管理虚拟机 ,可以查看微软的about powershell Azure https://learn.microsoft.com/en-u ... 1.0&tabs=powershell Get started with Azure PowerShell | Microsoft Learn
powershell 主要用于windows的文件管理,管理invoke远程电脑,利用Azure 管理云服务虚拟机
powershell 还用于
由于powershell 有大量的module 从文件管理,远程管理,爬取网站各方面的cmdlet都有 所以powershell 脚本 的功能也很强大,不过ps1没有GUI,脚本只能写CLI脚本
# tips:
在Windows系统powershell 都有完整的pwsh,如网吧电脑,公司电脑,可以上传你的模组在powershellget 然后install 模组就可以直接把你的脚本安装到如何一条电脑
powershell 不仅是使用脚本,终端体验也是很好的,很多时候在终端基本可以完成如何事情
powershell 书籍推荐: powershell for sysadmin
配合Windows terminal使用更好
常用变量:
$profile powershell 的profile文件
$home user文件夹
$pwd 当前文件夹
善用Microsoft的powershell文档
powershell 交流群
我以后会经常发powershell的有关帖子,可以关注我以获取我以后的power shell帖子 https://learn.microsoft.com/zh-cn/powershell/scripting/samples/creating-a-custom-input-box?view=powershell-7.4&viewFallbackFrom=powershell-7.1 能不能把推荐书籍PDF链接放一个! 这个听说是也可以搞自动化,有没有这方面的文案? 有没有相关的视频 FruitBaby 发表于 2023-12-24 13:48
有没有相关的视频
https://m.youtube.com/@DonJonesConTech FelixLee 发表于 2023-12-24 13:35
这个听说是也可以搞自动化,有没有这方面的文案?
看powershell for sysadmin 这本书,全面,小白,我是从零开始学的,一边看一边实际就摸清门道了 dengshen 发表于 2023-12-24 15:20
看powershell for sysadmin 这本书,全面,小白,我是从零开始学的,一边看一边实际就摸清门道了
有条件就买英文原版,国内翻译很拗口,影响学习 powershell大概是以自然语言为基础的,所以对英语基础好的特别友好,而且linux的shell是以编程语言为基础的,对编程人员友好
有段时间看了两三天,看不下去了,还是linux shell 好学 bigcan 发表于 2023-12-24 15:53
powershell大概是以自然语言为基础的,所以对英语基础好的特别友好,而且linux的shell是以编程语言为基础的 ...
哈。。。我恰恰跟你相反,sa用powershell多,后面不值钱了,开始学linux shell 看了几天,搞不赢。。。{:301_1005:}
页:
[1]
2