Good afternoon ladies and gentlemen! I see that your community is really cool in povershelle! Maybe someone will tell what to do ?! I need a script to uptime workstations in the domain. Unfortunately, yet I do not really know povershell. I did the vbs, however, I REAL like to see a working example on povershell
On Error Resume Next
Set objConnection = CreateObject(“ADODB.Connection”)
Set objCommand = CreateObject(“ADODB.Command”)
objConnection.Provider = “ADsDSOObject”
objConnection.Open “Active Directory Provider”
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = “;” & “(” & CONST_AD_BASE_FILTER & “);” & CONST_AD_ATTRs & CONST_AD_SCOPE
objCommand.Properties(“Page Size”) = 1000
objCommand.Properties(“Searchscope”) = 2
Const CONST_AD_BASE=“OU=PC,OU=Orlan,DC=dom,DC=de”
Const CONST_AD_BASE_FILTER=“&(objectClass=computer)”
Const CONST_AD_ATTRs=“Name,ADsPath,whenCreated,lastLogon,operatingSystem,description;”
Const CONST_AD_SCOPE=“subtree”
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
'----
Do Until objRecordSet.EOF
strComputer = objRecordSet.Fields(“Name”).Value
Wscript.Echo "Computer Name: " & objRecordSet.Fields(“Name”).Value
Set objWMIService = GetObject(“winmgmts:” _
& “{impersonationLevel=impersonate}!\” & strComputer & “\root\cimv2”)
Set colOperatingSystems = objWMIService.ExecQuery _
(“Select * from Win32_OperatingSystem”)
For Each objOS in colOperatingSystems
dtmBootup = objOS.LastBootUpTime
dtmLastBootupTime = WMIDateStringToDate(dtmBootup)
dtmSystemUptime = DateDiff(“s”, dtmLastBootUpTime, Now)
WScript.Echo (dtmSystemUptime \ (3600*24)) & “:” & (dtmSystemUptime \ 3600) Mod 24 & “:” & (dtmSystemUptime \ 60) Mod 60 & “:” & dtmSystemUptime Mod 60
Next
objRecordSet.MoveNext
Loop
Function WMIDateStringToDate(dtmBootup)
WMIDateStringToDate = CDate(Mid(dtmBootup, 5, 2) & “/” & _
Mid(dtmBootup, 7, 2) & “/” & Left(dtmBootup, 4) _
& " " & Mid (dtmBootup, 9, 2) & “:” & _
Mid(dtmBootup, 11, 2) & “:” & Mid(dtmBootup,13, 2))
End Function
Then I write the batch file and use third-party software to sort the desired value of systeminfo. It works, but for a long time gathering information. I understand that powershell all will be easier and faster. I do not know how to implement. Nobody will tell? uptime of local workstation get easy, but the stations in the domain of a specific OU - a heavy question. Please help me!!!