powershell 测试PowerShell配置文件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell 测试PowerShell配置文件相关的知识,希望对你有一定的参考价值。
<#
.Synopsis
Evaluates all 6 PowerShell Profile locations and will indicate if they are present - and if so what they contain
.DESCRIPTION
Checks the location of all 6 PowerShell Profile to determine if there is a Profile file loaded there. If there is, the contents will be scanned so you can see what profile customizations are being loaded up.
.EXAMPLE
Test-PSProfiles
Checks all 6 PowerShell Profile locations and returns results
.EXAMPLE
Test-PSProfiles -Verbose
Checks all 6 PowerShell Profile locations and returns results with verbose output
.OUTPUTS
Custom PSObject
Name Present Contents
---- ------- --------
allUsersAllHosts False
allUsersCurrentHostConsole False
allUsersCurrentHostISE False
currentUserAllHosts False
currentUserCurrentHostConsole True Write-Host "Hello Jake. Welcome Back" -ForegroundCo...
currentUserCurrentHostISE False
.NOTES
Author: Jake Morrison
http://techthoughts.info
Based on information from scripting guy: https://blogs.technet.microsoft.com/heyscriptingguy/2012/05/21/understanding-the-six-powershell-profiles/
$PSHOME = C:\Windows\System32\WindowsPowerShell\v1.0
$HOME = C:\Users\currentuser
#>
function Test-PSProfiles {
[CmdletBinding()]
param()
begin {
Write-Verbose -Message "Begin."
Write-Verbose -Message "Loading 6 PS Profile locations..."
$allUsersAllHosts = "$PSHOME\Profile.ps1"
$allUsersCurrentHostConsole = "$PSHOME\Microsoft.PowerShell_profile.ps1"
$allUsersCurrentHostISE = "$PSHOME\Microsoft.PowerShellISE_profile.ps1"
$currentUserAllHosts = "$HOME\Documents\WindowsPowerShell\Profile.ps1"
$currentUserCurrentHostConsole = "$HOME\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1.ps1"
$currentUserCurrentHostISE = "$Home\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1"
Write-Verbose -Message "Creating Hash of all profile locations..."
$profileHash = @{
"allUsersAllHosts" = $allUsersAllHosts;
"allUsersCurrentHostConsole" = $allUsersCurrentHostConsole;
"allUsersCurrentHostISE" = $allUsersCurrentHostISE;
"currentUserAllHosts" = $currentUserAllHosts;
"currentUserCurrentHostConsole" = $currentUserCurrentHostConsole;
"currentUserCurrentHostISE" = $currentUserCurrentHostISE;
}#profileHash
}#begin
process {
Write-Verbose -Message "Process."
$resultsArray = @()
Write-Verbose -Message "Evaluating each PS Profile location..."
$profileHash.GetEnumerator() | ForEach-Object {
$nameProperty = ($_.Name)
Write-Verbose -Message "Checking $nameProperty"
$evalProperty = $false
$contentsProperty = ""
if (Test-Path ($_.value)) {
Write-Verbose -Message "Found."
$evalProperty = $true
$contentsProperty = Get-Content ($_.value)
}#if-testLocation
$resultsArray += @{
"Name" = $nameProperty;
"Present" = $evalProperty;
"Contents" = $contentsProperty
}
}#ForEach-Object
}#proces
end {
Write-Verbose -Message "Generating results..."
$a = $resultsArray | ForEach-Object { new-object PSObject -Property $_}
$output = $a | Select-Object Name, Present, Contents | Sort-Object Name
Write-Verbose -Message "Complete."
return $output
}#end
}#function
以上是关于powershell 测试PowerShell配置文件的主要内容,如果未能解决你的问题,请参考以下文章
powershell 测试tridion-powershell-modules
powershell 测试tridion-powershell-modules
powershell 使用powershell创建用于测试SQL的Azure VM