当我看Win32_ComputerSystem类,它表明类似性质的负荷Status,PowerManagementCapabilities等等.然而,当在PowerShell中我做了以下我只拿回一对夫妇:
PS C:\Windows\System32\drivers> Get-WmiObject -Class "Win32_computersystem"
Domain : YYY.com
Manufacturer : VMware, Inc.
Model : VMware Virtual Platform
Name : LONINEGFQEF58
PrimaryOwnerName : Authorised User
TotalPhysicalMemory : 2147016704
Run Code Online (Sandbox Code Playgroud)
我怎样才能看到所有房产?
我有以下代码,目前它加载屏幕上的所有信息.我希望它登录到D:\ Apps\Logs上的日志文件.
日志文件需要具有要加载的计算机的名称 - 所以COMPUTERNAME.log
知道我怎么能这样做吗?
谢谢
$computer = gc env:computername
$onetcp = ((get-childitem c:\windows\system32\drivers\tcpip.sys).Versioninfo.ProductMajorPart).tostring() $twotcp = ((get-childitem c:\windows\system32\drivers\tcpip.sys).Versioninfo.ProductMinorPart).tostring() $threetcp = ((get-childitem c:\windows\system32\drivers\tcpip.sys).Versioninfo.ProductBuildPart).tostring() $fourtcp = ((get-childitem c:\windows\system32\drivers\tcpip.sys).Versioninfo.ProductPrivatePart).tostring()
$onedfsr = ((get-childitem c:\windows\system32\dfsrs.exe).Versioninfo.ProductMajorPart).tostring() $twodfsr = ((get-childitem c:\windows\system32\dfsrs.exe).Versioninfo.ProductMinorPart).tostring() $threedfsr = ((get-childitem c:\windows\system32\dfsrs.exe).Versioninfo.ProductBuildPart).tostring() $fourdfsr = ((get-childitem c:\windows\system32\dfsrs.exe).Versioninfo.ProductPrivatePart).tostring()
write-host TCPIP.sys Version on $computer is: "$onetcp.$twotcp.$threetcp.$fourtcp" Write-Host write-host DFSRS.exe Version on $computer is: "$onedfsr.$twodfsr.$threedfsr.$fourdfsr"
Write-Host
If (get-wmiobject win32_share | where-object {$_.Name -eq "REMINST"}) { Write-Host "The REMINST share exists on $computer" } Else { Write-Host "The …Run Code Online (Sandbox Code Playgroud) 我有以下脚本,我希望它出去到多个服务器并获得注册表的价值.不幸的是,它目前只是回发我正在运行脚本的机器的本地注册表值.
如何让脚本针对远程注册表运行?
脚本:
clear
#$ErrorActionPreference = "silentlycontinue"
$Logfile = "C:\temp\NEWnetbackup_version.log"
Function LogWrite
{
param([string]$logstring)
Add-Content $Logfile -Value $logstring
}
$computer = Get-Content -Path c:\temp\netbackup_servers1.txt
foreach ($computer1 in $computer){
$Service = Get-WmiObject Win32_Service -Filter "Name = 'NetBackup Client Service'" -ComputerName $computer1
if (test-connection $computer1 -quiet)
{
$NetbackupVersion1 = $(Get-ItemProperty hklm:\SOFTWARE\Veritas\NetBackup\CurrentVersion).PackageVersion
if($Service.state -eq 'Running')
{
LogWrite "$computer1 STARTED $NetbackupVersion1"
}
else
{
LogWrite "$computer1 STOPPED $NetbackupVersion1"
}
}
else
{
LogWrite "$computer1 is down" -foregroundcolor RED
}
}
Run Code Online (Sandbox Code Playgroud) 我有以下用作启动powershell的批处理文件(过了很长时间但是在另一个脚本中使用).
无论如何,我注意到%systemroot%\ temp和%systemroot%不起作用.
知道如何解决这个问题吗?
%systemroot%\system32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Unrestricted -File %SystemRoot%\TEMP\ROFS\testing_script_log.ps1
Run Code Online (Sandbox Code Playgroud)
谢谢,
我只是想弄清楚为什么在下面的一些行不以分号结束但其他行做的技术原因 - 它是什么关于C#在某些行中预期的分号呢?
事实上,在写这篇文章时,我注意到必须带有大括号{}的语句不需要分号,但是自己的"Console.WriteLine"中的行确实需要它.
真的试图找到这个的技术原因......
即:
namespace checkPackage **//no semicolon**
{
class Program **//no semicolon**
{
static void Main(string[] args) **//no semicolon**
{
listFilesInDirectory(@"C:\Temp\"); **//NEEDS a semicolon**
}
static void listFilesInDirectory(string workingDirectory) **//no semicolon**
{
string[] filePaths = Directory.GetFiles(workingDirectory); **//NEEDS a semicolon**
foreach (string filePath in filePaths) **//no semicolon**
{
Console.WriteLine(filePath); **//NEEDS a semicolon**
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 我有以下代码通过并获取计划任务信息并将屏幕上发生的输出放到日志文件中.
但是,我注意到的是,除了"访问被拒绝"的服务器之外,所有错误都会被记录 - 如何在日志文件中记录这些错误.
以下是代码:
Start-Transcript -path $scheduledpath\logging.txt -append
foreach ($name in $names)
{
Write-Host "Running Against Server $name" -ForegroundColor Magenta
if ( Test-Connection -ComputerName $name -Count 1 -ErrorAction SilentlyContinue )
{
#$Command = "schtasks.exe /query /S $name /fo CSV /v >c:\tools\Scheduled\$name.csv"
$Command = "schtasks.exe /query /S $name /fo CSV /v >$scheduledpath\$name.csv"
Invoke-Expression $Command
Clear-Variable Command -ErrorAction SilentlyContinue
}
else{
Write-Host "$name is Down" -ForegroundColor Red
}
}
Stop-Transcript
Run Code Online (Sandbox Code Playgroud)
这是屏幕上的输出:
> Running Against Server SV064909
> SV064909 is Down
> …Run Code Online (Sandbox Code Playgroud) 有没有办法让下面的内容并行运行(多线程)?我有大约200台需要运行的服务器,并且想知道是否有一种方法可以同时检查10台服务器,而不是一次检查一台...... WMI一次检查这台服务器的速度非常慢.
clear
Write-Host "Script to Check if Server is Alive and Simple WMI Check"
$servers = Get-Content -Path c:\Temp\Servers.txt
foreach($server in $servers)
{
if (Test-Connection -ComputerName $server -Quiet)
{
$wmi = (Get-WmiObject -Class Win32_ComputerSystem -ComputerName $server).Name
Write-Host "$server responds: WMI reports the name is: $wmi"
}
else
{
Write-Host "***$server ERROR - Not responding***"
}
}
Run Code Online (Sandbox Code Playgroud) 一个简单的问题,但如何在下面的代码中选择一个特定的列?
我只想显示TIME列,没有别的.我尝试放入FORMAT_TABLE TIME,但它只是在TIME中填充多次而没有实际显示时间..
$server_event = Get-Content -Path "c:\Temp\Servers.txt"
foreach($servers in $server_event)
{
$event = Get-EventLog -computerName $servers -logname system | Where-Object {$_.EventID -eq 6009} | Select -First 1
$event
}
Run Code Online (Sandbox Code Playgroud)
结果:我只想要显示时间栏
Index Time EntryType Source InstanceID Message
----- ---- --------- ------ ---------- -------
78858 Jun 01 07:19 Information EventLog 2147489657 Microsoft (R) Windows (R) 5.02. 3790 Service Pack 2 Multiprocessor Free.
46221 Jun 01 07:20 Information EventLog 2147489657 Microsoft (R) Windows (R) 5.02. 3790 Service Pack 2 Multiprocessor Free.
214480 …Run Code Online (Sandbox Code Playgroud) 请查看此帖的底部,以便更新.
我有以下代码搜索目录并显示目录中的最大文件.问题是它以KB格式显示 - 我究竟如何将其转换为MB?文件大小太大,所以想要更容易阅读 - 感谢您的帮助:
Private Sub btnGetMax_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetMax.Click
ClearList()
Dim dblSize As Integer = 0
Dim dblMax As Integer = 0
Dim strMax As String = ""
Dim objFileInfo As System.IO.FileInfo
For Each strFile As String In My.Computer.FileSystem.GetFiles("c:\temp", FileIO.SearchOption.SearchAllSubDirectories)
objFileInfo = My.Computer.FileSystem.GetFileInfo(strFile)
/*whats the size of the files?*/
dblSize = objFileInfo.Length
If dblSize > dblMax Then
dblMax = dblSize
strMax = objFileInfo.FullName
End If
Next
MessageBox.Show("Largest file in .Net folder …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用以下命令向我的applicationhost.config文件添加三个HTTP请求过滤器:
Set-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter 'system.webServer/security/requestFiltering/verbs' -Value @{VERB="GET";allowed="True"} -Name collection
Set-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter 'system.webServer/security/requestFiltering/verbs' -Value @{VERB="HEAD";allowed="True"} -Name collection
Set-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter 'system.webServer/security/requestFiltering/verbs' -Value @{VERB="POST";allowed="True"} -Name collection
Run Code Online (Sandbox Code Playgroud)
但是,每个后续行都会覆盖前一行,我只能添加一行.我想像这样添加所有三个:
<verbs allowUnlisted="false">
<add verb="GET" allowed="true" />
<add verb="HEAD" allowed="true" />
<add verb="POST" allowed="true" />
</verbs>
Run Code Online (Sandbox Code Playgroud)
我最终得到的是第一个GET被写入然后HEAD覆盖GET然后POST覆盖GET...我只想要所有三个列出.
有任何想法吗?