Posts

Showing posts from August, 2020

HW inventory by times

 select sys.name0 AS 'Device name', vgs.ResourceID, sys.User_Name0, Case when CS.ClientActiveStatus='1' then 'Active' When CS.ClientActiveStatus='0' then 'Inactive' end as 'Client Active Status', os.Caption0 AS  'Operating System', os.Version0, os.CSDVersion0, img.core_image_version0 AS 'image version ', sln.SerialNumber0 AS 'Serial Number', max(vgs.LastLogon0) As Lastlogon, max(hb.AgentTime) AS 'HeartBeat time', hw.LastHWScan, sw.LastScanDate, cs.LastPolicyRequest, cs.LastOnline, ip.IPAddress0, sys.Full_Domain_Name0, cs.LastMPServerName, max(ou.System_OU_Name0) AS OU from  v_GS_NETWORK_LOGIN_PROFILE as vgs left join v_R_System sys on vgs.ResourceID=sys.ResourceID inner join v_FullCollectionMembership col on sys.resourceid=col.resourceid left Join v_CH_ClientSummary CS on sys.ResourceId=CS.ResourceID left join v_AgentDiscoveries hb on hb.ResourceId=sys.ResourceID left join v_GS_WORKSTATION_STATUS hw on hw.R...

patching complaince for list of KB

 use CM_CAS declare @CollID char(50) select @CollID = CollectionID from v_Collection where CollectionID='CAS00846' select distinct m.Name0 as ServerName, ui.BulletinID as Bulletin,  ui.ArticleID as Article,  ui.Title as Title, --ucs.Status, case vstate.StateName when 'Update is installed' then '1' Else '0' End as 'Installed', case vstate.StateName when 'Update is required' then '1' Else '0' End as 'Required', case vstate.StateName when 'Detection state unknown' then '1' Else '0' End as 'Unknown', case vstate.StateName when 'Update is not required' then '1' Else '0' End as 'Not Required' --m.User_Domain0+'\'+User_Name0 as LastLoggedOnUser, --ucs.Status as UpdateStatus --asi.SMS_Assigned_Sites0 as AssignedSite, --m.Client_Version0 as ClientVersion, --LastStatusCheckTime as LastStateReceived, --LastStatusChangeTime as LastStateChange from v_Update...

get all win events

 Function Get-AllEvents{ param([string]$computername = $env:COMPUTERNAME, [datetime]$startdateandtime, [datetime]$enddateandtime ) $logs= (Get-WinEvent -ListLog * | Where-Object {$_.recordcount}).logname $Filtertable = @{     StartTime = $startdateandtime     EndTime = $enddateandtime     LogName = $logs } Get-WinEvent -ComputerName $computername  -FilterHashtable $Filtertable -ErrorAction SilentlyContinue } Get-AllEvents -startdateandtime '07/06/2020 01:00' -enddateandtime '07/08/2020 11:00'

get all ecent logs

 # winrm service should be running on the machine where script is running for ciminstance query else change it to get-wmiobject # Get-Allrecentlogs -computername 'localhost' -startdateandtime '01/01/2005 00:00' -enddateandtime '07/07/2020 00:00' -logfilextension 'flv' # Get-Allrecentlogs -computername 'localhost' -startdateandtime '01/01/2005 00:00' -enddateandtime '07/07/2020 00:00' -logfilextension 'mp4' Function Get-Allrecentlogs{ param([string]$computername = 'localhost', [datetime]$startdateandtime, [datetime]$enddateandtime, [string]$logfilextension = 'log' ) if ($computername -eq 'localhost')     {     $location = (Get-CimInstance -ClassName Win32_logicaldisk -Filter "DriveTYpe = '3'").DeviceId     } else { $shares = Get-CimInstance -ComputerName $computername -ClassName Win32_share | Where-Object {$_.Path -match '^\w{1}:\\$'} [System.Collections.ArrayList]$location ...

Powershell ISE class

  #region powershell ise came with ps 2.0 windows management frame  #endregion $PSVersionTable # File - new poowershell tab --> will create a new tab which completly new session from the cuurent where ur working  32 tabs $psISE.PowerShellTabs | select displayname $psISE.PowerShellTabs[1].displayname = 'newname' $psISE.PowerShellTabs.Remove($psISE.PowerShellTabs[3]) $psISE.CurrentPowerShellTab.DisplayName $psISE.PowerShellTabs.Add() $psISE.CurrentPowerShellTab.Files.displayname Get-ChildItem c:\ | ForEach-Object{ if($_.BaseName -like 'windows') { $created = $_.creationtime Write-Output "the windows folder was created in $($created.toshortdatestring())" } } #region we can collapse the region #endregion  $profile $profile.psextended | fl $profile.AllUsersAllHosts #every one on the system #creating new profile  New-Item -ItemType File -Path $profile -Force Get-Content Function:\psEdit #editing profile  psEdit $profile #script in new profile function prompt {...