A N

June 28, 2018

How to Comment Code Block in Visual Studio Code

Filed under: Tips — donrsh @ 12:40 pm

Select the code

 

To comment press:

Ctrl+K+C

 

To uncomment press:

Ctrl+K+U
Advertisements

June 19, 2018

How to install packages from Powershellgallery or Nuget gallery on server behind proxy/firewall?

Filed under: Tips — donrsh @ 12:48 pm

If your corporate servers are behind firewalls or proxy that don’t allow internet access but you need to install packages from Powershellgallery or Nuget gallery then you need to install CNTLM proxy on your desktop and configure server to talk to internet through your desktop.

1) Download cntlm and install it
2) open the ini file and add:

Username   userid
Domain     domain
Auth       NTLMv2
PassNTLMv2 D0D87E5BBF5D731FA906AE095xxxxxx
Proxy      proxy.domain.com:8080
NoProxy    localhost, 127.0.0.*, 10.*, 192.168.*
Listen     9090
Gateway    Yes

To hash your password, run

C:\Program Files (x86)\Cntlm>cntlm -H -d domain -u userID

3) Add your local computers IP and port 9090 to LAN settings of the server (start internet explorer – Internet Options – Connections – LAN Settings – Proxy Server)

4) Browse to http://www.google.com and a pop up will appear to authenticate, write your domain credentials.

5) Start Powershell as admin and run:

Set-PSRepository -Name PSGallery -InstallationPolicy Trusted

6) Now you can run Install-Module or Install-Package

June 1, 2018

Copy files to Azure Blob Storage – Copy-ToAzureBlob

Filed under: Tips — donrsh @ 8:58 am
<#
	.NOTES
	===========================================================================
	 Created on:   	2018-06-01
	 Created by:   	Arash Nabi - arash@nabi.nu
	===========================================================================


	.SYNOPSIS
		Copy-ToAzureBlob will copy files from $path to Azure Blob.
		The Azure powershell module should be installed, otherwise the script will fail.
		You can download it from https://www.powershellgallery.com/.

        
	
	.EXAMPLE
				PS C:\> Copy-ToAzureBlob -Path $value1
		
