Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 30 additions & 29 deletions build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ if ($IsLinux) {
$IsCentOS = $LinuxInfo.ID -match 'centos' -and $LinuxInfo.VERSION_ID -match '7'
$IsFedora = $LinuxInfo.ID -match 'fedora' -and $LinuxInfo.VERSION_ID -ge 24
$IsOpenSUSE = $LinuxInfo.ID -match 'opensuse'
$IsOpenSUSE13 = $IsOpenSUSE -and $LinuxInfo.VERSION_ID -match '13'
${IsOpenSUSE42.1} = $IsOpenSUSE -and $LinuxInfo.VERSION_ID -match '42.1'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variables is unused - so Ok to remove.

$IsRedHatFamily = $IsCentOS -or $IsFedora -or $IsOpenSUSE

# Workaround for temporary LD_LIBRARY_PATH hack for Fedora 24
Expand Down Expand Up @@ -283,7 +281,7 @@ Fix steps:
log "Run dotnet restore"

$srcProjectDirs = @($Options.Top, "$PSScriptRoot/src/TypeCatalogGen", "$PSScriptRoot/src/ResGen")
$testProjectDirs = Get-ChildItem "$PSScriptRoot/test/*.csproj" -Recurse | % { [System.IO.Path]::GetDirectoryName($_) }
$testProjectDirs = Get-ChildItem "$PSScriptRoot/test/*.csproj" -Recurse | ForEach-Object { [System.IO.Path]::GetDirectoryName($_) }

$RestoreArguments = @("--verbosity")
if ($PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent) {
Expand All @@ -292,7 +290,7 @@ Fix steps:
$RestoreArguments += "quiet"
}

($srcProjectDirs + $testProjectDirs) | % { Start-NativeExecution { dotnet restore $_ $RestoreArguments } }
($srcProjectDirs + $testProjectDirs) | ForEach-Object { Start-NativeExecution { dotnet restore $_ $RestoreArguments } }
}

# handle ResGen
Expand Down Expand Up @@ -354,9 +352,9 @@ Fix steps:

# Compile native resources
$currentLocation = Get-Location
@("nativemsh/pwrshplugin") | % {
@("nativemsh/pwrshplugin") | ForEach-Object {
$nativeResourcesFolder = $_
Get-ChildItem $nativeResourcesFolder -Filter "*.mc" | % {
Get-ChildItem $nativeResourcesFolder -Filter "*.mc" | ForEach-Object {
$command = @"
cmd.exe /C cd /d "$currentLocation" "&" "$($vcVarsPath)\vcvarsall.bat" "$NativeHostArch" "&" mc.exe -o -d -c -U "$($_.FullName)" -h "$nativeResourcesFolder" -r "$nativeResourcesFolder"
"@
Expand Down Expand Up @@ -394,7 +392,7 @@ cmd.exe /C cd /d "$location" "&" "$($vcVarsPath)\vcvarsall.bat" "$NativeHostArch

# Copy the binaries from the local build directory to the packaging directory
$dstPath = ($script:Options).Top
$FilesToCopy | % {
$FilesToCopy | ForEach-Object {
$srcPath = Join-Path (Join-Path (Join-Path (Get-Location) "bin") $msbuildConfiguration) "$clrTarget/$_"
log " Copying $srcPath to $dstPath"
Copy-Item $srcPath $dstPath
Expand Down Expand Up @@ -460,7 +458,7 @@ cmd.exe /C cd /d "$location" "&" "$($vcVarsPath)\vcvarsall.bat" "$NativeHostArch
# publish netcoreapp2.0 reference assemblies
try {
Push-Location "$PSScriptRoot/src/TypeCatalogGen"
$refAssemblies = Get-Content -Path "powershell.inc" | ? { $_ -like "*microsoft.netcore.app*" } | % { $_.TrimEnd(';') }
$refAssemblies = Get-Content -Path "powershell.inc" | Where-Object { $_ -like "*microsoft.netcore.app*" } | Foreach-Object { $_.TrimEnd(';') }
$refDestFolder = Join-Path -Path $publishPath -ChildPath "ref"

if (Test-Path $refDestFolder -PathType Container) {
Expand Down Expand Up @@ -516,6 +514,7 @@ function Compress-TestContent {

function New-PSOptions {
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param(
[ValidateSet("Linux", "Debug", "Release", "CodeCoverage", "")]
[string]$Configuration,
Expand Down Expand Up @@ -611,7 +610,7 @@ function New-PSOptions {
}

if (-not $Runtime) {
$Runtime = dotnet --info | % {
$Runtime = dotnet --info | ForEach-Object {
if ($_ -match "RID") {
$_ -split "\s+" | Select-Object -Last 1
}
Expand Down Expand Up @@ -668,7 +667,7 @@ function Get-PesterTag {
$alltags = @{}
$warnings = @()

get-childitem -Recurse $testbase -File |?{$_.name -match "tests.ps1"}| %{
get-childitem -Recurse $testbase -File | Where-Object {$_.name -match "tests.ps1"}| Foreach-Object {
$fullname = $_.fullname
$tok = $err = $null
$ast = [System.Management.Automation.Language.Parser]::ParseFile($FullName, [ref]$tok,[ref]$err)
Expand All @@ -684,7 +683,7 @@ function Get-PesterTag {
$warnings += "TAGS must be static strings, error in ${fullname}, line $lineno"
}
$values = $vAst.FindAll({$args[0] -is "System.Management.Automation.Language.StringConstantExpressionAst"},$true).Value
$values | % {
$values | ForEach-Object {
if (@('REQUIREADMINONWINDOWS', 'SLOW') -contains $_) {
# These are valid tags also, but they are not the priority tags
}
Expand Down Expand Up @@ -728,7 +727,7 @@ function Publish-PSTestTools {
$tools = @(
@{Path="${PSScriptRoot}/test/tools/TestExe";Output="testexe"}
)
if ($Options -eq $null)
if ($null -eq $Options)
{
$Options = New-PSOptions
}
Expand Down Expand Up @@ -873,15 +872,15 @@ function Start-PSPester {
{
$lines = Get-Content $outputBufferFilePath | Select-Object -Skip $currentLines
$lines | Write-Host
if ($lines | ? { $_ -eq '__UNELEVATED_TESTS_THE_END__'})
if ($lines | Where-Object { $_ -eq '__UNELEVATED_TESTS_THE_END__'})
{
break
}

$count = ($lines | measure-object).Count
if ($count -eq 0)
{
sleep 1
Start-Sleep -Seconds 1
}
else
{
Expand Down Expand Up @@ -1816,7 +1815,7 @@ function Publish-NuGetFeed
'Microsoft.WSMan.Management',
'Microsoft.WSMan.Runtime',
'Microsoft.PowerShell.SDK'
) | % {
) | ForEach-Object {
if ($VersionSuffix) {
dotnet pack "src/$_" --output $OutputPath --version-suffix $VersionSuffix /p:IncludeSymbols=true
} else {
Expand Down Expand Up @@ -1869,7 +1868,7 @@ function Start-DevPowerShell {

$env:DEVPATH = $binDir
if ($ZapDisable) {
$env:COMPLUS_ZapDisable = 1
[Environment]::SetEnvironmentVariable('COMPLUS_ZapDisable', 1)
}

if ($FullCLR -and (-not (Test-Path $binDir\powershell.exe.config))) {
Expand Down Expand Up @@ -1947,7 +1946,7 @@ function Copy-MappedFiles {
# Do some intelligence to prevent shooting us in the foot with CL management

# finding base-line CL
$cl = git --git-dir="$PSScriptRoot/.git" tag | % {if ($_ -match 'SD.(\d+)$') {[int]$Matches[1]} } | Sort-Object -Descending | Select-Object -First 1
$cl = git --git-dir="$PSScriptRoot/.git" tag | Foreach-Object {if ($_ -match 'SD.(\d+)$') {[int]$Matches[1]} } | Sort-Object -Descending | Select-Object -First 1
if ($cl) {
log "Current base-line CL is SD:$cl (based on tags)"
} else {
Expand Down Expand Up @@ -1979,7 +1978,7 @@ function Copy-MappedFiles {
}

end {
$map.GetEnumerator() | % {
$map.GetEnumerator() | Foreach-Object {
New-Item -ItemType Directory (Split-Path $_.Value) -ErrorAction SilentlyContinue > $null
Copy-Item $_.Key $_.Value -Verbose:([bool]$PSBoundParameters['Verbose']) -WhatIf:$WhatIf
}
Expand All @@ -1989,6 +1988,7 @@ function Copy-MappedFiles {
function Get-Mappings
{
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param(
[Parameter(ValueFromPipeline=$true)]
[string[]]$Path = "$PSScriptRoot",
Expand Down Expand Up @@ -2020,7 +2020,7 @@ function Get-Mappings

end {
$map = @{}
$mapFiles | % {
$mapFiles | ForEach-Object {
$file = $_
try {
$rawHashtable = $_ | Get-Content -Raw | ConvertFrom-Json | Convert-PSObjectToHashtable
Expand All @@ -2036,7 +2036,7 @@ function Get-Mappings
$mapRoot = $mapRoot.Replace('\', '/')
}

$rawHashtable.GetEnumerator() | % {
$rawHashtable.GetEnumerator() | ForEach-Object {
$newKey = if ($Root) { Join-Path $Root $_.Key } else { $_.Key }
$newValue = if ($KeepRelativePaths) { ($mapRoot + '/' + $_.Value) } else { Join-Path $mapRoot $_.Value }
$map[$newKey] = $newValue
Expand Down Expand Up @@ -2064,10 +2064,10 @@ function Send-GitDiffToSd {
)

# this is only for windows, because you cannot have SD enlistment on Linux
$patchPath = (ls (Join-Path (get-command git).Source '..\..') -Recurse -Filter 'patch.exe').FullName
$patchPath = (Get-ChildItem (Join-Path (get-command git).Source '..\..') -Recurse -Filter 'patch.exe').FullName
$m = Get-Mappings -KeepRelativePaths -Root $AdminRoot
$affectedFiles = git diff --name-only $diffArg1 $diffArg2
$affectedFiles | % {
$affectedFiles | ForEach-Object {
log "Changes in file $_"
}

Expand Down Expand Up @@ -2184,12 +2184,12 @@ function Convert-TxtResourceToXml
)

process {
$Path | % {
Get-ChildItem $_ -Filter "*.txt" | % {
$Path | ForEach-Object {
Get-ChildItem $_ -Filter "*.txt" | ForEach-Object {
$txtFile = $_.FullName
$resxFile = Join-Path (Split-Path $txtFile) "$($_.BaseName).resx"
$resourceHashtable = ConvertFrom-StringData (Get-Content -Raw $txtFile)
$resxContent = $resourceHashtable.GetEnumerator() | % {
$resxContent = $resourceHashtable.GetEnumerator() | ForEach-Object {
@'
<data name="{0}" xml:space="preserve">
<value>{1}</value>
Expand All @@ -2213,7 +2213,7 @@ function Start-XamlGen
)

Use-MSBuild
Get-ChildItem -Path "$PSScriptRoot/src" -Directory | % {
Get-ChildItem -Path "$PSScriptRoot/src" -Directory | ForEach-Object {
$XamlDir = Join-Path -Path $_.FullName -ChildPath Xamls
if ((Test-Path -Path $XamlDir -PathType Container) -and
(@(Get-ChildItem -Path "$XamlDir\*.xaml").Count -gt 0)) {
Expand All @@ -2231,7 +2231,7 @@ function Start-XamlGen
throw "No .cs or .g.resources files are generated for $XamlDir, something went wrong. Run 'Start-XamlGen -Verbose' for details."
}

$filesToCopy | % {
$filesToCopy | ForEach-Object {
$sourcePath = $_.FullName
Write-Verbose "Copy generated xaml artifact: $sourcePath -> $DestinationDir"
Copy-Item -Path $sourcePath -Destination $DestinationDir
Expand Down Expand Up @@ -2293,7 +2293,7 @@ function script:ConvertFrom-Xaml {
log "ConvertFrom-Xaml for $XamlDir"

$Pages = ""
Get-ChildItem -Path "$XamlDir\*.xaml" | % {
Get-ChildItem -Path "$XamlDir\*.xaml" | ForEach-Object {
$Page = $Script:XamlProjPage -f $_.FullName
$Pages += $Page
}
Expand Down Expand Up @@ -2351,7 +2351,7 @@ function script:logerror([string]$message) {
function script:precheck([string]$command, [string]$missedMessage) {
$c = Get-Command $command -ErrorAction SilentlyContinue
if (-not $c) {
if ($missedMessage -ne $null)
if ($null -ne $missedMessage)
{
Write-Warning $missedMessage
}
Expand Down Expand Up @@ -2604,6 +2604,7 @@ function New-MSIPackage
function New-AppxPackage
{
[CmdletBinding()]
[OutputType([String])]
param (

# Name of the Package
Expand Down
4 changes: 2 additions & 2 deletions demos/Apache/Apache/Apache.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ Function Get-ApacheVHost{
}
}

if ($ServerName -ne $null){
if ($null -ne $ServerName){
$vHost = [ApacheVirtualHost]::New($ServerName, $ConfFile, $ListenAddress.Split(":")[0],$ListenAddress.Split(":")[1])
$ExtProps = GetVHostProps $ConfFile $ServerName $ListenAddress
$vHost.DocumentRoot = $ExtProps.DocumentRoot
Expand All @@ -206,7 +206,7 @@ Function Restart-ApacheHTTPServer{
[switch]$Graceful
)

if ($Graceful -eq $null){$Graceful = $false}
if ($null -eq $Graceful){$Graceful = $false}
$cmd = GetApacheCmd
if ($Graceful){
& $global:sudocmd $cmd -k graceful
Expand Down
14 changes: 7 additions & 7 deletions demos/Azure/Azure-Demo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Import-Module AzureRM.NetCore.Preview
Login-AzureRmAccount

### Specify a name for Azure Resource Group
$resourceGroupName = "PSAzDemo" + (New-Guid | % guid) -replace "-",""
$resourceGroupName = "PSAzDemo" + (New-Guid | ForEach-Object guid) -replace "-",""
$resourceGroupName

### Create a new Azure Resource Group
Expand All @@ -26,7 +26,7 @@ New-AzureRmResourceGroup -Name $resourceGroupName -Location "West US"
### Deploy an Ubuntu 14.04 VM using Resource Manager cmdlets
### Template is available at
### http://armviz.io/#/?load=https:%2F%2Fraw.githubusercontent.com%2FAzure%2Fazure-quickstart-templates%2Fmaster%2F101-vm-simple-linux%2Fazuredeploy.json
$dnsLabelPrefix = $resourceGroupName | % tolower
$dnsLabelPrefix = $resourceGroupName | ForEach-Object tolower
$dnsLabelPrefix
$password = ConvertTo-SecureString -String "PowerShellRocks!" -AsPlainText -Force
New-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateFile ./Compute-Linux.json -adminUserName psuser -adminPassword $password -dnsLabelPrefix $dnsLabelPrefix
Expand All @@ -35,21 +35,21 @@ New-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroupName -Templa
Get-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroupName

### Discover the resources we created by the previous deployment
Find-AzureRmResource -ResourceGroupName $resourceGroupName | select Name,ResourceType,Location
Find-AzureRmResource -ResourceGroupName $resourceGroupName | Select-Object Name,ResourceType,Location

### Get the state of the VM we created
### Notice: The VM is in running state
Get-AzureRmResource -ResourceName MyUbuntuVM -ResourceType Microsoft.Compute/virtualMachines -ResourceGroupName $resourceGroupName -ODataQuery '$expand=instanceView' | % properties | % instanceview | % statuses
Get-AzureRmResource -ResourceName MyUbuntuVM -ResourceType Microsoft.Compute/virtualMachines -ResourceGroupName $resourceGroupName -ODataQuery '$expand=instanceView' | ForEach-Object properties | ForEach-Object instanceview ForEach-Object statuses

### Discover the operations we can perform on the compute resource
### Notice: Operations like "Power Off Virtual Machine", "Start Virtual Machine", "Create Snapshot", "Delete Snapshot", "Delete Virtual Machine"
Get-AzureRmProviderOperation -OperationSearchString Microsoft.Compute/* | select OperationName,Operation
Get-AzureRmProviderOperation -OperationSearchString Microsoft.Compute/* | Select-Object OperationName,Operation

### Power Off the Virtual Machine we created
Invoke-AzureRmResourceAction -ResourceGroupName $resourceGroupName -ResourceType Microsoft.Compute/virtualMachines -ResourceName MyUbuntuVM -Action poweroff

### Check the VM state again. It should be stopped now.
Get-AzureRmResource -ResourceName MyUbuntuVM -ResourceType Microsoft.Compute/virtualMachines -ResourceGroupName $resourceGroupName -ODataQuery '$expand=instanceView' | % properties | % instanceview | % statuses
Get-AzureRmResource -ResourceName MyUbuntuVM -ResourceType Microsoft.Compute/virtualMachines -ResourceGroupName $resourceGroupName -ODataQuery '$expand=instanceView' | ForEach-Object properties | ForEach-Object instanceview | ForEach-Object statuses

### As you know, you may still be incurring charges even if the VM is in stopped state
### Deallocate the resource to avoid this charge
Expand All @@ -59,7 +59,7 @@ Invoke-AzureRmResourceAction -ResourceGroupName $resourceGroupName -ResourceType
Remove-AzureRmResource -ResourceName MyUbuntuVM -ResourceType Microsoft.Compute/virtualMachines -ResourceGroupName $resourceGroupName

### Look at the resources that still exists
Find-AzureRmResource -ResourceGroupName $resourceGroupName | select Name,ResourceType,Location
Find-AzureRmResource -ResourceGroupName $resourceGroupName | Select-Object Name,ResourceType,Location

### Remove the resource group and its resources
Remove-AzureRmResourceGroup -Name $resourceGroupName
2 changes: 1 addition & 1 deletion demos/crontab/CronTab/CronTab.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function Remove-CronJob {
.DESCRIPTION
Removes the exactly matching cron job from the cron table
.EXAMPLE
Get-CronJob | ? {%_.Command -like 'foo *'} | Remove-CronJob
Get-CronJob | Where-Object {%_.Command -like 'foo *'} | Remove-CronJob
.RETURNVALUE
None
.PARAMETER UserName
Expand Down
2 changes: 1 addition & 1 deletion docs/KNOWNISSUES.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Removing the aliases exposes the native command experience to the PowerShell use

Currently, PowerShell only does wildcard expansion (globbing) for built-in cmdlets on Windows, and for external commands or binaries as well as cmdlets on Linux.
This means that a command like `ls *.txt` will fail because the asterisk will not be expanded to match file names.
You can work around this by doing `ls (gci *.txt | % name)` or, more simply, `gci *.txt` using the PowerShell built-in equivalent to `ls`.
You can work around this by doing `ls (gci *.txt | ForEach-Object name)` or, more simply, `gci *.txt` using the PowerShell built-in equivalent to `ls`.

See [#954](https://github.com/PowerShell/PowerShell/issues/954) to give us feedback on how to improve the globbing experience on Linux/macOS.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1967,7 +1967,7 @@ public Int16 Delay
foreach ($computerName in $array[1])
{
$ret = $null
if ($array[0] -eq $null)
if ($null -eq array[0])
{
$ret = Invoke-Command -ComputerName $computerName {$true} -SessionOption (New-PSSessionOption -NoMachineProfile) -ErrorAction SilentlyContinue
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ public abstract class ControlPanelItemBaseCommand : PSCmdlet
private static readonly string[] s_controlPanelItemFilterList = new string[] { "Folder Options", "Taskbar and Start Menu" };
private const string TestHeadlessServerScript = @"
$result = $false
$serverManagerModule = Get-Module -ListAvailable | ? {$_.Name -eq 'ServerManager'}
if ($serverManagerModule -ne $null)
$serverManagerModule = Get-Module -ListAvailable | Where-Object {$_.Name -eq 'ServerManager'}
if ($null -ne $serverManagerModule)
{
Import-Module ServerManager
$Gui = (Get-WindowsFeature Server-Gui-Shell).Installed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2140,7 +2140,7 @@ private static ConcurrentDictionary<string, string> InitializeStrongNameDictiona
// $dlls = ((dir c:\windows\Microsoft.NET\Framework\ -fi *.dll -rec) + (dir c:\windows\assembly -fi *.dll -rec)) + (dir C:\Windows\Microsoft.NET\assembly) |
// % { [Reflection.Assembly]::LoadFrom($_.FullName) }
// "var strongNames = new ConcurrentDictionary<string, string>(4, $($dlls.Count), StringComparer.OrdinalIgnoreCase);" > c:\temp\strongnames.txt
// $dlls | Sort-Object -u { $_.GetName().Name} | % { 'strongNames["{0}"] = "{1}";' -f $_.FullName.Split(",", 2)[0], $_.FullName >> c:\temp\strongnames.txt }
// $dlls | Sort-Object -u { $_.GetName().Name} | ForEach-Object { 'strongNames["{0}"] = "{1}";' -f $_.FullName.Split(",", 2)[0], $_.FullName >> c:\temp\strongnames.txt }

// The default concurrent level is 4. We use the default level.
var strongNames = new ConcurrentDictionary<string, string>(4, 744, StringComparer.OrdinalIgnoreCase);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1646,7 +1646,7 @@ internal static char SetDelimiter(PSCmdlet Cmdlet, string ParameterSetName, char
if (UseCulture == true)
{
// ListSeparator is apparently always a character even though the property returns a string, checked via:
// [CultureInfo]::GetCultures("AllCultures") | % { ([CultureInfo]($_.Name)).TextInfo.ListSeparator } | ? Length -ne 1
// [CultureInfo]::GetCultures("AllCultures") | ForEach-Object { ([CultureInfo]($_.Name)).TextInfo.ListSeparator } | Where-Object Length -ne 1
Delimiter = CultureInfo.CurrentCulture.TextInfo.ListSeparator[0];
}
break;
Expand Down
Loading