Powershell How to Get Script to Start Again
If yous have ever wondered how to get concluding kick time for the listing of servers this article will reply that question and many others that popular upwardly on the mode.
To get last kick fourth dimension using PowerShell, we employ either WMI or CIM classes, Win32_OperatingSystem or CIM_OperatingSystem respectively.
Get The Last Boot-Time – Solutions
Hither are a few solutions:
Solution ane – Get The Last Kicking-Fourth dimension From The Local Motorcar
As mentioned, nosotros volition use CIM_OperatingSystem CIM form and Get-CimInstance CmdLet to get the Last Kicking Up Time for the local motorcar:
Get-CimInstance -ComputerName localhost -Class CIM_OperatingSystem -ErrorAction Stop | Select-Object CSName, LastBootUpTime Here is the result for the local automobile:
If we want to come across all the properties that CIM_OperatingSystem CIM class returns nosotros tin run the following line:
Get-CimInstance -ComputerName localhost -Form CIM_OperatingSystem -ErrorAction Cease | Select-Object * Hither is the resultset with all the properties:
Solution two – Go The Final Boot-Time For The List Of Servers (Remote Computers)
Create the list of servers in the text file and salvage in, for example, C:\Temp folder and run the following command. We basically load the content of the text file usingGet-ContentCmdLet and PowerShell will get through the list and run the aforementioned control as in the previous solution for each server on the listing.
Get-CimInstance -ComputerName (Become-Content -Path 'C:\Temp\servers.txt') -Class CIM_OperatingSystem -ErrorAction Stop | Select-Object CSName, LastBootUpTime | Out-GridView Hither is the resultset for the list of servers:
I practice not take servers in my domicile network so in order to simulate 1 I have created a very simple input list of servers in a text file just copying thelocalhostvalue several times.
Solution 3 – Write Own PowerShell CmdLet ( Get-LastBootUpTime )
I accept written my own Get-LastBootUpTime CmdLet that I will explain in the minute.
This approach takes a picayune chip longer time but gives u.s.a. more benefits in the long run and then it is my preferred way and we can combine this CmdLet with the library of CmdLets in Efficiency Booster PowerShell Project.
Here is a sample call to Go-LastBootUpTime CmdLet:
Get-LastBootUpTime -filename "OKFINservers.txt" -errorlog -client "OK" -solution "FIN" -Verbose | Select-Object 'Environs', 'Logical Name', 'Server Name', 'OS', 'Terminal bootup time', 'IP', 'Collected' | Out-GridView Here is the issue of a call to Get-LastBootUpTime CmdLet:
INFO: I have written two PowerShell Addition functions ( Get-CIMClassProperty and Select-CIMClassAllProperties) that help us working withWMIandCIM classes. First list all the backdrop and datatypes of WMI or CIM classes and the 2d 1 makes the select statements with all the properties for the WMI or CIM class. How To List CIM Or WMI Class All Properties And Their Datatypes With PowerShell AND How To Write Select Statement For All Properties Of CIM Or WMI Class With PowerShell.
Get-LastBootUpTime CmdLet Explained
Get-LastBootUpTime CmdLet collects Last boot fourth dimension for the list of servers and this CmdLet belongs to Efficiency Booster PowerShell Projection. This project is the library of unlike CmdLets that can help us IT personal to practise our everyday tasks more efficiently and accurately.
Source code forGet-LastBootUpTime CmdLet can be downloaded from this zip file so please experience free to download it and it would exist easier for yous to follow me along.
Get-LastBootUpTime CmdLet is part of Common module and if you accept downloaded the source code it can exist found in the folder…\[My] Documents\WindowsPowerShell\Modules\03common
INFO: If yous want to know how to install and configure Efficiency Booster PowerShell Project files please read the following article: How To Install And Configure PowerShell: CmdLets, Modules, Profiles.
Get-LastBootUpTime CmdLet – Input Parameters
As input parameters we have:
- computers– it is a list of servers passed every bit input parameter with default value 'localhost' and accepts both pipeline options. Parameter belongs to the "ServerNames" parameter set. The "ServerNames" parameter set is the default parameter ready.
- filename– information technology is the proper name of the text file with the list of servers and represents an alternative selection to the "computers" parameter. The parameter belongs to the "FileName" parameter set.
- errorlog– switch datatype and when turned on it will write errors into an external mistake log file using Write-ErrorLog CmdLet. The error log file is located in the PSLogs folder of [My] Documents.
- client– it is a mandatory input parameter and by convention, I utilize 2 letters for client shortcode (for example, OK = O client, BK = B client, etc.). This parameter value is part of the filename parameter naming convention.
- solution– it is a mandatory input parameter and by convention, I use two-three letters for solution shortcode (for case, FIN = Financial solution, HR = Hr solution, etc.).
The naming convention for thefilenameparameter is as follows:Client + Solution + Text.txt.The text file should be located in…[My] Documents\WindowsPowerShell\Modules\01servers binder.
For case:
- OKFINTestServers.txt– List of test environment servers for OK client and FIN solution.
- OKFINProdServers.txt – List of production environment servers for OK customer and FIN solution.
- OKFINAllServers.txt – List of all servers for OK client and FIN solution.
INFO: To get a deeper caption aboutclientandsolutioninput parameters delight read these two sections Parameter client, Parameter solution.
INFO: In guild to customize the installation of CmdLet to your needs and fix necessary CSV file please read the following article How To Install And Configure PowerShell: CmdLets, Modules, Profiles
Hither is the parameters definition code:
Function Go-LastBootUpTime { [CmdletBinding(DefaultParametersetName="ServerNames")] param ( [Parameter( ValueFromPipeline=$truthful, ValueFromPipelineByPropertyName=$true, ParameterSetName="ServerNames", HelpMessage="List of computer names separated by commas.")] [Alias('hosts')] [cord[]]$computers = 'localhost', [Parameter( ParameterSetName="FileName", HelpMessage="Name of txt file with listing of servers. Txt file should be in 01servers folder.")] [string]$filename, [Parameter( Mandatory=$imitation, HelpMessage="Write to error log file or not.")] [switch]$errorlog, [Parameter(Mandatory=$true, HelpMessage="Client for instance OK = O client, BK = B client")] [cord]$client, [Parameter(Mandatory=$true, HelpMessage="Solution, for example FIN = Fiscal, HR = Man Resource")] [string]$solution ) } INFO: To know more well-nighPowerShell ParametersandParameter Sets with some awesome examples delight read the following articles How To Create Parameters In PowerShell and How To Use Parameter Sets In PowerShell Functions.
INFO:PowerShell Pipeliningis a very important concept and I highly recommend you to read the article written on the subject. How PowerShell Pipeline Works. Here I accept shown in many examples the existentpowerofPowerShellusing thePipelining.
BEGIN Cake
In theBeginblock we:
- If theFileNameparameter set has been used we test if text file with a list of servers exists.
- If the file exists read the file and create the list of servers as a string assortment in the$computersvariable.
- … and if not write a warning with data to the caller to create the file.
BEGIN { if ( $PsCmdlet.ParameterSetName -eq "FileName") { if ( Test-Path -Path "$dwelling\Documents\WindowsPowerShell\Modules\01servers\$filename" -PathType Leaf ) { Write-Verbose "Read content from file: $filename" $computers = Get-Content( "$habitation\Documents\WindowsPowerShell\Modules\01servers\$filename" ) } else { Write-Alarm "This file path does NOT be: $dwelling\Documents\WindowsPowerShell\Modules\01servers\$filename" Write-Warning "Create file $filename in folder $home\Documents\WindowsPowerShell\Modules\01servers with list of server names." break; } } } PROCESS Cake
In thePROCESSblock we run this block of code for each server passed into the pipeline or read from the text file:
- We supplant the localhost default value for the local server with the actual name of the local motorcar.
- We apply Go-ComputerInfo CmdLet to read boosted data well-nigh each server (proper name, environment, logical proper name, IP address).
- Nosotros implement Error Treatment usingtry-catch blocks and writing errors in an external text file using Write-ErrorLog CmdLet.
- We employ PowerShell splatting to prepare the input parameters for the next call ofGo-CimInstance CmdLet.
- We call CIM class CIM_OperatingSystem usingGet-CimInstance CmdLet
- We prepare the resultset ofGet-LastBootUpTime CmdLet.
Delight observe these 2 features in theProcedureblock.
Splatting
We accept used splatting twice. First when nosotros prepare the call to Get-CimInstance CmdLet, and second when nosotros gear up the resultset.
Splatting helps u.s.a. to have a more than neat and understandable code.
Here is a phone call to Get-CimInstance CmdLet and employ of splatting:
$params = @{ 'ComputerName'=$computer; 'Course'='CIM_OperatingSystem'; 'ErrorAction'='End'} $boottime = Become-CimInstance @params | Select-Object Caption, LastBootUpTime Here is the second use of splatting when creating the resultset.
$properties = @{ 'Environment'=$env; 'Logical proper name'=$logicalname; 'Server name'=$computer; 'Bone'=$boottime.Explanation; 'Concluding bootup time'=$boottime.LastBootUpTime; 'IP'=$ip; 'Nerveless'=(Get-Appointment -UFormat %Y.%m.%d' '%H:%M:%Southward)} $obj = New-Object -TypeName PSObject -Property $backdrop Type Name Of The Resultset Objects
Notice the proper noun of the resultset (Report.LastBootUpTime).
$obj.PSObject.TypeNames.Insert(0,'Written report.LastBootUpTime') So if we phone call PowerShellGo-Member CmdLet to become the type of resultset for Get-LastBootUpTimeCmdLet we will become Report.LastBootUpTime type and not standard PowerShell PSObject type.
Get-LastBootUpTime -client OK -solution FIN | Get-Fellow member Hither is the resultset:
Type Proper name of resultset gives us a possibility to farther expend the employ of resultset. For example, we can employ MS SQL Database and create tableLastBootUpTimebased on resultset type proper name ( Report.LastBootUpTime ) where we tin record the resultset and employ MS SQL Reporting Services to show the results collected over a sure menses of time.
Here is thePROCESSblock source code:
Procedure { foreach ($computer in $computers ) { if ( $computer -eq 'localhost' ) { $computer = $env:COMPUTERNAME } $computerinfo = Get-ComputerInfo -computername $figurer -client $client -solution $solution $hostname = $computerinfo.hostname $env = $computerinfo.environment $logicalname = $computerinfo.logicalname $ip = $computerinfo.ipaddress try { Write-Verbose "Processing: $figurer - $env - $logicalname" Write-Verbose "Start CIM_OperatingSystem processing..." $boottime = $null $params = @{ 'ComputerName'=$reckoner; 'Class'='CIM_OperatingSystem'; 'ErrorAction'='Terminate'} $boottime = Get-CimInstance @params | Select-Object Explanation, LastBootUpTime #@{characterization="Terminal BootUp Fourth dimension"; expression={$_.converttodatetime($_.LastBootUpTime)}} Write-Verbose "Finish CIM_OperatingSystem processing..." $backdrop = @{ 'Environment'=$env; 'Logical name'=$logicalname; 'Server proper noun'=$computer; 'Os'=$boottime.Caption; 'Last bootup fourth dimension'=$boottime.LastBootUpTime; 'IP'=$ip; 'Collected'=(Get-Engagement -UFormat %Y.%1000.%d' '%H:%1000:%S)} $obj = New-Object -TypeName PSObject -Property $properties $obj.PSObject.TypeNames.Insert(0,'Report.LastBootUpTime') Write-Output $obj Write-Verbose "Finished processing: $estimator - $env - $logicalname" } catch { Write-Warning "Computer failed: $computer - $env - $logicalname" Write-Alarm "Mistake message: $_" if ( $errorlog ) { $errormsg = $_.ToString() $exception = $_.Exception $stacktrace = $_.ScriptStackTrace $failingline = $_.InvocationInfo.Line $positionmsg = $_.InvocationInfo.PositionMessage $pscommandpath = $_.InvocationInfo.PSCommandPath $failinglinenumber = $_.InvocationInfo.ScriptLineNumber $scriptname = $_.InvocationInfo.ScriptName Write-Verbose "Kickoff writing to Error log." Write-ErrorLog -hostname $computer -env $env -logicalname $logicalname -errormsg $errormsg -exception $exception -scriptname $scriptname -failinglinenumber $failinglinenumber -failingline $failingline -pscommandpath $pscommandpath -positionmsg $pscommandpath -stacktrace $stacktrace Write-Verbose "Finish writing to Error log." } } } } INFO: To learn almost PowerShellError Handlingand codedebuggingplease read the following articles: How To Log PowerShell Errors And Much More and How To Debug PowerShell Scripts.
END Block
Finishblock is empty.
INFO: To understandBEGIN,PROCESSandENDblocks in PowerShell please read PowerShell Function Begin Procedure Cease Blocks Explained With Examples.
Comment-Based Aid Section
For every ane of my ain CmdLets, I writeComment-Based help as well.
INFO: If yous want to acquire how to writeannotate-based Help for your own PowerShell Functions and Scripts please read these articles How To Write PowerShell Help (Step by Step). In this commodity How To Write PowerShell Function's Or CmdLet'south Assist (Fast), I explicate the PowerShell Add-on that help us to exist fast with writing assistance content.
How To Employ Go-LastBootUpTime CmdLet – Tips
To get Last Boot Fourth dimension for the local machine we just call Go-LastBootUpTime CmdLet and provide values for mandatory parameters (client and solution):
Get-LastBootUpTime -client "OK" -solution "FIN" Here is the resultset:
As we have seen in the solution section of this article nosotros tin phone call Get-LastBootUpTimeCmdLet for the listing of servers:
Get-LastBootUpTime -filename "OKFINservers.txt" -errorlog -client "OK" -solution "FIN" -Verbose | Select-Object 'Environment', 'Logical Proper noun', 'Server Proper noun', 'Os', 'Last bootup fourth dimension', 'IP', 'Nerveless' | Out-GridView Here is the resultset for the list of servers.
We can PowerShell pipeline result from Get-LastBootUpTimeCmdLet intoSave-ToExcel CmdLet and get resultset as an Excel Sheet:
Get-LastBootUpTime -filename "OKFINservers.txt" -errorlog -client "OK" -solution "FIN" -Verbose | Save-ToExcel -errorlog -ExcelFileName "Get-LastBootUpTime" -title "Get Last bootup fourth dimension info of servers in Financial solution for " -author "Dejan Mladenovic" -WorkSheetName "Last bootup time" -client "OK" -solution "FIN" Hither is the Excel Canvas outcome:
Bonus Tip
I have used Get-LastBootUpTimeCmdLet combined with Reset Servers CmdLet. For example, when I want to reset the list of servers, I run reset servers CmdLet and if for any reason some servers are not reset I volition run again the same reset servers CmdLet simply this time just confronting the servers that have not been reset in the last half an hour since we do not have to reset the servers that have been already reset.
This is just 1 of many useful examples that show united states the efficiency of having the Library of ain CmdLets.
Useful PowerShell Concluding Kick Fourth dimension Manufactures
Here are some useful articles and resource:
- Go-CimInstance
- Go-CimClass
- CIM_OperatingSystem class
- Win32_OperatingSystem class
- Computer Arrangement Hardware Classes
Get-LastBootUpTime CmdLet Source Lawmaking
DISCLAIMER:Get-LastBootUpTime function is part of the Efficiency Booster PowerShell Project and as such utilize other CmdLets that are part of the same projection. So the best selection for y'all in gild for this function to work without any additional customization is to download the source lawmaking of the whole project from here.
INFO: My best communication to every PowerShell scripter is to learn writing ownPowerShell Avant-garde Functions andCmdLetsand I have written several manufactures explaining this, so please read them. How To Create A Custom PowerShell CmdLet (Step By Step). Here I explain how to employ PowerShell Add-on Function to be faster in writing PowerShell Functions How To Write Avant-garde Functions Or CmdLets With PowerShell (Fast).
Here is the source code of the wholeGet-LastBootUpTime CmdLet:
<# .SYNOPSIS Get last bootup time for list of computers. .Clarification Get last bootup time for list of computers. Of import: Restart-Server CmdLet depends on this CmdLet so be aware when you change this CmdLet to check if this change has some implication on Restart-Server CmdLet List of servers is in txt file in 01servers folderor list of strings with names of computers. CmdLet has two ParameterSets ane for list of computers from file and some other from list of strings as computer names. Errors will be saved in log folder PSLogs with name Error_Log.txt. Parameter errorlog controls logging of errors in log file. Become-LastBootUpTime function uses CimInstance -Class CIM_OperatingSystem PowerShell part to get Last bootup fourth dimension info. Result shows post-obit columns: Surroundings (PROD, Acceptance, Test, Class...), Logical Proper name (Application, web, integration, FTP, Scan, Terminal Server...), Server Name, Bone, Last bootup time, IP, Collected .PARAMETER computers Listing of computers that we want to go Last bootup time from. Parameter belongs to default Parameter Set = ServerNames. .PARAMETER filename Name of txt file with list of servers that nosotros want to check Terminal bootup time. .txt file should be in 01servers folder. Parameter belongs to Parameter Set = FileName. .PARAMETER errorlog Switch parameter that sets to write to log or not to write to log. Error file is in PSLog folder with proper noun Error_Log.txt. .PARAMETER customer OK - O client BK - B client etc. .PARAMETER solution FIN - Financial solution 60 minutes - Human resource solution etc. .Instance Get-LastBootUpTime -customer "OK" -solution "FIN" Description --------------------------------------- Examination of default parameter with default value ( computers = 'localhost' ) in default ParameterSet = ServerName. .EXAMPLE Become-LastBootUpTime -client "OK" -solution "FIN" -Verbose Description --------------------------------------- Test of Verbose parameter. Notation: Notice how localhost default value of parameter computers replaces with name of server. .EXAMPLE 'ERROR' | Become-LastBootUpTime -customer "OK" -solution "FIN" -errorlog Description --------------------------------------- Test of errorlog parameter. In that location is no server with proper noun Fault and so this call volition fail and write to Fault log since errorlog switch parameter is on. Look Error_Log.txt file in PSLogs folder. .EXAMPLE Get-LastBootUpTime -computers 'APP100001' -client "OK" -solution "FIN" -errorlog Description --------------------------------------- Examination of computers parameter with one value. Parameter accepts array of strings. .EXAMPLE Get-LastBootUpTime -computers 'APP100001', 'APP100002' -client "OK" -solution "FIN" -errorlog -Verbose Description --------------------------------------- Examination of computers parameter with array of strings. Parameter accepts assortment of strings. .Case Go-LastBootUpTime -hosts 'APP100002' -client "OK" -solution "FIN" -errorlog Description --------------------------------------- Test of computers paramater alias hosts. .Instance Get-LastBootUpTime -computers (Go-Content( "$home\Documents\WindowsPowerShell\Modules\01servers\OKFINservers.txt" )) -client "OK" -solution "FIN" -errorlog -Verbose Clarification --------------------------------------- Test of computers parameter and values for parameter comes from .txt file that has list of servers. .Example 'APP100001' | Get-LastBootUpTime -client "OK" -solution "FIN" -errorlog Description --------------------------------------- Test of pipeline past value of computers parameter. .Case 'APP100001', 'APP100002' | Go-LastBootUpTime -customer "OK" -solution "FIN" -errorlog -Verbose Description --------------------------------------- Test of pipeline by value with array of strings of computers parameter. .EXAMPLE 'APP100001', 'APP100002' | Select-Object @{characterization="computers";expression={$_}} | Get-LastBootUpTime -client "OK" -solution "FIN" -errorlog Description --------------------------------------- Test of values from pipeline by property name (computers). .EXAMPLE Get-Content( "$home\Documents\WindowsPowerShell\Modules\01servers\OKFINkservers.txt" ) | Become-LastBootUpTime -customer "OK" -solution "FIN" -errorlog -Verbose Description --------------------------------------- Test of pipeline by value that comes as content of .txt file with list of servers. .Example Help Get-LastBootUpTime -Full Clarification --------------------------------------- Test of Powershell aid. .EXAMPLE Get-LastBootUpTime -filename "OKFINservers.txt" -errorlog -customer "OK" -solution "FIN" -Verbose Clarification --------------------------------------- This is exam of ParameterSet = FileName and parameter filename. At that place is listing of servers in .txt file. .Case Get-LastBootUpTime -filename "OKFINserverss.txt" -errorlog -client "OK" -solution "FIN" -Verbose Description --------------------------------------- This is examination of ParameterSet = FileName and parameter filename. This exam volition fail due to wrong name of the .txt file with warning message "Alert: This file path does NOT exist:". .INPUTS Organisation.String Computers parameter pipeline both by Value and by Belongings Proper name value and has default value of localhost. (Parameter Set = ComputerNames) Filename parameter does not pipeline and does non have default value. (Parameter Set = FileName) .OUTPUTS System.Direction.Automation.PSCustomObject Get-LastBootUpTime returns PSCustomObjects which has been converted from PowerShell function Get-WmiObject -Class Win32_OperatingSystem Result shows following columns: Environment (PROD, Acceptance, Test, Grade...), Logical proper noun (Application, web, integration, FTP, Scan, Final Server...), Server name, Bone, Last bootup time, IP, Nerveless .NOTES FunctionName : Become-LastBootUpTime Created by : Dejan Mladenovic Date Coded : 10/31/2018 19:06:41 More info : https://improvescripting.com/ .LINK https://improvescripting.com/get-the-last-boot-fourth dimension-using-powershell-script CimInstance -Course Win32_OperatingSystem CimInstance -Grade CIM_OperatingSystem Restart-Server #> Function Get-LastBootUpTime { [CmdletBinding(DefaultParametersetName="ServerNames")] param ( [Parameter( ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, ParameterSetName="ServerNames", HelpMessage="List of computer names separated by commas.")] [Alias('hosts')] [string[]]$computers = 'localhost', [Parameter( ParameterSetName="FileName", HelpMessage="Name of txt file with list of servers. Txt file should be in 01servers folder.")] [string]$filename, [Parameter( Mandatory=$false, HelpMessage="Write to fault log file or not.")] [switch]$errorlog, [Parameter(Mandatory=$true, HelpMessage="Client for example OK = O client, BK = B client")] [string]$client, [Parameter(Mandatory=$true, HelpMessage="Solution, for example FIN = Fiscal, HR = Human Resources")] [cord]$solution ) BEGIN { if ( $PsCmdlet.ParameterSetName -eq "FileName") { if ( Test-Path -Path "$home\Documents\WindowsPowerShell\Modules\01servers\$filename" -PathType Leaf ) { Write-Verbose "Read content from file: $filename" $computers = Get-Content( "$home\Documents\WindowsPowerShell\Modules\01servers\$filename" ) } else { Write-Warning "This file path does NOT be: $dwelling house\Documents\WindowsPowerShell\Modules\01servers\$filename" Write-Alert "Create file $filename in binder $dwelling house\Documents\WindowsPowerShell\Modules\01servers with list of server names." pause; } } } PROCESS { foreach ($computer in $computers ) { if ( $estimator -eq 'localhost' ) { $estimator = $env:COMPUTERNAME } $computerinfo = Get-ComputerInfo -computername $computer -client $customer -solution $solution $hostname = $computerinfo.hostname $env = $computerinfo.environment $logicalname = $computerinfo.logicalname $ip = $computerinfo.ipaddress try { Write-Verbose "Processing: $estimator - $env - $logicalname" Write-Verbose "Start CIM_OperatingSystem processing..." $boottime = $null $params = @{ 'ComputerName'=$figurer; 'Class'='CIM_OperatingSystem'; 'ErrorAction'='Stop'} $boottime = Become-CimInstance @params | Select-Object Explanation, LastBootUpTime #@{label="Concluding BootUp Time"; expression={$_.converttodatetime($_.LastBootUpTime)}} Write-Verbose "Stop CIM_OperatingSystem processing..." $backdrop = @{ 'Environs'=$env; 'Logical name'=$logicalname; 'Server name'=$figurer; 'Os'=$boottime.Caption; 'Last bootup time'=$boottime.LastBootUpTime; 'IP'=$ip; 'Collected'=(Get-Appointment -UFormat %Y.%m.%d' '%H:%Yard:%Due south)} $obj = New-Object -TypeName PSObject -Holding $properties $obj.PSObject.TypeNames.Insert(0,'Report.LastBootUpTime') Write-Output $obj Write-Verbose "Finished processing: $figurer - $env - $logicalname" } catch { Write-Warning "Computer failed: $computer - $env - $logicalname" Write-Alarm "Error bulletin: $_" if ( $errorlog ) { $errormsg = $_.ToString() $exception = $_.Exception $stacktrace = $_.ScriptStackTrace $failingline = $_.InvocationInfo.Line $positionmsg = $_.InvocationInfo.PositionMessage $pscommandpath = $_.InvocationInfo.PSCommandPath $failinglinenumber = $_.InvocationInfo.ScriptLineNumber $scriptname = $_.InvocationInfo.ScriptName Write-Verbose "Start writing to Error log." Write-ErrorLog -hostname $estimator -env $env -logicalname $logicalname -errormsg $errormsg -exception $exception -scriptname $scriptname -failinglinenumber $failinglinenumber -failingline $failingline -pscommandpath $pscommandpath -positionmsg $pscommandpath -stacktrace $stacktrace Write-Verbose "Finish writing to Fault log." } } } } Cease { } } #region Execution examples #Go-LastBootUpTime -filename "OKFINservers.txt" -errorlog -client "OK" -solution "FIN" -Verbose | Select-Object 'Environment', 'Logical Name', 'Server Name', 'OS', 'Last bootup time', 'IP', 'Collected' | Out-GridView <# #Test ParameterSet = ServerName Get-LastBootUpTime -client "OK" -solution "FIN" Get-LastBootUpTime -customer "OK" -solution "FIN" -errorlog Get-LastBootUpTime -client "OK" -solution "FIN" -errorlog -Verbose Get-LastBootUpTime -computers 'APP100001' -customer "OK" -solution "FIN" -errorlog Become-LastBootUpTime -computers 'APP100001', 'APP100002' -client "OK" -solution "FIN" -errorlog -Verbose Get-LastBootUpTime -hosts 'APP100001' -customer "OK" -solution "FIN" -errorlog Get-LastBootUpTime -computers (Get-Content( "$domicile\Documents\WindowsPowerShell\Modules\01servers\OKFINservers.txt" )) -client "OK" -solution "FIN" -errorlog -Verbose #Pipeline examples 'APP100001' | Get-LastBootUpTime -client "OK" -solution "FIN" -errorlog 'APP100001', 'APP100002' | Get-LastBootUpTime -client "OK" -solution "FIN" -errorlog -Verbose 'APP100001', 'APP100002' | Select-Object @{label="computers";expression={$_}} | Get-LastBootUpTime -customer "OK" -solution "FIN" -errorlog Get-Content( "$home\Documents\WindowsPowerShell\Modules\01servers\OKFINservers.txt" ) | Get-LastBootUpTime -client "OK" -solution "FIN" -errorlog -Verbose 'ERROR' | Become-LastBootUpTime -client "OK" -solution "FIN" -errorlog #Test CmdLet aid Help Become-LastBootUpTime -Full #SaveToExcel Get-LastBootUpTime -filename "OKFINservers.txt" -errorlog -customer "OK" -solution "FIN" -Verbose | Save-ToExcel -errorlog -ExcelFileName "Get-LastBootUpTime" -title "Get Last bootup time info of servers in Fiscal solution for " -writer "Dejan Mladenovic" -WorkSheetName "Last bootup time" -client "OK" -solution "FIN" #SaveToExcel and ship email Get-LastBootUpTime -filename "OKFINservers.txt" -errorlog -client "OK" -solution "FIN" -Verbose | Relieve-ToExcel -sendemail -errorlog -ExcelFileName "Become-LastBootUpTime" -title "Get Last bootup fourth dimension info of servers in Financial solution for " -writer "Dejan Mladenovic" -WorkSheetName "Last bootup time" -client "OK" -solution "FIN" #Benchmark #Time = 3 sec; Total Items = 28 Measure-BenchmarksCmdLet { Get-LastBootUpTime -filename "OKFINservers.txt" -errorlog -client "OK" -solution "FIN" -Verbose } #Time = 3 sec; Total Items = 28 Measure out-BenchmarksCmdLet { Become-LastBootUpTime -filename "OKFINservers.txt" -errorlog -customer "OK" -solution "FIN" } #Test ParameterSet = FileName Get-LastBootUpTime -filename "OKFINservers.txt" -errorlog -client "OK" -solution "FIN" -Verbose Go-LastBootUpTime -filename "OKFINserverss.txt" -errorlog -client "OK" -solution "FIN" -Verbose #>
0 Response to "Powershell How to Get Script to Start Again"
Post a Comment