#>
function Copy-ToAzureBlob
{
	[CmdletBinding()]
	[Alias()]
	[OutputType([int])]
	param
	(
		[Parameter(Mandatory = $true,
				   ValueFromPipelineByPropertyName = $true,
				   Position = 0)]
		$Path
	)
	
	Begin
	{
	}
	Process
	{
		try
		{
			
			$VerbosePreference = 'Ignore'
			# Check if the Azure modules are loaded
			If ((Get-Module -Name Azure.Storage -ListAvailable).Count -le 0)
			{
				# Azure Storage module is not available Exit script
				Write-Warning "ERROR: The Azure module is not available, exiting script"
				Write-Warning "Please download the Azure PowerShell modules from https://www.powershellgallery.com/"
				
				return
			}
			else
			{
				Write-Output "The Azure module is available and loaded..."
			}
			
			# details about Service Principal account. This part will authenticat to Azure.
			$u = "APPLICATION_id@COMPANYNAME.onmicrosoft.com" # application ID
			$key = "KEY" # Key
			$tenantid = "TENANT_ID"
			$pass = ConvertTo-SecureString $key -AsPlainText –Force
			$cred = New-Object -TypeName pscredential –ArgumentList $u, $pass
			Login-AzureRmAccount -Credential $cred -ServicePrincipal –TenantId $tenantid
			
			
			$Global:AzureStorageAccountName = "STORAGE ACCOUNT" # STORAGE ACCOUNT NAME
			$Global:AzureStorageAccountKey = "STORAGE ACCOUNT KEY" # STORAGE ACCOUNT KEY
			$Container = "backup" # Name of Container where the backup will be store.
			
			
			# Initiate the Azure Storage Context
			$context = New-AzureStorageContext -StorageAccountName $Global:AzureStorageAccountName -StorageAccountKey $Global:AzureStorageAccountKey
			
			# Check if the defined container already exists
			Write-Output "Checking availability of Azure container `"$Container`""
			$azcontainer = Get-AzureStorageContainer -Name $Container -Context $context -ErrorAction stop
			Get-AzureStorageBlob -Container $Container -Context $context | ForEach-Object {
				Write-Output "Removing Azure container and $($_.Name) `"$Container`""
				Remove-AzureStorageBlob -Blob $_.Name -Container $Container -Context $context -ErrorAction stop
			}
			
			If ($? -eq $false)
			{
				# Something went wrong, check the last error message
				If ($Error[0] -like "*Can not find the container*")
				{
					# Container doesn't exist, create a new one
					Write-Output "Container `"$Container`" does not exist, trying to create container"
					$azcontainer = New-AzureStorageContainer -Name $Container -Context $context -ErrorAction stop
				}
			}
			# Retrieve the files in the given folders
			if (Test-Path -Path $path)
			{
				ForEach ($localpath in $Path) 
				{
					$GetFiles = get-childitem -Path $Path -Recurse
					ForEach ($file in $GetFiles | Where-Object { $_.PSIsContainer -eq $false })
					{
						Set-AzureStorageBlobContent -File $file.FullName -Blob $blobname -Container $Container -Context $context -Force -ErrorAction stop
					}
				}
			}
			else
			{
				Write-Warning "$path is not correct!"
			}
			
			
		}
		    # Catch specific types of exceptions thrown by one of those commands
		    catch [System.Net.WebException], [System.Exception] {
			Write-Warning -Message $Error[0].Exception.Message
		}
		
		
	}
	
}		
	

May 21, 2018

Run code in “Terminal” instead of “Output” in Visual Studio Code

Filed under: Tips — donrsh @ 9:07 am

To tell Code Runner to run code in the Terminal, add the below line in User Settings.

"code-runner.runInTerminal": true

You need Code Runner extension to perform the above step.

August 31, 2016

Manage Windows Services with Powershell

Filed under: Tips — donrsh @ 9:58 am

Manage Windows Services with Powershell. With this script you can connect to a server(s) and change logon account or just show the services.

#REQUIRES -Version 4.0
<#
	.NOTES
	===========================================================================
	 Created on:   	2016-08-30
	 Created by:   	Arash Nabi - arash@nabi.nu
	 Created for:	-
	===========================================================================
 
	.SYNOPSIS
		Manage service accounts
	
	
	.EXAMPLE
        
        PS C:\WINDOWS> Set-Service -Servers Server001,Server002,Server003 -ServiceName fake* -UpdateServices
        WARNING: No Service with name fake* found in Server003 


        Name         DisplayName        ServerName PathName               StartMode    State  
        ----         -----------        ---------- --------               ---------    -----  
        Fake         Fake Service       Server001  C:\windows\notepad.exe DC\SysScript Stopped
        Fake         Fake Service       Server002  C:\windows\notepad.exe DC\SysScript Stopped
        
     
    .EXAMPLE
             
        PS C:\WINDOWS> Set-Service -Servers Server001,Server002,Server003 -ServiceName fake* -ShowServices

        WARNING: No Service with name fake* found in Server003 

        DisplayName        State   StartName    SystemName
        -----------        -----   ---------    ----------
        Fake Service       Stopped DC\SysScript Server001   
        Fake Service       Stopped DC\SysScript Server002 
#>

function Set-Service
{
	[CmdletBinding()]
	param
	(
		[Parameter(Mandatory = $true)]
		$Servers,
		[Parameter(Mandatory = $true)]
		[string]$ServiceName,
		[switch]$ShowServices,
		[switch]$UpdateServices
	)
	
	Function Change-Service()
	{
		$cred = Get-Credential -Credential Domain\UserName
		$ServiceObj = @()
		foreach ($Server in $Servers)
		{
			# CIM stuff
			$objOption = New-CimSessionOption -Protocol Dcom
			$objSession = New-CimSession -ComputerName $server -SessionOption $objOption
			if ($objSession)
			{
				$params = @{
					'ServerName' = $Server
				}
				$getServices = Get-CimInstance win32_service -CimSession $objSession | Where-Object { $_.Name -like $ServiceName }
				if ($getServices)
				{
					foreach ($Service in $getServices)
					{
						$X = $Service | Invoke-CimMethod -Name Change -Arguments @{ StartName = "$($cred.UserName)"; StartPassword = "$($cred.Password)" }
						$ListService = Get-CimInstance win32_service -CimSession $objSession | Where-Object { $_.Name -like $ServiceName }
						$params.Add("DisplayName", "$($ListService.DisplayName)")
						$params.Add("StartMode", "$($ListService.StartName)")
						$params.Add("Name", "$($ListService.Name)")
						$params.Add("State", "$($ListService.State)")
						$params.Add("PathName", "$($ListService.PathName)")
					}
					$ServiceObj += New-Object psObject -Property $params
				}
				else
				{
					Write-Warning -Message "No Service with name $serviceName found in $server"
				}
				
			}
			else
			{
				Write-Warning -Message "ohh nooo! No Session established to $server"
			}
		}
		
		$ServiceObj | Select-Object -Property Name, DisplayName, ServerName, PathName, StartMode, State | Format-Table -AutoSize
	}
	
	if ($UpdateServices)
	{
		Change-Service
	}
	
	
	
	if ($ShowServices)
	{
		foreach ($Server in $servers)
		{
			$objOption = New-CimSessionOption -Protocol Dcom
			$objSession = New-CimSession -ComputerName $server -SessionOption $objOption
			if ($objSession)
			{
				$ListServices = Get-CimInstance win32_service -CimSession $objSession | Where-Object { $_.Name -like $ServiceName } |
				Select-Object -Property DisplayName, State, StartName, SystemName
				if ($ListServices)
				{
					$ListServices
				}
				else
				{
					Write-Warning -Message "No Service with name $serviceName found in $server `n"
				}
			}
			else
			{
				Write-Warning -Message "ohh nooo! No Session established to $server"
			}
			
		}
	}
}

