CDSoftware/PowerShellHelper.ps1
function Get-PowerShellUserProfileFolders { <# .SYNOPSIS ��ȡ PowerShell �� profile Ŀ¼���ڡ��ĵ����ļ����У������ڿ��ܴ��ڶ�� profile Ŀ¼����˷���һ�����顣 .DESCRIPTION ��ȡ PowerShell �� profile Ŀ¼���ڡ��ĵ����ļ����У������ڿ��ܴ��ڶ�� profile Ŀ¼����˷���һ�����顣 .PARAMETER Create ��Ŀ¼������ʱ���������� .EXAMPLE Get-PowerShellProfileFolders .OUTPUTS String[] #> [CmdletBinding()] PARAM( [Switch] $Create ) PROCESS { $doc = [Environment]::GetFolderPath("MyDocuments", 32768) $ret = @() foreach ($child in 'PowerShell', 'WindowsPowerShell') { $dir = Join-Path $doc $child $inc = $false if (Test-Path $dir -PathType Container) { $inc = $true } elseif ($Create) { New-Item -Path $dir -ItemType Directory $inc = $true } if ($inc) { $ret += $dir } } return $ret } } function Get-PowerShellUserProfiles { <# .SYNOPSIS ��ȡ PowerShell �� profile �ļ����ڡ��ĵ����ļ����У������ڿ��ܴ��ڶ�� profile �ļ�����˷���һ�����顣 .DESCRIPTION ��ȡ PowerShell �� profile �ļ����ڡ��ĵ����ļ����У������ڿ��ܴ��ڶ�� profile �ļ�����˷���һ�����顣 .PARAMETER Create �� profile �ļ�������ʱ���������� .EXAMPLE Get-PowerShellUserProfiles .OUTPUTS String[] #> [CmdletBinding()] PARAM( [Switch] $Create ) PROCESS { $ret = @() $dirs = Get-PowerShellUserProfileFolders -Create:$Create foreach ($dir in $dirs) { $fn = Join-Path $dir 'profile.ps1' $inc = $false if (Test-Path $fn -PathType Leaf) { $inc = $true } elseif ($Create) { New-Item -Path $fn -ItemType File $inc = $true } if ($inc) { $ret += $fn } } return $ret } } |