diff --git a/Lib/BootStrap.ps1 b/Lib/BootStrap.ps1 index af3ef5da..71b4f926 100644 --- a/Lib/BootStrap.ps1 +++ b/Lib/BootStrap.ps1 @@ -33,7 +33,7 @@ function NewBootStrap { break; } catch { - Write-Error $_; + Write-Error -Message $_; Start-Sleep -Seconds 5; } } #end while diff --git a/Lib/ConfigurationData.ps1 b/Lib/ConfigurationData.ps1 index d3c16659..ac0d5ca8 100644 --- a/Lib/ConfigurationData.ps1 +++ b/Lib/ConfigurationData.ps1 @@ -56,7 +56,7 @@ function ResolveConfigurationDataPath { $resolvedPath = Join-Path -Path $labDefaults.ModuleRoot -ChildPath $configPath; } } - Write-Debug ('Resolved ''{0}'' configuration file to ''{1}''.' -f $Configuration, $resolvedPath); + Write-Debug -Message ('Resolved ''{0}'' configuration file to ''{1}''.' -f $Configuration, $resolvedPath); return $resolvedPath; } #end process } #end function ReolveConfigurationPath diff --git a/Lib/DiskImage.ps1 b/Lib/DiskImage.ps1 index 359b5543..53a87aa3 100644 --- a/Lib/DiskImage.ps1 +++ b/Lib/DiskImage.ps1 @@ -11,7 +11,7 @@ function GetDiskImageDriveLetter { process { # Microsoft.Vhd.PowerShell.VirtualHardDisk $driveLetter = Get-Partition -DiskNumber $DiskImage.DiskNumber | - Where Type -eq $PartitionType | + Where-Object Type -eq $PartitionType | Where-Object DriveLetter | Select-Object -Last 1 -ExpandProperty DriveLetter; if (-not $driveLetter) { diff --git a/Lib/DscModule.ps1 b/Lib/DscModule.ps1 index b1272ee7..6e909975 100644 --- a/Lib/DscModule.ps1 +++ b/Lib/DscModule.ps1 @@ -12,7 +12,7 @@ function ExpandDscModule { ) process { $targetPath = Join-Path -Path $DestinationPath -ChildPath $ModuleName; - if (-not (Test-Path $targetPath) -or $Force) { + if (-not (Test-Path -Path $targetPath) -or $Force) { if (Test-Path -Path $targetPath) { WriteVerbose ($localized.RemovingDirectory -f $targetPath); Remove-Item -Path $targetPath -Recurse -Force -ErrorAction Stop; @@ -22,7 +22,7 @@ function ExpandDscModule { $archiveItems = $shellApplication.Namespace($Path).Items(); $shellApplication.NameSpace($DestinationPath).CopyHere($archiveItems); ## Rename any -master branch folder where no GitHub release available - Get-ChildItem -Path $DestinationPath -Directory | Where-Object { $_.Name -like '*-dev' -or $_.Name -like '*-master' } | % { + Get-ChildItem -Path $DestinationPath -Directory | Where-Object { $_.Name -like '*-dev' -or $_.Name -like '*-master' } | ForEach-Object { $destinationFilename = $_.Name -replace '-dev','' -replace '-master',''; WriteVerbose ($localized.RenamingPath -f $_.FullName, $destinationFilename); Rename-Item -Path $_.FullName -NewName $destinationFilename -ErrorAction Stop; @@ -69,12 +69,12 @@ function GetDscModule { $dscModulePath = Join-Path -Path $dscModulePath -ChildPath "DSCResources\$ResourceName"; } if (-not (Test-Path -Path $dscModulePath)) { - Write-Error ($localized.DscResourceNotFoundError -f $ModuleName); + Write-Error -Message ($localized.DscResourceNotFoundError -f $ModuleName); return $null; } if ($MinimumVersion) { if ($Module.Version -lt [System.Version]$MinimumVersion) { - Write-Error ($localized.ResourceVersionMismatchError -f $ModuleName, $module.Version.ToString(), $MinimumVersion); + Write-Error -Message ($localized.ResourceVersionMismatchError -f $ModuleName, $module.Version.ToString(), $MinimumVersion); return $null; } } diff --git a/Lib/DscResource.ps1 b/Lib/DscResource.ps1 index c5504a41..309e69df 100644 --- a/Lib/DscResource.ps1 +++ b/Lib/DscResource.ps1 @@ -31,7 +31,7 @@ function ImportDscResource { } } else { - Write-Debug ($localized.DscResourceAlreadyImported -f $ModuleName, $ResourceName); + Write-Debug -Message ($localized.DscResourceAlreadyImported -f $ModuleName, $ResourceName); } } #end process } #end function ImportDscResource @@ -76,7 +76,7 @@ function TestDscResource { $testTargetResourceCommand = 'Test-{0}TargetResource' -f $ResourceName; WriteVerbose ($localized.InvokingCommand -f $testTargetResourceCommand); $Parameters.Keys | ForEach-Object { - Write-Debug ($localized.CommandParameter -f $_, $Parameters.$_); + Write-Debug -Message ($localized.CommandParameter -f $_, $Parameters.$_); } $testDscResourceResult = & $testTargetResourceCommand @Parameters; if (-not $testDscResourceResult) { @@ -103,7 +103,7 @@ function SetDscResource { $setTargetResourceCommand = 'Set-{0}TargetResource' -f $ResourceName; WriteVerbose ($localized.InvokingCommand -f $setTargetResourceCommand); $Parameters.Keys | ForEach-Object { - Write-Debug ($localized.CommandParameter -f $_, $Parameters.$_); + Write-Debug -Message ($localized.CommandParameter -f $_, $Parameters.$_); } return (& $setTargetResourceCommand @Parameters); } #end process diff --git a/Lib/DscResourceModule.ps1 b/Lib/DscResourceModule.ps1 index f01ed469..69f7577d 100644 --- a/Lib/DscResourceModule.ps1 +++ b/Lib/DscResourceModule.ps1 @@ -15,20 +15,20 @@ function TestDscResourceModule { process { ## This module contains a \DSCResources folder, but we don't want to enumerate this! if ($Path -notmatch "\\$($labDefaults.ModuleName)$") { - Write-Debug ('Testing for MOF-based DSC Resource ''{0}'' directory.' -f "$Path\DSCResources"); + Write-Debug -Message ('Testing for MOF-based DSC Resource ''{0}'' directory.' -f "$Path\DSCResources"); if (Test-Path -Path "$Path\DSCResources" -PathType Container) { ## We have a WMF 4.0/MOF DSC resource module - Write-Debug ('Found MOF-based DSC resource ''{0}''.' -f $Path); + Write-Debug -Message ('Found MOF-based DSC resource ''{0}''.' -f $Path); return $true; } - Write-Debug ('Testing for Class-based DSC resource definition ''{0}''.' -f "$Path\$ModuleName.psm1"); + Write-Debug -Message ('Testing for Class-based DSC resource definition ''{0}''.' -f "$Path\$ModuleName.psm1"); if (Test-Path -Path "$Path\$ModuleName.psm1") { $psm1Content = Get-Content -Path "$Path\$ModuleName.psm1"; ## If there's a .psm1 file, check if it's a class-based DSC resource if ($psm1Content -imatch '^(\s*)\[DscResource\(\)\](\s*)$') { ## File has a [DscResource()] declaration - Write-Debug ('Found Class-based DSC resource ''{0}''.' -f $Path); + Write-Debug -Message ('Found Class-based DSC resource ''{0}''.' -f $Path); return $true; } } @@ -60,9 +60,9 @@ function GetDscResourceModule { $moduleInfo = $PSItem; ## Check to see if we have a MOF or class resource in the module if (TestDscResourceModule -Path $moduleInfo.FullName -ModuleName $moduleInfo.Name) { - Write-Debug ('Discovered DSC resource ''{0}''.' -f $moduleInfo.FullName); + Write-Debug -Message ('Discovered DSC resource ''{0}''.' -f $moduleInfo.FullName); $module = Test-ModuleManifest -Path "$($moduleInfo.FullName)\$($moduleInfo.Name).psd1"; - Write-Output ([PSCustomObject] @{ + Write-Output -InputObject ([PSCustomObject] @{ ModuleName = $moduleInfo.Name; ModuleVersion = [System.Version] $module.Version; Path = $moduleInfo.FullName; @@ -71,13 +71,13 @@ function GetDscResourceModule { else { ## Enumerate each module\. subdirectory Get-ChildItem -Path $moduleInfo.FullName -Directory | Where-Object Name -match '^\d+\.\d+' | ForEach-Object { - Write-Debug ('Checking module versioned directory ''{0}''.' -f $PSItem.FullName); + Write-Debug -Message ('Checking module versioned directory ''{0}''.' -f $PSItem.FullName); ## Test to see if it's a DSC resource module if (TestDscResourceModule -Path $PSItem.FullName -ModuleName $moduleInfo.Name) { try { #$moduleVersion = [System.Version] $PSItem.Name; - Write-Debug ('Discovered versioned DSC resource ''{0}''.' -f $PSItem.FullName); - Write-Output ([PSCustomObject] @{ + Write-Debug -Message ('Discovered versioned DSC resource ''{0}''.' -f $PSItem.FullName); + Write-Output -InputObject ([PSCustomObject] @{ ModuleName = $moduleInfo.Name; ModuleVersion = [System.Version] $PSItem.Name; Path = "$($moduleInfo.FullName)\$($PSItem.Name)"; @@ -86,7 +86,7 @@ function GetDscResourceModule { catch { } } } | #end foreach module\. sub directory - Sort-Object -Property ModuleVersion -Descending | Select -First 1; + Sort-Object -Property ModuleVersion -Descending | Select-Object -First 1; } } #end foreach module directory } #end foreach path diff --git a/Lib/Internal.ps1 b/Lib/Internal.ps1 index 82fd49f8..3a64b8e4 100644 --- a/Lib/Internal.ps1 +++ b/Lib/Internal.ps1 @@ -50,8 +50,8 @@ function InvokeExecutable { NoNewWindow = $true; PassThru = $true; } - Write-Debug ($localized.RedirectingOutput -f 'StdOut', $processArgs.RedirectStandardOutput); - Write-Debug ($localized.RedirectingOutput -f 'StdErr', $processArgs.RedirectStandardError); + Write-Debug -Message ($localized.RedirectingOutput -f 'StdOut', $processArgs.RedirectStandardOutput); + Write-Debug -Message ($localized.RedirectingOutput -f 'StdErr', $processArgs.RedirectStandardError); WriteVerbose ($localized.StartingProcess -f $Path, [System.String]::Join(' ', $Arguments)); $process = Start-Process @processArgs; if ($process.ExitCode -ne 0) { WriteWarning ($localized.ProcessExitCode -f $Path, $process.ExitCode);} @@ -70,7 +70,7 @@ function WriteVerbose { [Parameter(Mandatory, ValueFromPipeline)] [System.String] $Message ) process { - Write-Verbose ('[{0}] {1}' -f (Get-Date).ToLongTimeString(), $Message); + Write-Verbose -Message ('[{0}] {1}' -f (Get-Date).ToLongTimeString(), $Message); } } @@ -84,6 +84,6 @@ function WriteWarning { [Parameter(Mandatory, ValueFromPipeline)] [System.String] $Message ) process { - Write-Warning ('[{0}] {1}' -f (Get-Date).ToLongTimeString(), $Message); + Write-Warning -Message ('[{0}] {1}' -f (Get-Date).ToLongTimeString(), $Message); } } diff --git a/Lib/Resource.ps1 b/Lib/Resource.ps1 index 1019cece..8957c14d 100644 --- a/Lib/Resource.ps1 +++ b/Lib/Resource.ps1 @@ -20,12 +20,12 @@ function NewDirectory { [ValidateNotNullOrEmpty()] [System.String[]] $Path ) process { - Write-Debug ("Using parameter set '{0}'." -f $PSCmdlet.ParameterSetName); + Write-Debug -Message ("Using parameter set '{0}'." -f $PSCmdlet.ParameterSetName); switch ($PSCmdlet.ParameterSetName) { 'ByString' { foreach ($directory in $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Path)) { - Write-Debug ("Testing target directory '{0}'." -f $directory); - if (!(Test-Path $directory -PathType Container)) { + Write-Debug -Message ("Testing target directory '{0}'." -f $directory); + if (!(Test-Path -Path $directory -PathType Container)) { if ($PSCmdlet.ShouldProcess($directory, "Create directory")) { WriteVerbose ($localized.CreatingDirectory -f $directory); New-Item -Path $directory -ItemType Directory; @@ -39,7 +39,7 @@ function NewDirectory { 'ByDirectoryInfo' { foreach ($directoryInfo in $InputObject) { - Write-Debug ("Testing target directory '{0}'." -f $directoryInfo.FullName); + Write-Debug -Message ("Testing target directory '{0}'." -f $directoryInfo.FullName); if (!($directoryInfo.Exists)) { if ($PSCmdlet.ShouldProcess($directoryInfo.FullName, "Create directory")) { WriteVerbose ($localized.CreatingDirectory -f $directoryInfo.FullName); @@ -99,12 +99,12 @@ function GetResourceDownload { [ref] $null = SetResourceChecksum -Path $DestinationPath; } if (Test-Path -Path $checksumPath) { - Write-Debug ('MD5 checksum file ''{0}'' found.' -f $checksumPath); + Write-Debug -Message ('MD5 checksum file ''{0}'' found.' -f $checksumPath); $md5Checksum = (Get-Content -Path $checksumPath -Raw).Trim(); - Write-Debug ('Discovered MD5 checksum ''{0}''.' -f $md5Checksum); + Write-Debug -Message ('Discovered MD5 checksum ''{0}''.' -f $md5Checksum); } else { - Write-Debug ('MD5 checksum file ''{0}'' not found.' -f $checksumPath); + Write-Debug -Message ('MD5 checksum file ''{0}'' not found.' -f $checksumPath); } $resource = @{ DestinationPath = $DestinationPath; @@ -211,7 +211,7 @@ function InvokeWebClientDownload { [System.UInt64] $contentLength = $webClient.ResponseHeaders['Content-Length']; $path = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($DestinationPath); [System.IO.Stream] $outputStream = [System.IO.File]::Create($path); - [System.Byte[]] $buffer = New-Object System.Byte[] $BufferSize; + [System.Byte[]] $buffer = New-Object -TypeName System.Byte[] -ArgumentList $BufferSize; [System.UInt64] $bytesRead = 0; [System.UInt64] $totalBytes = 0; do { diff --git a/Lib/UnattendXml.ps1 b/Lib/UnattendXml.ps1 index ec10ebce..3f066993 100644 --- a/Lib/UnattendXml.ps1 +++ b/Lib/UnattendXml.ps1 @@ -162,7 +162,7 @@ function NewUnattendXml { } } #end foreach setting.Component } #end foreach unattendXml.Unattend.Settings - Write-Output $unattendXml; + Write-Output -InputObject $unattendXml; } #end process } #end function NewUnattendXml diff --git a/Lib/ZipArchive.ps1 b/Lib/ZipArchive.ps1 index e2a760cb..a52ef4eb 100644 --- a/Lib/ZipArchive.ps1 +++ b/Lib/ZipArchive.ps1 @@ -39,7 +39,7 @@ function ExpandZipArchive { } } ## If all tests passed, load the required .NET assemblies - Write-Debug 'Loading ''System.IO.Compression'' .NET binaries.'; + Write-Debug -Message 'Loading ''System.IO.Compression'' .NET binaries.'; Add-Type -AssemblyName 'System.IO.Compression'; Add-Type -AssemblyName 'System.IO.Compression.FileSystem'; } # end begin @@ -55,7 +55,7 @@ function ExpandZipArchive { ExpandZipArchiveItem @expandZipArchiveItemParams; } # end try catch { - Write-Error $_.Exception; + Write-Error -Message $_.Exception; } finally { ## Close the file handle @@ -91,7 +91,7 @@ function ExpandZipArchiveItem { [System.Management.Automation.SwitchParameter] $Force ) begin { - Write-Debug 'Loading ''System.IO.Compression'' .NET binaries.'; + Write-Debug -Message 'Loading ''System.IO.Compression'' .NET binaries.'; Add-Type -AssemblyName 'System.IO.Compression'; Add-Type -AssemblyName 'System.IO.Compression.FileSystem'; } @@ -102,7 +102,7 @@ function ExpandZipArchiveItem { if ($zipArchiveEntry.FullName.Contains('/')) { ## We need to create the directory path as the ExtractToFile extension method won't do this and will throw an exception $pathSplit = $zipArchiveEntry.FullName.Split('/'); - $relativeDirectoryPath = New-Object System.Text.StringBuilder; + $relativeDirectoryPath = New-Object -TypeName System.Text.StringBuilder; ## Generate the relative directory name for ($pathSplitPart = 0; $pathSplitPart -lt ($pathSplit.Count -1); $pathSplitPart++) { @@ -126,7 +126,7 @@ function ExpandZipArchiveItem { ## This is a folder and we need to create the directory path as the ## ExtractToFile extension method won't do this and will throw an exception $pathSplit = $zipArchiveEntry.FullName.Split('/'); - $relativeDirectoryPath = New-Object System.Text.StringBuilder; + $relativeDirectoryPath = New-Object -TypeName System.Text.StringBuilder; ## Generate the relative directory name for ($pathSplitPart = 0; $pathSplitPart -lt ($pathSplit.Count -1); $pathSplitPart++) { @@ -152,13 +152,13 @@ function ExpandZipArchiveItem { WriteVerbose ($localized.ExtractingZipArchiveEntry -f $fullDestinationFilePath); [System.IO.Compression.ZipFileExtensions]::ExtractToFile($zipArchiveEntry, $fullDestinationFilePath, $true); ## Return a FileInfo object to the pipline - Write-Output (Get-Item -Path $fullDestinationFilePath); + Write-Output -InputObject (Get-Item -Path $fullDestinationFilePath); } } # end if } # end foreach zipArchiveEntry } # end try catch { - Write-Error $_.Exception; + Write-Error -Message $_.Exception; } } # end process } #end function ExpandZipArchiveItem diff --git a/Resources.psd1 b/Resources.psd1 index b7fb13f7..b0a496a2 100644 --- a/Resources.psd1 +++ b/Resources.psd1 @@ -1,4 +1,4 @@ -ConvertFrom-StringData @' +ConvertFrom-StringData -StringData @' DownloadingResource = Downloading resource '{0}' to '{1}'. DownloadingActivity = Downloading '{0}'. DownloadStatus = {0:N0} of {1:N0} bytes ({2} %). diff --git a/Src/Lab.ps1 b/Src/Lab.ps1 index be21b151..1b4cf854 100644 --- a/Src/Lab.ps1 +++ b/Src/Lab.ps1 @@ -199,7 +199,7 @@ function Checkpoint-Lab { } elseif ($runningNodes) { foreach ($runningNode in $runningNodes) { - Write-Error ($localized.CannotSnapshotNodeError -f $runningNode.Name); + Write-Error -Message ($localized.CannotSnapshotNodeError -f $runningNode.Name); } } else { @@ -268,7 +268,7 @@ function Restore-Lab { } elseif ($runningNodes) { foreach ($runningNode in $runningNodes) { - Write-Error ($localized.CannotSnapshotNodeError -f $runningNode.NodeName); + Write-Error -Message ($localized.CannotSnapshotNodeError -f $runningNode.NodeName); } } else { diff --git a/Src/LabConfiguration.ps1 b/Src/LabConfiguration.ps1 index 0182d99a..2b4b3bd4 100644 --- a/Src/LabConfiguration.ps1 +++ b/Src/LabConfiguration.ps1 @@ -28,7 +28,7 @@ function Test-LabConfiguration { } process { WriteVerbose $localized.StartedLabConfigurationTest; - $nodes = $ConfigurationData.AllNodes | Where { $_.NodeName -ne '*' }; + $nodes = $ConfigurationData.AllNodes | Where-Object { $_.NodeName -ne '*' }; foreach ($node in $nodes) { [PSCustomObject] @{ Name = $node.NodeName; @@ -61,7 +61,7 @@ function TestLabConfigurationMof { } process { $Path = Resolve-Path -Path $Path -ErrorAction Stop; - $node = $ConfigurationData.AllNodes | Where { $_.NodeName -eq $Name }; + $node = $ConfigurationData.AllNodes | Where-Object { $_.NodeName -eq $Name }; $mofPath = Join-Path -Path $Path -ChildPath ('{0}.mof' -f $node.NodeName); WriteVerbose ($localized.CheckingForNodeFile -f $mofPath); @@ -200,7 +200,7 @@ function Start-LabConfiguration { } process { WriteVerbose $localized.StartedLabConfiguration; - $nodes = $ConfigurationData.AllNodes | Where { $_.NodeName -ne '*' }; + $nodes = $ConfigurationData.AllNodes | Where-Object { $_.NodeName -ne '*' }; $Path = ResolvePathEx -Path $Path; foreach ($node in $nodes) { @@ -266,7 +266,7 @@ function Remove-LabConfiguration { } process { WriteVerbose $localized.StartedLabConfiguration; - $nodes = $ConfigurationData.AllNodes | Where { $_.NodeName -ne '*' }; + $nodes = $ConfigurationData.AllNodes | Where-Object { $_.NodeName -ne '*' }; foreach ($node in $nodes) { ##TODO: Should this not ensure that VMs are powered off? RemoveLabVM -Name $node.NodeName -ConfigurationData $ConfigurationData -RemoveSwitch:$RemoveSwitch; diff --git a/Src/LabHostConfiguration.ps1 b/Src/LabHostConfiguration.ps1 index a3dad83f..2c40e531 100644 --- a/Src/LabHostConfiguration.ps1 +++ b/Src/LabHostConfiguration.ps1 @@ -17,7 +17,7 @@ function GetLabHostSetupConfiguration { $labHostSetupConfiguration = @(); if ($isDesktop) { - Write-Debug 'Implementing desktop configuration.'; + Write-Debug -Message 'Implementing desktop configuration.'; $labHostSetupConfiguration += @{ UseDefault = $true; Description = 'Hyper-V role'; @@ -31,7 +31,7 @@ function GetLabHostSetupConfiguration { }; } else { - Write-Debug 'Implementing server configuration.'; + Write-Debug -Message 'Implementing server configuration.'; $labHostSetupConfiguration += @{ UseDefault = $true; Description = 'Hyper-V Role'; diff --git a/Src/LabImage.ps1 b/Src/LabImage.ps1 index 0ff0569f..602505d9 100644 --- a/Src/LabImage.ps1 +++ b/Src/LabImage.ps1 @@ -27,7 +27,7 @@ function Get-LabImage { FileSize = $diskImage.FileSize; Size = $diskImage.Size; } - Write-Output $labImage; + Write-Output -InputObject $labImage; } } #end foreach $image } #end process @@ -137,7 +137,7 @@ function New-LabImage { catch { ## Have to ensure VHDX is dismounted before we can delete! $imageCreationFailed = $true; - Write-Error $_; + Write-Error -Message $_; } finally { ## Dismount VHDX diff --git a/Src/LabResource.ps1 b/Src/LabResource.ps1 index 561074a7..032d1ec8 100644 --- a/Src/LabResource.ps1 +++ b/Src/LabResource.ps1 @@ -120,7 +120,7 @@ function ResolveLabResource { [Parameter(Mandatory)] [System.String] $ResourceId ) process { - $resource = $ConfigurationData.NonNodeData.($labDefaults.ModuleName).Resource | Where Id -eq $ResourceId; + $resource = $ConfigurationData.NonNodeData.($labDefaults.ModuleName).Resource | Where-Object Id -eq $ResourceId; if ($resource) { return $resource; } else { throw ($localized.CannotResolveResourceIdError -f $resourceId); } } diff --git a/Src/LabVM.ps1 b/Src/LabVM.ps1 index f658c2ab..fe9c806e 100644 --- a/Src/LabVM.ps1 +++ b/Src/LabVM.ps1 @@ -95,10 +95,10 @@ function Get-LabVM { try { ImportDscResource -ModuleName xHyper-V -ResourceName MSFT_xVMHyperV -Prefix VM; $vm = GetDscResource -ResourceName VM -Parameters $xVMParams; - Write-Output ([PSCustomObject] $vm); + Write-Output -InputObject ([PSCustomObject] $vm); } catch { - Write-Error ($localized.CannotLocateNodeError -f $nodeName); + Write-Error -Message ($localized.CannotLocateNodeError -f $nodeName); } } #end foreach node @@ -124,7 +124,7 @@ function Test-LabVM { } process { if (-not $Name) { - $Name = $ConfigurationData.AllNodes | Where NodeName -ne '*' | ForEach-Object { $_.NodeName } + $Name = $ConfigurationData.AllNodes | Where-Object NodeName -ne '*' | ForEach-Object { $_.NodeName } } foreach ($vmName in $Name) { $isNodeCompliant = $true; @@ -158,7 +158,7 @@ function Test-LabVM { if (-not (TestLabVirtualMachine @testLabVirtualMachineParams -Name $vmName)) { $isNodeCompliant = $false; } - Write-Output $isNodeCompliant; + Write-Output -InputObject $isNodeCompliant; } } #end process } #end function Test-LabVM @@ -278,7 +278,7 @@ function NewLabVM { } } - Write-Output (Get-VM -Name $Name); + Write-Output -InputObject (Get-VM -Name $Name); } #end process } #end function NewLabVM diff --git a/Src/LabVMSnapshot.ps1 b/Src/LabVMSnapshot.ps1 index bf21a42c..977be63c 100644 --- a/Src/LabVMSnapshot.ps1 +++ b/Src/LabVMSnapshot.ps1 @@ -12,7 +12,7 @@ function RemoveLabVMSnapshot { <## TODO: Add the ability to force/wait for the snapshots to be removed. When removing snapshots it take a minute or two before the files are actually removed. This causes issues when performing a lab reset #> foreach ($vmName in $Name) { - Get-VMSnapshot -VMName $Name -ErrorAction SilentlyContinue | Where Name -like $SnapshotName | ForEach-Object { + Get-VMSnapshot -VMName $Name -ErrorAction SilentlyContinue | Where-Object Name -like $SnapshotName | ForEach-Object { WriteVerbose ($localized.RemovingSnapshot -f $vmName, $_.Name); Remove-VMSnapshot -VMName $_.VMName -Name $_.Name; } @@ -55,7 +55,7 @@ function GetLabVMSnapshot { WriteWarning ($localized.SnapshotMissingWarning -f $SnapshotName, $vmName); } else { - Write-Output $snapshot; + Write-Output -InputObject $snapshot; } } #end foreach VM } #end process diff --git a/VirtualEngineLab.psm1 b/VirtualEngineLab.psm1 index da417cee..70a7881a 100644 --- a/VirtualEngineLab.psm1 +++ b/VirtualEngineLab.psm1 @@ -2,7 +2,7 @@ ## Set the global defaults $labDefaults = @{ - ModuleRoot = Split-Path -Parent $MyInvocation.MyCommand.Path; + ModuleRoot = Split-Path -Path $MyInvocation.MyCommand.Path -Parent; ModuleName = 'VirtualEngineLab'; ConfigurationData = 'Config'; HostConfigFilename = 'HostDefaults.json'; @@ -21,7 +21,7 @@ $moduleLibPath = Join-Path -Path $moduleRoot -ChildPath 'Lib'; $moduleSrcPath = Join-Path -Path $moduleRoot -ChildPath 'Src'; Get-ChildItem -Path $moduleLibPath,$moduleSrcPath -Include *.ps1 -Exclude '*.Tests.ps1' -Recurse | ForEach-Object { - Write-Verbose ('Importing library\source file ''{0}''.' -f $_.FullName); + Write-Verbose -Message ('Importing library\source file ''{0}''.' -f $_.FullName); . $_.FullName; } @@ -29,8 +29,8 @@ Get-ChildItem -Path $moduleLibPath,$moduleSrcPath -Include *.ps1 -Exclude '*.Tes $moduleConfigPath = Join-Path -Path $moduleRoot -ChildPath 'Config'; $allUsersConfigPath = Join-Path -Path $env:AllUsersProfile -ChildPath "$($labDefaults.ModuleName)\Certificates\"; [ref] $null = NewDirectory -Path $allUsersConfigPath; -Get-ChildItem -Path $moduleConfigPath -Include *.cer,*.pfx -Recurse | % { - Write-Verbose ('Updating certificate ''{0}''.' -f $_.FullName); +Get-ChildItem -Path $moduleConfigPath -Include *.cer,*.pfx -Recurse | ForEach-Object { + Write-Verbose -Message ('Updating certificate ''{0}''.' -f $_.FullName); Copy-Item -Path $_ -Destination $allUsersConfigPath; } diff --git a/en-US/Example.ps1 b/en-US/Example.ps1 index e8f6473d..34b00251 100644 --- a/en-US/Example.ps1 +++ b/en-US/Example.ps1 @@ -8,7 +8,7 @@ Configuration Example { ! xDhcpServer (v1.3.0 or later): https://github.com/iainbrighton/xDhcpServer/dev (due to xDhcpServerAuthorization resource) #> param ( - [Parameter()] [ValidateNotNull()] [PSCredential] $Credential = (Get-Credential 'Administrator') + [Parameter()] [ValidateNotNull()] [PSCredential] $Credential = (Get-Credential -Credential 'Administrator') ) Import-DscResource -Module xComputerManagement, xNetworking, xActiveDirectory; Import-DscResource -Module xSmbShare, PSDesiredStateConfiguration; @@ -70,7 +70,7 @@ Configuration Example { node $AllNodes.Where({$_.Role -in 'DC'}).NodeName { ## Flip credential into username@domain.com - $domainCredential = New-Object System.Management.Automation.PSCredential("$($Credential.UserName)@$($node.DomainName)", $Credential.Password); + $domainCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList ("$($Credential.UserName)@$($node.DomainName)", $Credential.Password); xComputer 'Hostname' { Name = $node.NodeName; @@ -146,7 +146,7 @@ Configuration Example { ## INET1 is on the 'Internet' subnet and not domain-joined node $AllNodes.Where({$_.Role -in 'CLIENT','APP','EDGE'}).NodeName { ## Flip credential into username@domain.com - $domainCredential = New-Object System.Management.Automation.PSCredential("$($Credential.UserName)@$($node.DomainName)", $Credential.Password); + $domainCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList ("$($Credential.UserName)@$($node.DomainName)", $Credential.Password); xComputer 'DomainMembership' { Name = $node.NodeName; @@ -157,7 +157,7 @@ Configuration Example { node $AllNodes.Where({$_.Role -in 'APP'}).NodeName { ## Flip credential into username@domain.com - $domainCredential = New-Object System.Management.Automation.PSCredential("$($Credential.UserName)@$($node.DomainName)", $Credential.Password); + $domainCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList ("$($Credential.UserName)@$($node.DomainName)", $Credential.Password); foreach ($feature in @( 'Web-Default-Doc',