June 10, 2016

Convert RoboCopy log details to Powershell Object

Filed under: Tips — donrsh @ 11:53 am
<#	
	 Created on:   	2016-06-08 
	 Created by:   	Arash Nabi
	 Email: 	arash@nabi.nu 
#>
$TimeDay = get-date -Format "yyyyMMdd"
$xResults = @()
$xErr = @()
foreach ($x in (get-childitem -path "C:\temp\log\$TimeDay"))
{
  

$LogFile = Get-Content -Path $x.FullName

foreach ($Lines in $LogFile)
{
	
	$Lines | Foreach {
        if ($_ -match 'ERROR :')
            { $xError = $_.SubString(8)
              $xTime  = $x.CreationTime  
                $P = [ordered]@{
				Error = $xError
                Time  = $xTime
                }
                $xErr += New-Object -TypeName PSObject -Property $P
            }
        
        if ($_ -match '   Source : ') { $Source = $_.Substring(12, $_.Length - 12) }
		if ($_ -match '     Dest : ') { $Destination = $_.Substring(12, $_.Length - 12) }
		if ($_ -match '    Dirs :')
		{
			$DirTotal = [Long]$_.Substring(12, 10).Trim()
			$DirCopied = [Long]$_.Substring(22, 10).Trim()
			$DirFailed = [Long]$_.Substring(52, 10).Trim()
		}
		if ($_ -match '   Files : ' -and $_.Length -gt 60)
		{
			$FileTotal = [Long]$_.Substring(12, 10).Trim()
			$FileCopied = [Long]$_.Substring(22, 10).Trim()
			$FileFailed = [Long]$_.Substring(52, 10).Trim()
		}
		if ($_ -match '   Times :') { $Duration = [TimeSpan]$_.Substring(12, 10).Trim() }
		if ($_ -match '   Ended : ')
		{
			$Ended = $_.Substring(11, $_.Length - 11).Trim()
			$Properties = [ordered]@{
				Source = $Source
				Destination = $Destination
				DirTotal = $DirTotal
				NewDirCopied = $DirCopied
				DirFailed = $DirFailed
				FileTotal = $FileTotal
				NewFileCopied = $FileCopied
				FileFailed = $FileFailed
				Ended = $Ended
                }
			$xResults += New-Object -TypeName PSObject -Property $Properties
		}
	}


}
}
$xResults | Format-Table -AutoSize

RoboCopy Powershell Object Results

RoboCopy – Copy files from source to destination with x days old

