Get free disk space for different servers with separate credentials - windows

I'm trying to query Disk space info on Grid box and Export it to CSV.
I was able to use Marc Weisel's script to make it use different credentials. I used computers.csv
to store the computer name and referenced credentials. This is working although the problem I'm facing is that Grid box opens for all the servers mentioned in the csv.
I want to view all disk space information on the same grid box.
Below are my script and module I'm using
Import-Module D:\get.psm1
Import-Module D:\out-CSV.psm1
$ComputerList = Import-Csv -Path d:\Computers.csv;
#$servers = 'laptop-pc','laptop-pc','laptop-pc'
$CredentialList = #{
Cred1 = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'laptop-pc\laptop', (ConvertTo-SecureString -String 'tamboli' -AsPlainText -Force);
#Cred2 = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'tnt\administrator', (ConvertTo-SecureString -String 'Atlantic12' -AsPlainText -Force);
}
foreach ($computer in $ComputerList )
{
Get-DiskFree -ComputerName $Computer.Name -Credential $CredentialList[$Computer.Credential] -Format | ? { $_.Type -like '*fixed*' } | select * -ExcludeProperty Type |
}
get.ps1
function Get-DiskFree
{
[CmdletBinding()]
param
(
[Parameter(Position=0,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true)]
[Alias('hostname')]
[Alias('cn')]
[string[]]$ComputerName = $env:COMPUTERNAME,
[Parameter(Position=1,
Mandatory=$false)]
[Alias('runas')]
[System.Management.Automation.Credential()]$Credential =
[System.Management.Automation.PSCredential]::Empty,
[Parameter(Position=2)]
[switch]$Format
)
BEGIN
{
function Format-HumanReadable
{
param ($size)
switch ($size)
{
{$_ -ge 1PB}{"{0:#.#'P'}" -f ($size / 1PB); break}
{$_ -ge 1TB}{"{0:#.#'T'}" -f ($size / 1TB); break}
{$_ -ge 1GB}{"{0:#.#'G'}" -f ($size / 1GB); break}
{$_ -ge 1MB}{"{0:#.#'M'}" -f ($size / 1MB); break}
{$_ -ge 1KB}{"{0:#'K'}" -f ($size / 1KB); break}
default {"{0}" -f ($size) + "B"}
}
}
$wmiq = 'SELECT * FROM Win32_LogicalDisk WHERE Size != Null AND DriveType >= 2'
}
PROCESS
{
foreach ($computer in $ComputerName)
{
try
{
if ($computer -eq $env:COMPUTERNAME)
{
$disks = Get-WmiObject -Query $wmiq `
-ComputerName $computer -ErrorAction Stop
}
else
{
$disks = Get-WmiObject -Query $wmiq `
-ComputerName $computer -Credential $Credential `
-ErrorAction Stop
}
if ($Format)
{
# Create array for $disk objects and then populate
$diskarray = #()
$disks | ForEach-Object { $diskarray += $_ }
$diskarray | Select-Object #{n='Name';e={$_.SystemName}},
#{n='Vol';e={$_.DeviceID}},
#{n='Size';e={Format-HumanReadable $_.Size}},
#{n='Used';e={Format-HumanReadable `
(($_.Size)-($_.FreeSpace))}},
#{n='Avail';e={Format-HumanReadable $_.FreeSpace}},
#{n='Use%';e={[int](((($_.Size)-($_.FreeSpace))`
/($_.Size) * 100))}},
#{n='FS';e={$_.FileSystem}},
#{n='Type';e={$_.Description}}
}
else
{
foreach ($disk in $disks)
{
$diskprops = #{'Volume'=$disk.DeviceID;
'Size'=$disk.Size;
'Used'=($disk.Size - $disk.FreeSpace);
'Available'=$disk.FreeSpace;
'FileSystem'=$disk.FileSystem;
'Type'=$disk.Description
'Computer'=$disk.SystemName;}
# Create custom PS object and apply type
$diskobj = New-Object -TypeName PSObject `
-Property $diskprops
$diskobj.PSObject.TypeNames.Insert(0,'BinaryNature.DiskFree')
Write-Output $diskobj
}
}
}
catch
{
# Check for common DCOM errors and display "friendly" output
switch ($_)
{
{ $_.Exception.ErrorCode -eq 0x800706ba } `
{ $err = 'Unavailable (Host Offline or Firewall)';
break; }
{ $_.CategoryInfo.Reason -eq 'UnauthorizedAccessException' } `
{ $err = 'Access denied (Check User Permissions)';
break; }
default { $err = $_.Exception.Message }
}
Write-Warning "$computer - $err"
}
}
}
END {}
}

You need to append the result of Get-DiskFree to an array in the loop, and pipe that result to the Grid View from outside your loop:
foreach ($computer in $ComputerList )
{
$result += Get-DiskFree -ComputerName $Computer.Name -Credential $CredentialList[$Computer.Credential] -Format | ? { $_.Type -like '*fixed*' } | select * -ExcludeProperty Type
}
$result | Out-GridView
Or, better yet, pipe the result from outside the Foreach-Object loop:
$ComputerList | % {
Get-DiskFree -ComputerName $_.Name -Credential $CredentialList[$_.Credential] -Format | ? { $_.Type -like '*fixed*' } | select * -ExcludeProperty Type
} | Out-GridView

Related

How to get the 'status' column value in Windows explorer by PowerShell or java

when we open a windows explorer, we will see multi-column, like this:
now, I want to get the status column(Circled in red) value by PowerShell or java, Is there a way to do it?
You can include below function and modify as per your need in Powershell.
Below Powershell function can be used to get all details or properties of an item in file explorer.
function Get-FileMetaData {
<#
.SYNOPSIS
Small function that gets metadata information from file providing similar output to what Explorer shows when viewing file
.DESCRIPTION
Small function that gets metadata information from file providing similar output to what Explorer shows when viewing file
.PARAMETER File
FileName or FileObject
.EXAMPLE
Get-ChildItem -Path $Env:USERPROFILE\Desktop -Force | Get-FileMetaData | Out-HtmlView -ScrollX -Filtering -AllProperties
.EXAMPLE
Get-ChildItem -Path $Env:USERPROFILE\Desktop -Force | Where-Object { $_.Attributes -like '*Hidden*' } | Get-FileMetaData | Out-HtmlView -ScrollX -Filtering -AllProperties
.NOTES
#>
[CmdletBinding()]
param (
[Parameter(Position = 0, ValueFromPipeline)][Object] $File,
[switch] $Signature
)
Process {
foreach ($F in $File) {
$MetaDataObject = [ordered] #{}
if ($F -is [string]) {
$FileInformation = Get-ItemProperty -Path $F
} elseif ($F -is [System.IO.DirectoryInfo]) {
#Write-Warning "Get-FileMetaData - Directories are not supported. Skipping $F."
continue
} elseif ($F -is [System.IO.FileInfo]) {
$FileInformation = $F
} else {
Write-Warning "Get-FileMetaData - Only files are supported. Skipping $F."
continue
}
$ShellApplication = New-Object -ComObject Shell.Application
$ShellFolder = $ShellApplication.Namespace($FileInformation.Directory.FullName)
$ShellFile = $ShellFolder.ParseName($FileInformation.Name)
$MetaDataProperties = [ordered] #{}
0..400 | ForEach-Object -Process {
$DataValue = $ShellFolder.GetDetailsOf($null, $_)
$PropertyValue = (Get-Culture).TextInfo.ToTitleCase($DataValue.Trim()).Replace(' ', '')
if ($PropertyValue -ne '') {
$MetaDataProperties["$_"] = $PropertyValue
}
}
foreach ($Key in $MetaDataProperties.Keys) {
$Property = $MetaDataProperties[$Key]
$Value = $ShellFolder.GetDetailsOf($ShellFile, [int] $Key)
if ($Property -in 'Attributes', 'Folder', 'Type', 'SpaceFree', 'TotalSize', 'SpaceUsed') {
continue
}
If (($null -ne $Value) -and ($Value -ne '')) {
$MetaDataObject["$Property"] = $Value
}
}
if ($FileInformation.VersionInfo) {
$SplitInfo = ([string] $FileInformation.VersionInfo).Split([char]13)
foreach ($Item in $SplitInfo) {
$Property = $Item.Split(":").Trim()
if ($Property[0] -and $Property[1] -ne '') {
$MetaDataObject["$($Property[0])"] = $Property[1]
}
}
}
$MetaDataObject["Attributes"] = $FileInformation.Attributes
$MetaDataObject['IsReadOnly'] = $FileInformation.IsReadOnly
$MetaDataObject['IsHidden'] = $FileInformation.Attributes -like '*Hidden*'
$MetaDataObject['IsSystem'] = $FileInformation.Attributes -like '*System*'
if ($Signature) {
$DigitalSignature = Get-AuthenticodeSignature -FilePath $FileInformation.Fullname
$MetaDataObject['SignatureCertificateSubject'] = $DigitalSignature.SignerCertificate.Subject
$MetaDataObject['SignatureCertificateIssuer'] = $DigitalSignature.SignerCertificate.Issuer
$MetaDataObject['SignatureCertificateSerialNumber'] = $DigitalSignature.SignerCertificate.SerialNumber
$MetaDataObject['SignatureCertificateNotBefore'] = $DigitalSignature.SignerCertificate.NotBefore
$MetaDataObject['SignatureCertificateNotAfter'] = $DigitalSignature.SignerCertificate.NotAfter
$MetaDataObject['SignatureCertificateThumbprint'] = $DigitalSignature.SignerCertificate.Thumbprint
$MetaDataObject['SignatureStatus'] = $DigitalSignature.Status
$MetaDataObject['IsOSBinary'] = $DigitalSignature.IsOSBinary
}
[PSCustomObject] $MetaDataObject
}
}
}
Reference :
Follow Below Link for the complete tutorial.
https://evotec.xyz/getting-file-metadata-with-powershell-similar-to-what-windows-explorer-provides/

Why the argument is empty or null

everyone
I'm a novice at Powershell.
My script gather Windows Event Viewer logs and export data to csv files. If the input is empty then is used the default values.
But it crashes:
"Export-Csv: Unable to validate argument for "Path" parameter. The argument is empty or NULL. Specify a non-empty, non-null argument and then run the command again."
Could explain to me why??
function exportLogs
{
[CmdletBinding()]
param (
$exportFolder=(Read-Host -prompt "exportFolder"),
$applicatiomLogs=(Read-Host -prompt "applicationLogs"),
$systemLogs=(Read-Host -prompt "systemLogs"),
$fromDate=(Read-Host -prompt "fromDate"),
$eventTypes=(Read-Host -prompt "eventTypes")
)
$comp = $env:computername
$now=Get-Date
#check empty input and assign default values
if (!$exportFolder) { [String]$exportFolder="D:\temp\" }
if (!$applicationLogs) {
$applicationLogs="True"
[System.Convert]::ToBoolean($applicationLogs)
}
if (!$systemLogs) {
$systemLogs="True"
[System.Convert]::ToBoolean($systemLogs)
}
if (!$fromDate) { [DateTime]$fromDate=$now.AddDays(-30) }
if (!$eventtypes) { [String[]]$eventtypes=("Error", "Warning") }
if ($applicationLogs)
{
$exportFile = $exportFolder + "applicationLogs_" + $now.ToString("yyyyMMddHHmmss") + ".csv"
$exportedLog = get-eventlog -ComputerName $comp -log "Application" -After $fromDate -EntryType $eventTypes
exportCsv($exportedLog, $exportFile)
}
if ($systemLogs)
{
$exportFile = $exportFolder + "systemLogs_" + $now.ToString("yyyyMMddHHmmss") + ".csv"
$exportedLog = get-eventlog -ComputerName $comp -log "System" -After $fromDate -EntryType $eventTypes
exportCsv($exportedLog, $exportFile)
}
}
function exportCsv([String]$exportedLog, [String]$exportFile)
{
$el_sorted = $exportedLog | Sort-Object TimeGenerated
Write-Host Exporting to $exportFile
$el_sorted|Select MachineName, TimeGenerated, EntryType, Source, Message | Export-CSV $exportFile -NoTypeInfo
}
Try this refactor... (run on the default Windows Sandbox on Win10)
function New-LogExport
{
Param
(
[String]$exportedLog,
[String]$exportFile
)
$el_sorted = $exportedLog |
Sort-Object TimeGenerated
Write-Host "Exporting to $exportFile"
$el_sorted |
Select-Object MachineName,
TimeGenerated,
EntryType,
Source,
Message |
Export-Csv -Path $exportFile -NoTypeInfo
}
function Start-ExportLogs
{
[CmdletBinding()]
param
(
$exportFolder = (Read-Host -prompt 'exportFolder'),
$applicatiomLogs = (Read-Host -prompt 'applicationLogs'),
$systemLogs = (Read-Host -prompt 'systemLogs'),
$fromDate = (Read-Host -prompt 'fromDate'),
$eventTypes = (Read-Host -prompt 'eventTypes')
)
$comp = $env:computername
$now = Get-Date
if (!$exportFolder)
{[String]$exportFolder = 'C:\temp'}
if (!$applicationLogs)
{
$applicationLogs = 'True'
[System.Convert]::ToBoolean($applicationLogs)
}
if (!$systemLogs)
{
$systemLogs = 'True'
[System.Convert]::ToBoolean($systemLogs)
}
if (!$fromDate)
{[DateTime]$fromDate = $now.AddDays(-30)}
if (!$eventtypes)
{[String[]]$eventtypes = ('Error', 'Warning')}
if ($applicationLogs)
{
$exportFile = "$exportFolder\applicationLogs_$($now.ToString('yyyyMMddHHmmss')).csv"
$getEventLogSplat = #{
ComputerName = $comp
LogName = 'Application'
EntryType = $eventTypes
After = $fromDate
}
$exportedLog = Get-EventLog #getEventLogSplat
New-LogExport -exportedLog $exportedLog, -exportFile $exportFile
}
if ($systemLogs)
{
$exportFile = "$exportFolder\systemLogs_$($now.ToString('yyyyMMddHHmmss')).csv"
$getEventLogSplat = #{
ComputerName = $comp
LogName = 'System'
EntryType = $eventTypes
After = $fromDate
}
$exportedLog = Get-EventLog #getEventLogSplat
}
New-LogExport -exportedLog $exportedLog -exportFile $exportFile
}
# Results
<#
exportFolder:
applicationLogs:
systemLogs:
fromDate:
eventTypes:
True
True
Exporting to C:\temp\applicationLogs_20210120143659.csv
Exporting to C:\temp\systemLogs_20210120143659.csv
#>

Server Pending Reboot

I am trying to modify my PowerShell script to find the best possible ways to check for Pending Reboots on our servers. This script checks the registry entries. However, I am seeing inconsistencies from other PowerShell scripts and wanting guidance on the best approach.
function PendingReboot ($comp) {
process {
try {
$WMI_OS = ""
$RegCon = ""
$WMI_OS = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $comp -ErrorAction Stop
if ($?){
try{
$RegCon = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]"LocalMachine",$comp)
If ($WMI_OS.BuildNumber -ge 6001){
$RegValueSetupex = ""
$RegValuePFRO2k8 = ""
$RegSubKeySM = $RegCon.OpenSubKey("SYSTEM\CurrentControlSet\Control\Session Manager\")
$RegValueSetupex = $RegSubKeySM.GetValue("SetupExecute",$null)
if ($RegValueSetupex){
$RegValueSetupex = $true
}
$RegSubKeySM = $RegCon.OpenSubKey("SYSTEM\CurrentControlSet\Control\Session Manager\")
$RegValuePFRO2k8 = $RegSubKeySM.GetValue("PendingFileRenameOperations",$null)
if ($RegValuePFRO2k8 ){
$RegValuePFRO2k8 = $true
}
$RegCon.Close()
if ( $RegValueSetupex -eq $true -or $RegValuePFRO2k8 -eq $true){
return '<font color="#FF0000">'+$true
}
else {
return $false
}
}
else{
$RegValuePFRO2k3 = $false;
$RegCon = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]"LocalMachine","$comp")
$RegSubKeySM = $RegCon.OpenSubKey("SYSTEM\CurrentControlSet\Control\Session Manager\")
$RegValuePFRO2k3 = $RegSubKeySM.GetValue("PendingFileRenameOperations",$null)
$RegCon.Close()
If ($RegValuePFRO2k3) {
return '<font color="#FF0000">'+$true;
}
else {
return $false;
}
}
}
catch {
return '<font color="#FFFF00">'+"Remote Registry Service KO"
}
}
else {
throw $error[0].Exception
}
}
catch {
return '<font color="#FF0000">'+"RPC Issue"
}
}
}
Try this.
function PendingBoot($comp) {
$pendingRebootTests = #(
#{
Name = 'RebootPending'
Test = { Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing' Name 'RebootPending' -ErrorAction Ignore }
TestType = 'ValueExists'
}
#{
Name = 'RebootRequired'
Test = { Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update' Name 'RebootRequired' -ErrorAction Ignore }
TestType = 'ValueExists'
}
#{
Name = 'PendingFileRenameOperations'
Test = { Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager' -Name 'PendingFileRenameOperations' -ErrorAction Ignore }
TestType = 'NonNullValue'
}
)
$session = New-PSSession -Computer SRV1
foreach ($test in $pendingRebootTests) {
$result = Invoke-Command -Session $session -ScriptBlock $test.Test
if ($test.TestType -eq 'ValueExists' -and $result) {
$true
} elseif ($test.TestType -eq 'NonNullValue' -and $result -and $result.($test.Name)) {
$true
} else {
$false
}
}
$session | Remove-PSSession
}

POWERSHELL on server 2019 : script not working

Here's powershell script :
copy-item "\\xxx.xlsx" -destination "c:\liste\liste.xlsx" -force
$filepath = "c:\liste\liste.xlsx"
$Excel = New-Object -ComObject excel.application
$Workbook = $excel.Workbooks.open($filepath)
$Worksheet = $Workbook.WorkSheets.item("Feuil1")
$Worksheet.activate()
$line = 4
$col = 1
$MobilePhone=''
$DECTPhone=''
$FixePhone=''
$DN=''
while ($worksheet.Cells.Item($line,1).Value())
{
if ($worksheet.Cells.Item($line,4).Value() -like "*06-??-??-??-??*" -or $worksheet.Cells.Item($line,4).Value() -like "*07-??-??-??-??*" -or $worksheet.Cells.Item($line,4).Value() -like "*???-???-????*" -or $worksheet.Cells.Item($line,4).Value() -like "*????-???-????-????*")
{
$MobilePhone = $worksheet.Cells.Item($line,4).Value()
}
if ($worksheet.Cells.Item($line,5).Value() -like "*[0-9][0-9][0-9][0-9]*")
{
$DECTPhone = $worksheet.Cells.Item($line,5).Value()
}
if ($worksheet.Cells.Item($line,6).Value() -like "*01-??-??-??-??*" -or $worksheet.Cells.Item($line,6).Value() -like "*02-??-??-??-??*" -or $worksheet.Cells.Item($line,6).Value() -like "*03-??-??-??-??*" -or $worksheet.Cells.Item($line,6).Value() -like "*04-??-??-??-??*" -or $worksheet.Cells.Item($line,6).Value() -like "*05-??-??-??-??*" -or $worksheet.Cells.Item($line,6).Value() -like "*09-??-??-??-??*" -or $worksheet.Cells.Item($line,6).Value() -like "*????-???-????-????*")
{
$FixePhone = $worksheet.Cells.Item($line,6).Value()
}
$NOM = $worksheet.Cells.Item($line,1).Value()
$PRENOM = $worksheet.Cells.Item($line,2).Value()
if ((Get-ADObject -LDAPFilter "(&(GivenName=$PRENOM)(Sn=$NOM))" | ft -HideTableHeaders DistinguishedName | Out-String).Trim())
{
$DN = (Get-ADObject -LDAPFilter "(&(GivenName=$PRENOM)(Sn=$NOM))" | ft -HideTableHeaders DistinguishedName | Out-String).Trim()
#Dans le cas ou l'utilisateur à plusieurs comptes, on place $DN dans un foreach
foreach ( $a in $($DN -split "`r`n") )
{
if ( $MobilePhone -eq '' )
{
Set-ADObject -Identity $a -Clear mobile
}
else
{
if ($MobilePhone -like "*0?-??-??-??-??*")
{
Set-ADObject -Identity $a -Replace #{mobile=$MobilePhone}
}
}
if ( $DECTPhone -eq '' )
{
Set-ADObject -Identity $a -Clear otherTelephone
}
else
{
Set-ADObject -Identity $a -Replace #{otherTelephone=$DECTPhone}
}
if ( $FixePhone -eq '' )
{
Set-ADObject -Identity $a -Clear telephoneNumber
}
else
{
if ($FixePhone -like "*0?-??-??-??-??*")
{
Set-ADObject -Identity $a -Replace #{telephoneNumber=$FixePhone}
}
}
}
}
$MobilePhone=''
$DECTPhone=''
$FixePhone=''
$DN=''
$line++
}
$workbook.Close()
$excel.Quit()
Script is working on Windows 2008 R2 but not on Windows server 2019.
Set-ADObject : Type non valide « System.Double ». Nom du paramètre : otherTelephone Au caractère Ligne:63 : 5
+ ... Set-ADObject -Identity $a -Replace #{otherTelephone=$DECT ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument : (CN=XXXX\, Xx...T,DC=XXX,DC=XXX:ADObject) [Set-ADObject], ArgumentException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:System.ArgumentException,Microsoft.ActiveDirectory.Management.Commands.SetADObject
When i initialise $NOM and $PRENOM and $DN with get-adobject, set-adobject command works without system.double error.
Thanks for help.
Found.
You shall put double quote on every set-adobject lines.
Set-ADObject -Identity $a -Replace #{otherTelephone="$DECTPhone"}
Solved.

Powershell input validition

I am trying to only allow a user to enter 2 letters when they rename a file if its exists.
It is not working as I wanted it. I am allowed to enter numbers.
if ($RenameLargeFiles.Length -gt '2') {
Write-Host " You may only enter 2 letters."
Pause
Clear-Host
Rename-LargeFiles
} else {
Rename-Item -Path $LargeFiles $RenameLargeFiles".txt"
$LargeFiles = $RenameLargeFiles
Set-Content -Value $Files -Path $LargeFiles
}
}
Set-StrictMode –Version Latest
$LargeFiles = "C:\PSScripts\LargeFiles.txt"
$PSScripts = "C:\PSScripts"
$TestPSScripts = Test-Path "C:\PSScripts"
switch ($TestPSScripts) {
'False' { New-Item -Type directory -Path $PSScripts }
}
function Test-Files {
$Files8 = ""
$Files8 = Read-Host " Please Enter the Complete Path. "
$TFiles8 = Test-Path $files8
if ($TFiles8 -eq 'True') {
Write-Host $Files8 "LOCATED."
} else {
Write-Host $Files8 "NOT FOUND"
Pause
Clear-Host
Test-Files
}
}
function Test-LargeFiles {
$LargeFiles = "C:\PSScripts\LargeFiles.txt"
$TestLargeFiles = Test-Path $LargeFiles
if ($TestLargeFiles -eq 'True') {
Write-Host $LargeFiles "already present"
Rename-LargeFiles
} else {
Write-Host $LargeFiles "NOT FOUND."
Write-Host $LargeFiles "created"
}
}
function Rename-LargeFiles {
$LargeFiles = "C:\PSScripts\LargeFiles.txt"
[string] $RenameLargeFiles = Read-Host " Please Enter 2 letters to rename" $LargeFiles
if ($RenameLargeFiles.Length -gt '2') {
Write-Host " You may only enter 2 letters."
Pause
Clear-Host
Rename-LargeFiles
} else {
Rename-Item -Path $LargeFiles $RenameLargeFiles".txt"
$LargeFiles = $RenameLargeFiles
Set-Content -Value $Files -Path $LargeFiles
}
}
Test-Files
$Files = Get-ChildItem -Recurse $Files8 | Sort-Object -Descending -Property Length | Select-Object -First 10
Test-LargeFiles
Add-Content -Value $Files -Path $LargeFiles
pause
Use a regex like so:
if ($RenameLargeFiles -notmatch '[aA-zZ]{2}') {
... display error message
}

Resources