随笔 - 911  文章 - 5  评论 - 94  阅读 - 243万

静态类

静态类是不能更改状态的方法和属性的引用库,不能使用 New-Object 进行创建。

导出所有静态类:

([AppDomain]::CurrentDomain.GetAssemblies()|?{$_.location -ne $null}| ForEach { $_.GetExportedTypes() }).FullName|Out-File D:\StaticClass.txt

 

查找 IPAddress 相关的静态类
[AppDomain]::CurrentDomain.GetAssemblies()|?{$_.location -ne $null}| ForEach-Object { $_.GetExportedTypes() } | Where-Object { $_.Name -like "IPAddress" } |Foreach {$_.FullName}

 

查看[System.Net.IPAddress] 可用的属性和方法
[System.Net.IPAddress]|gm -Static
[System.DateTime] |gm -static -membertype Method

 

将字符串转换为IP地址格式:
[System.Net.IPAddress]::parse("192.168.10.2")
[System.Net.IPAddress]'192.168.2.2'
[System.Net.IPAddress]'192.168.2.2222'   #如果该字符串不满足IP格式将会转换失败

 

查找 Environment相关的静态类
[AppDomain]::CurrentDomain.GetAssemblies()|?{$_.location -ne $null}| ForEach-Object { $_.GetExportedTypes() } | Where-Object { $_.Name -like "Environment" } |Foreach {$_.FullName}

 

=====================================================================================

 

[datetime]::now ===== (Get-Date).DateTime

[Diagnostics.Process]::getprocesses() ===== Get-Process
[Diagnostics.Process]::Start("calc.exe") #打开计算机器程序

$m=get-date
$m.GetType().fullname
System.DateTime 就是一个静态类


[System.DateTime]::isleapyear(1998) #判断1998年是否是闰年
[System.DateTime]::Parse("2013-08-13") #将字符串转换为DateTime类型

 

=====================================================


Web文件下载,FTP下载需要用户名和密码,Net.WebClient不可用:
$url = "http://192.168.12.6/iisstart.htm"
$m="e:\aa.txt"
$webclient = New-Object Net.WebClient
$webclient.DownloadFile($url,$m)

 

更改文件扩展名
[System.IO.Path]::ChangeExtension("test.txt", "ps1")

还有其他静态类参考如下:
[System.IO.Path]|gm -Static

 

posted on   momingliu11  阅读(1400)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示