find Nodes in Windows Cluster
below is the snippet for that
Get the node names from the cluster
$ClusterName=’ClusterName’
Get-WmiObject -Namespace root/mscluster -Class MSCluster_Node -ComputerName $ClusterName -EnableAllPrivileges -Authentication 6
Regards,
Chaitanya
search large files in the folders or network locations
Hi All,
If you want to search large files in the folders or network locations, below is the PowerShell code.
workflow DirectoryCheck {
param([string[]]$FileShares,[int] $days ,[int] $sizeinMB)
$t=(get-date).adddays(-$days)
foreach –parallel -throttlelimit $fileshare.count ($Fileshare in $FileShares)
{
$DirArr = @()
$DirArr = Get-ChildItem -Path $Fileshare -Recurse -Directory | ? {$_.lastwritetime -ge $t }
foreach –parallel -throttlelimit 50 ($dir in $DirArr)
{
Get-ChildItem -Path $dir.FullName -File | ?{ $_.Length/1MB -ge $sizeinMB}| sort Length -desc | select Name,fullname, length, lastwritetime -First 100 -ExcludeProperty PSSourceJobInstanceId,PSComputerName
}
}
}
directorycheck -FileShares "C:\work\","D:\work" -days 800 -sizeinMB 1 |Out-GridView
get-childitem works really slowly if you have network locations to check. Below is the more information on that
https://blogs.msdn.microsoft.com/powershell/2009/11/04/why-is-get-childitem-so-slow/
I will post one more optimized script in upcoming posts.
Regards,
Chaitanya
get the System time zones in your local system
get the System time zones in your local system using powershell,below is command for that
[System.TimeZoneInfo]::GetSystemTimeZones()
Regards,
Chaitanya
Upload files to Azure Blobs using PowerShell
Below is the sample script for that.
$StorageAccountName = "storageaccountname"
$StorageAccountKey = "storageaccountkey"
$ctx = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey # get the context
$ContainerName = "yourcontainer"
New-AzureStorageContainer -Name $ContainerName -Context $ctx -Permission Blob
$localFileDirectory = "C:\work\UploadFilestoBlob\FileDrop\"
$BlobName1 = "yourblob.txt"
$localFile1 = $localFileDirectory + $BlobName1
Set-AzureStorageBlobContent -File $localFile1 -Container $ContainerName1 -Blob $BlobName1 -Context $ctx -Force
Regards,
Chaitanya
Check the Installed PowerShell version
below is the snippet for that
$PSVersionTable.PSVersion
If you want to check this on remote servers, use invoke-command which connects using WinRM service.
Invoke-command -computername server1,server2 -scriptblock ( $PSVersionTable.PSVersion)
Regards,
Chaitanya
Compare files in folders Using PowerShell
below is the snippet for that
get-childitem -File -Recurse -Path C:\work | Group-Object -Property { ($_ | Get-FileHash).Hash } | Where-Object Count -gt 1
Regards,
Chaitanya
Check Service Status Parallelly across multiple servers using PowerShell
Hi All,
If you want to check the services across multiple remote servers , below script will be useful. It uses PowerShell work flow and works in multi-threaded way.
workflow parallelServiceCheck {
param(
[String[]]$ComputerName,
[string]$Status,
[String]$serviceName
)
$obj =New-Object –TypeName PSObject
$Services=$null
if (!([String]::IsNullOrEmpty($serviceName)))
{
$Services = Get-Service -Name $($serviceName) | where { $_.Status -eq $Status }
}
else
{
$Services = Get-Service| where { $_.Status -eq $Status }
}
Add-Member -InputObject $obj -MemberType NoteProperty -Name Services -Value $Services -Force
$obj| select servername, services|select -ExpandProperty services|select Name,Status
}
Clear-Host
parallelServiceCheck -PSComputerName Server1,Server2 `
-Status ‘running’ ` # status is mandatory
-Servicename ” `
|select PSComputerName,Name,Status | Out-GridView
Regards,
Chaitanya
How to find Existing File types in the Folder path
below is the snippet for that
get-childitem -Path c:\work -Recurse |select -Unique Extension
Regards,
Chaitanya
Open Website using PowerShell
below are the ways to do that.
Start-Process -filepath "https://sqlblogging.com/"
[System.Diagnostics.Process]::Start("https://sqlblogging.com/")
(New-Object -Com Shell.Application).Open("https://sqlblogging.com/")
Regards,
Chaitanya
finding shared folders on remote servers Using PowerShell
Use the below snippet code to check the shared folders on remote servers
#Check the shared folders on remote servers.
invoke-command -computername Server1,Server2 -ScriptBlock{ Get-SmbShare}
Regards,
Chaitanya