Filed under: Tips — donrsh @ 11:47 am
<#	
	.NOTES
	===========================================================================
	 Created on:   	2016-06-08 
	 Created by:   	Arash Nabi
	 Email: 	arash@nabi.nu 

	===========================================================================
	.DESCRIPTION
     # /SEC           - Copies files with security
     # /R:1           - Specifies the number of retries on failed copies.
     # /W:1           - Specifies the wait time between retries, in seconds.
     # /NP            - Specifies that the progress of the copying operation (the number of files or directories copied so far) will not be displayed.
     # /FP            - Includes the full path names of the files in the output.
     # /V             - Produces verbose output, and shows all skipped files.
     # /MOVE          - Moves files and directories, and deletes them from the source after they are copied.
     # /maxage:<N>    - Specifies the maximum file age (to exclude files older than N days or date).
     # /log:<LogFile> - Writes the status output to the log file (overwrites the existing log file).
     # /minage:<N>    - Specifies the minimum file age (exclude files newer than N days or date).
     # /L             - Specifies that files are to be listed only (and not copied, deleted, or time stamped).	
     # /S             - Copies subdirectories. Note that this option excludes empty directories.
     # /FP            - Includes the full path names of the files in the output.
     # /NC            - Specifies that file classes are not to be logged.
     # /TS            - Includes source file time stamps in the output.
	 	
#>



$Time = (get-date -Format T).Replace(':','.')
$TimeDay = get-date -Format "yyyyMMdd"
$DateMonth = get-date -Format "yyyyMM" 
$Y = New-Item -Path "c:\temp\log\" -ItemType Directory -Name $TimeDay -Force
$Log = "C:\temp\log\$TimeDay\LogTime-$Time.txt" 
$MinAgeDate = (get-date).AddDays(-2) | get-date -Format "yyyyMMdd" 
$Dir = 'C:\temp\Archive\'
$Destination = 'C:\temp\Archive2'
$RoboCopyList = Invoke-Expression -Command  "Robocopy $Dir $Destination\$DateMonth /S /COPYALL /MINAGE:$MinageDate /MOV /R:10 /W:5 /TS /NFL /ETA /LOG+:$log"

April 7, 2016

Create ODBC Connection with Powershell

Filed under: Tips — donrsh @ 8:55 am

Create ODBC Connection with Powershell.


<#
	 Created on:   	2016-04-07 
	 Created by:   	Arash Nabi
	 Email: 	    arash@nabi.nu 

#>


<#
	
    .SYNOPSIS
		Create ODBC Connection
	
	.DESCRIPTION
		Create ODBC Connection
	
	.PARAMETER SQLserver
		Provide a SQLserver with instance name. Ex SQLserver\InstanceName
	
	.PARAMETER Databases
		A description of the Databases parameter.
	
	.PARAMETER DsnType
		Data Source Name type
	
	.PARAMETER Platform
		X86 or X64 platform
	
	.PARAMETER DriverName
		An ODBC driver allows ODBC-enabled programs to get information from ODBC data sources.
	
	.PARAMETER Name
		A description of the Name parameter.
	
	.EXAMPLE
		PS C:\>  Create-ODBC -SQLserver SQLserver\InstanceName -Databases DBname -DsnType System -Platform 64-bit -Verbose
	
	.NOTES
		Additional information about the function.
#>
function Create-ODBC
{
	[CmdletBinding()]
	param
	(
		$SQLserver,
		$Databases,
		[ValidateSet('System', 'User')]
		$DsnType,
		[ValidateSet('64-bit', '32-bit')]
		$Platform
	)
	
	try
	{
		foreach ($Database in $Databases)
		{
			Add-OdbcDsn -Name $Database -DriverName "SQL Server Native Client 11.0" -DsnType $DsnType -Platform $Platform -SetPropertyValue @("Server=$SQLserver", "Trusted_Connection=Yes", "Database=$Database") -ErrorAction SilentlyContinue -PassThru
		}
	}
	catch [System.IO.IOException] {
		$_.Exception.Message
	}
	
	finally
	{
		Write-Verbose -Message "End of script"
	}
}



March 7, 2016

SCOM – Show and Start MaintenanceMode

Filed under: Tips — donrsh @ 2:49 pm
#REQUIRES -Version 4.0
<# .NOTES
	===========================================================================
	Created on:   	2016-03-07
	Created by:   	Arash Nabi - arash@nabi.nu
	===========================================================================
#>

