Bonjour,
J'aimerais dans le script mettre les running en vert et en rouge pour le stopped avec la commande foregroundcolord merci.
#Output
#(.\CheckServices.ps1 [Hostname of Laptop that to be send out] | Out-File \\[Hostname of your laptop]\C$\TEMP\[Hostname of Laptop that to be send out]_Services.txt)
#example: .\CheckServices.ps1 RTH006666 | Out-File \\RTH014662\C$\TEMP\RTH006666_Services.txt
[CmdletBinding()]
Param(
[Parameter(Mandatory)]
[string]$Hostname
)
function Check-IsElevated {
$id = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$p = New-Object System.Security.Principal.WindowsPrincipal($id)
if ($p.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator))
{ Write-Output $true }
else
{ Write-Output $false }
}
function GetService {
$out = @()
$sys = Get-WmiObject -ComputerName $Hostname -class Win32_ComputerSystem
$SerialNumber = Get-WmiObject -ComputerName $Hostname -class Win32_BIOS
$UserName = Get-CimInstance Win32_ComputerSystem -ComputerName $Hostname | Select -ExpandProperty username
$TcpIpV4 = (Get-WmiObject -ComputerName $Hostname -Class Win32_NetworkAdapterConfiguration | where {$_.DefaultIPGateway -ne $null}).IPAddress | select-object -first 1
$os = Get-WmiObject -ComputerName $Hostname -class win32_operatingsystem
$winver = Invoke-Command -computerName $HostName -ScriptBlock {(Get-ItemProperty registry::'\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion').Displayversion}
$BitLocker = (manage-bde -status -computername $Hostname C: | where {$_ -match 'Protection Status'}).Split(":")[1].trim()
$MDOP = Get-WmiObject -ComputerName $Hostname -Class Win32_Product | where Name -like "MDOP*" | select Version
$line = "---------------------------------------------------------------------------------------------"
$enter = "`n"
$today = Get-Date
$DeviceInfo= @{}
$DeviceInfo.add("System Name", $sys.Name)
$DeviceInfo.add("Model", $sys.Model)
$DeviceInfo.add("SerialNumber", $SerialNumber.SerialNumber)
$DeviceInfo.add("UserName" , $UserName)
$DeviceInfo.add("TcpIpV4" , $TcpIpV4)
$DeviceInfo.add("Windows Version", $os.Version)
$DeviceInfo.add("Display Version", $winver)
$DeviceInfo.add("Build Number", $os.BuildNumber)
$DeviceInfo.add("Architecture", $os.OSArchitecture)
$DeviceInfo.add("Build Date", ([WMI]'').ConvertToDateTime($os.InstallDate))
$DeviceInfo.add("BitLocker", $BitLocker)
$DeviceInfo.add("MDOP MBAM Version", $MDOP)
$out += New-Object PSObject -Property $DeviceInfo | Select-Object `
"System Name", `
"Model", `
"SerialNumber", `
"UserName", `
"TcpIpV4", `
"Windows Version", `
"Build Number", `
"Display Version", `
"Architecture", `
"Build Date", `
"BitLocker", `
"MDOP MBAM Version"
$out2 = Get-Service -ComputerName $Hostname FA_Scheduler, `
McAfeeFramework, `
macmnsvc, `
masvc, `
MfeFfCoreService, `
mfemms, `
mfevtp, `
WdNisSvc, `
WinDefend, `
Sense, `
mpssvc, `
'Nexthink Service', `
'Nexthink Coordinator', `
QualysAgent, `
CcmExec, `
bomgar-ps*| ft `
$today
$line
$out
$line
$out2
$TotalRecord = ($out2).count -4
$out3 = Write-Host $TotalRecord "Services"
$out4 = Get-Hotfix -ComputerName $Hostname | Format-Table -AutoSize
$out5 = Get-hotfix -ComputerName $Hostname | Group-Object -Property Description | Select Name,Count
$line
$out4
$line
$out5
}
$line
if (-not (Check-IsElevated)){
$enter
Write-Host "Please run this script as an administrator!!"
}
else {
IF (Test-Connection -BufferSize 32 -Count 1 -ComputerName $Hostname -Quiet) {
GetService
} Else {
Write-Host "The remote machine is not Online! "
}
}
Partager