OwnerAccount Priority FileList ---------------------------- NT AUTHORITY\NETWORK SERVICE Normal {} NT AUTHORITY\SYSTEM Foreground {https://downloads.dell.com/catalog/CatalogIndexPC.cab} NT AUTHORITY\SYSTEM Foreground {https://dellupdater.dell.com/non_du/ClientService/Catalog/CatalogI...
Get-NetTCPConnection 返回所有当前的 TCP 网络连接,但是此 cmdlet 不会确切告诉您谁在连接到您的计算机。您仅得到 IP 地址:
1 2 3 4 5 6 7
PS> Get-NetTCPConnection-RemotePort443
LocalAddress LocalPort RemoteAddress RemotePort State AppliedSetting OwningProcess ------------------------------------------------------------------------ 192.168.2.1106096013.107.6.171443 Established Internet 21824 192.168.2.1106095920.44.232.74443 Established Internet 4540 192.168.2.1106095652.184.216.226443 Established Internet 13204
使用计算属性,您可以重新计算返回的值,例如,将 IP 地址发送到公开真实来源的 Web 服务。使用相同的技术,您还可以转换在 OwningProcess 中找到的进程 ID,并返回维护连接的进程名称:
# specify the folder that you want to discover # $home is the root folder of your user profile # you can use any folder: $path = 'c:\somefolder' $path = $HOME
# specify the depth you want to examine (the number of levels you'd like # to dive into the folder tree) $Depth = 3
# specify the folder that you want to discover # $home is the root folder of your user profile # you can use any folder: $path = 'c:\somefolder' $path = $HOME
# find all subfolders... Get-ChildItem$path-Directory-Recurse-ErrorAction Ignore | ForEach-Object { # return custom object with relative subfolder path and # file count [pscustomobject]@{ # use GetFiles() to find all files in folder: FileCount = $_.GetFiles().Count FolderCount = $_.GetDirectories().Count FullName = $_.Fullname.Substring($path.Length+1) } }
在 Windows上,默认情况下,许多 cmdlet 使用BOM (Byte Order Mask) 编码对文本文件进行编码。 BOM 会在文本文件的开头写入一些额外的字节,以标记用于写入文件的编码。
不幸的是,BOM 编码在 Windows 世界之外并未得到很好的采用。如今,当您在 Windows 系统上保存文本文件并将其上传到 GitHub 时,BOM 编码可能会损坏文件或使其完全不可读。
以下是一段可用于确保以与 Linux 兼容的方式,在不使用 BOM 的情况下保存文本文件:
1 2 3 4 5
$outpath = "$env:temp\nobom.txt" $text = 'This is the text to write to disk.' $Utf8NoBomEncoding = [System.Text.UTF8Encoding]::new($false) [System.IO.File]::WriteAllLines($outpath, $text, $Utf8NoBomEncoding) $outpath