<#
	.SYNOPSIS
		Invoke a command to SCOM Server
	
	.DESCRIPTION
		The Invoke-SCOM function uses SCOM Module to connect to SCOM Server and Show if a server is in maintenance mode,
		put a server in maintenance mode, show if a Web Watcher is in maintenance mode or put a Web Watcher in maintenance mode.
	
	.PARAMETER ShowInMaintenanceModeServer
		Selecting this parameter will show you Maintenance mode of a server or servers.
	
	.PARAMETER StartMaintenanceModeServer
		Selecting this parameter will start Maintenance mode of a server or serves, if the server is in maintenance mode
		it will update it with the new entries you entered.
	
	.PARAMETER ComputerName
		ComputerName should be entered either with .hm.com or without. The script is smart enough to check and add domain
		prefix if doesn´t have.
	
	.PARAMETER Minutes
		Minutes should be entred as integer, minimum 10 minutes.
	
	.PARAMETER Reason
		The reason parameter is predefined values. Choose the one that fits.
	
	.PARAMETER Comment
		The comment parameter should be entered in quotation mark, otherwise you will get error.
	
	
	.EXAMPLE
		Invoke-SCOM -ShowInMaintenanceModeServer -ComputerName SERVER001,SERVER002
		
		Show if a server(s) is in Maintenance mode or not.
		
		HealthState     InMaintenanceMode  DisplayName
		-----------     -----------------  -----------
		Error                 False        SERVER001.DOMAIN.COM
		Success               False        SERVER002.DOMAIN.COM
	
	.EXAMPLE
		Invoke-SCOM -StartMaintenanceModeServer -ComputerName SERVER001,SERVER001 -Minutes 10 -Reason PlannedOther -Comment "Some text comments here..."
		Put a server(s) in Maintenance mode. If the server is in maintenance mode, the records will be updated.
		
		VERBOSE: SERVER001.DOMAIN.COM is not in maintenance mode. Starting maintenance mode...
		
		
		StartTime        : 2016-03-07 12:15:42
		ScheduledEndTime : 2016-03-07 12:25:32
		Reason           : PlannedOther
		Comments         : Some text comments here...
		User             : DOMAIN\USERNAME
		
		VERBOSE: SERVER002.DOMAIN.COM is not in maintenance mode. Starting maintenance mode...
		StartTime        : 2016-03-07 12:15:42
		ScheduledEndTime : 2016-03-07 12:25:32
		Reason           : PlannedOther
		Comments         : Some text comments here...
		User             : DOMAIN\USERNAME
	
	.NOTES
		Additional information about the function.
