techthoughts2
2/28/2016 - 4:41 AM

PowerShell Gallery Commands

PowerShell Gallery Commands

#get the updated help
Update-Help -Module PowerShellGet

#install NuGet if not already installed
$testNuGet = $null
$nuGet = Get-PackageProvider | Select-Object -ExpandProperty Name
foreach($result in $nuGet){
    if($result -eq "NuGet"){
        $testNuGet = $true
    }
}
if($testNuGet -eq $true){
    Write-Host "NuGet is installed" -ForegroundColor Magenta
}
else{
    Install-PackageProvider -Name NuGet -Force
}

#find some scripts and stuff
Find-Module -Repository PSGallery
Find-Script -Repository PSGallery
Find-Module -Name PSReadLine -Repository PSGallery | Get-Member
Find-Script -Repository PSGallery -Tag Hyper-V
Find-Script -Repository PSGallery -Filter Hyper-V

#save - but not install (inspect stuff)
Save-Module
Save-Script 
Save-Script -Name "Fabrikam-ClientScript" -Repository PSGallery -Path "D:\ScriptSharingDemo"

#actually install
#modules: $env:USERPROFILE\Documents\WindowsPowerShell\Modules
#scripts: $env:USERPROFILE\Documents\WindowsPowerShell\Scripts
Install-Module
Install-Script

#to update installed script/module
Update-Module
Update-Script

#show what is currently installed
Get-InstalledModule
Get-InstalledScript

#publish stuff
Publish-Module -Name <moduleName> -NuGetApiKey <apiKey> 
Publish-Script -Path <scriptPath> -NuGetApiKey <apiKey>
Publish-Script -Path "C:\rs-pkgs\Diag-V.ps1" -NuGetApiKey 

#writing file info for a script before upload
Update-ScriptFileInfo -Path "C:\rs-pkgs\Diag-V2.ps1"
Test-ScriptFileInfo -Path "C:\rs-pkgs\Diag-V.ps1"
New-ScriptFileInfo -Path "C:\rs-pkgs\Diag-V.ps1" -Verbose

# top 50 modules
$allModules = Find-Module -Name *

$community = $allModules | ? {
    $_.AdditionalMetadata.copyright -notlike "*Microsoft*" `
    -and $_.AdditionalMetadata.CompanyName -notlike "*Microsoft*" `
    -and $_.AdditionalMetadata.CompanyName -notlike "*Amazon.com*" `
    -and $_.AdditionalMetadata.copyright -notlike "*Amazon.com*" `
    -and $_.AdditionalMetadata.CompanyName -notlike "*VMware*" `
    -and $_.AdditionalMetadata.copyright -notlike "*VMware*" `
    }

$top50 = $community `
    | Sort-Object {[int]$_.AdditionalMetadata.downloadCount} -Descending `
    | Select-Object Name,@{N="Downloads";E={$_.AdditionalMetadata.downloadCount}} -First 50


$top50Summary = $community `
    | Sort-Object {[int]$_.AdditionalMetadata.downloadCount} -Descending `
    | Select-Object Name,@{N="Summary";E={$_.AdditionalMetadata.summary}} -First 50