#>
function Invoke-SCOM
{
	[CmdletBinding(DefaultParameterSetName = 'MaintenanceModeServer')]
	[OutputType([int])]
	param
	(
		[Parameter(ParameterSetName = 'ShowOnlyMaintenanceModeServers',
				   Mandatory = $true,
				   ValueFromPipeline = $true,
				   ValueFromPipelineByPropertyName = $true,
				   Position = 0)]
		[switch]$ShowInMaintenanceModeServer,
		[Parameter(ParameterSetName = 'MaintenanceModeServer',
				   Mandatory = $false,
				   Position = 0)]
		[switch]$StartMaintenanceModeServer,
		[Parameter(ParameterSetName = 'MaintenanceModeServer',
				   Mandatory = $true)]
		[Parameter(ParameterSetName = 'ShowOnlyMaintenanceModeServers',
				   Mandatory = $true)]
		$ComputerName,
		[Parameter(ParameterSetName = 'MaintenanceModeServer')]
		[int]$Minutes,
		[Parameter(ParameterSetName = 'MaintenanceModeServer')]
		[ValidateSet('ApplicationInstallation', 'ApplicationUnresponsive', 'ApplicationUnstable', 'LossOfNetworkConnectivity', 'PlannedApplicationMaintenance', 'PlannedHardwareInstallation', 'PlannedHardwareMaintenance', 'PlannedOperatingSystemReconfiguration', 'PlannedOther', 'SecurityIssue', 'UnplannedApplicationMaintenance', 'UnplannedHardwareInstallation', 'UnplannedHardwareMaintenance', 'UnplannedOperatingSystemReconfiguration', 'UnplannedOther')]
		[string]$Reason,
		[Parameter(ParameterSetName = 'MaintenanceModeServer',
				   Mandatory = $true)]
		[string]$Comment
	)
	
	Begin
	{
		$VerbosePreference = 'Continue'
		$SCOMServer = "ScomServer"
		$GetModule = Get-Module -Name 'OperationsManager'
		
		if (-not $GetModule)
		{
			$ScomModule = Get-Module -ListAvailable | Where-Object { $_.Name -like 'OperationsManager' }
			if ($ScomModule)
			{
				Write-Verbose -Message "OperationsManager exist in $env:COMPUTERNAME"
				Import-Module -Name 'OperationsManager' -Verbose
				New-SCOMManagementGroupConnection -ComputerName $SCOMServer -Verbose
			}
			else
			{
				[void][System.Windows.Forms.MessageBox]::Show("OperationsManager module does not exist", "Warning!")
				Break
			}
			
		}
		
		
	}
	Process
	{
		try
		{
			$end = ((get-date).AddMinutes($minutes))
			
			# Show All Servers Maintenance Mode
			if ($ShowInMaintenanceModeServer)
			{
				$instanceclass = Get-SCOMClass -Name 'Microsoft.Windows.Computer' -ErrorAction SilentlyContinue | Get-SCOMClassInstance
				foreach ($Computer in $ComputerName)
				{
					if (-not ($Computer -match ".domain.com"))
					{
						$computer = $($computer + ".domain.com")
					}
					$instance = $instanceclass | Where-Object { $_.DisplayName -match $Computer }
					$isMaint = $instance | Get-SCOMMaintenanceMode -ErrorAction SilentlyContinue | Select-Object -Property StartTime, ScheduledEndTime, Reason, Comments, User
					if ($isMaint)
					{
						Write-Host " "
						Write-Verbose -Message "$Computer"
						$isMaint
					}
					else
					{
						$instance
					}
					
				}
				
			}
			
			
			# Start Server Maintenance
			if ($StartMaintenanceModeServer)
			{
				$instanceclass = Get-SCOMClass -Name 'Microsoft.Windows.Computer' -ErrorAction SilentlyContinue | Get-SCOMClassInstance
				foreach ($Computer in $ComputerName)
				{
					if (-not ($Computer -match ".domain.com"))
					{
						$computer = $($computer + ".domain.com")
					}
					$instance = $instanceclass | Where-Object { $_.DisplayName -match $Computer }
					if ($instance.InMaintenanceMode -eq $false)
					{
						Write-Verbose -Message "$computer is not in maintenance mode. Starting maintenance mode..."
						Start-SCOMMaintenanceMode -Instance $instance -EndTime $end -Reason $Reason -Comment $Comment -ErrorAction SilentlyContinue
					}
					else
					{
						Write-Warning "$Computer is in maintenance mode. Updating with new entries you entered... "
						$instance | Get-SCOMMaintenanceMode -ErrorAction SilentlyContinue | Set-SCOMMaintenanceMode -EndTime $end -Reason $Reason -Comment $Comment -ErrorAction SilentlyContinue
						
					}
					$instance | Get-SCOMMaintenanceMode -ErrorAction SilentlyContinue | Select-Object -Property StartTime, ScheduledEndTime, Reason, Comments, User
				}
				
				
			}
			
			
			
		}
		
		catch [System.Net.WebException], [System.Exception]
		{
			$errorMessage = $_.Exception.Message
			Write-Warning  $errorMessage
		}
		finally
		{
			
		}
		
		
	}
	End
	{
	}
}


February 11, 2016

Get LastBootUpTime and Export to CSV

Filed under: Tips — donrsh @ 10:51 am
# Created by Arash Nabi / arash@nabi.nu
# Date: 2016-02-11

try
{
	$Source = "C:\temp\Serverlists\2.txt"
    $Export = "C:\temp\Serverlists\2.csv"
    $VerbosePreference = 'Continue'
    $xObj = @()
	$Servers = Get-Content -Path $Source
	
	foreach ($server in $servers)
	{		
		# CIM stuff
		$objOption = New-CimSessionOption -Protocol Dcom -ErrorAction SilentlyContinue
		$objSession = New-CimSession -ComputerName $server -SessionOption $objOption -ErrorAction SilentlyContinue
		if ($objSession)
		{
			$params = @{
			'ServerName' = $server
			}
			$LastReboot =  Get-CimInstance -CimSession $objSession -Namespace ROOT/cimv2 -ClassName Win32_OperatingSystem | select LastBootUpTime
			$params.Add('LastBootUptime',"$($LastReboot.LastBootUpTime)")
			# Create objects
			$objresult = New-Object psobject -Property $params
			# Add object to result
			$xObj += $objresult
			Write-Verbose -Message $server
		}
		else
		{
			Write-Warning "No CimSession connection to $server. Aborting"
		}
	}
	$xObj | Export-Csv -Path $Export -NoTypeInformation
}
catch [System.Net.WebException] #, [System.Exception]
{
	$errorMessage = $_.Exception
	Write-Warning -Message $errorMessage
}
finally
{
	Write-Verbose -Message 'End of Script'
}
Older Posts »

Create a free website or blog at WordPress.com.