
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 462 Articles for PowerShell

3K+ Views
To add the tag to the Azure VM we need to use the Update-AZTag command. This command will merge the new tag to the existing tag(s) of the VM. If you are planning to add the entirely new VM tag, you can use the New-AZTag command. Once you use the New-AZTag command, other tags will be deleted for that particular VM and the New tag will be created so pls be careful with that command.We have the VM called TestMachine2k12 on Azure and there are few existing tags applied to the VM as shown below.ExampleGet-AzVM -Name TestMachine2k12 | Select -ExpandProperty ... Read More

2K+ Views
There are two ways to get the applied azure VM tags using PowerShell.Using Tags Property of the Azure VMUsing the Get-AZTag command.ExamplePS C:\> Get-AzVM -VMName Testmachine2k12 | Select -ExpandProperty Tags Key Value --- ----- Patching_Day Sunday Owner ChiragAnother way is by using the Get-AZTag command.PS C:\> $vm = Get-AzVM -VMName TestMachine2k12 PS C:\> Get-AzTag -ResourceId $vm.Id | Select -ExpandProperty PropertiesOutputTagsProperty ------------ {[Owner, Chirag], [Patching_Day, Sunday]}We need to export this tag and the best way to store the tags is using the JSON file.Get-AzVM -VMName Testmachine2k12 | Select -ExpandProperty Tags ... Read More

614 Views
To add the new tag of Azure VM using PowerShell, we need to use the New-AZTag command. Please note: If you have already tags applied to the VM, you need to use the Update-AZTag command to merge with the available Azure Tags otherwise all the previous applied.For example, We have the below VM called TestMachine2k12 and after signing to the Azure account we need VMs resource ID to apply the tag to the VM.We will use a tag in the HastTable format so we will have its Key and a Value. We need to apply the below new tag.Example$tag = ... Read More

4K+ Views
We will first retrieve the content of the folder using the Get-ChildItem command and then pipeline the Measure-Object command as shown below.Get-ChildItem C:\Temp\ -Recurse | Measure-Object -Property Length -SumOutputCount : 1514 Average : Sum : 372060503 Maximum : Minimum : Property : LengthSo the above output shows that there is a total of 1514 files and folders and the sum shows the size of all the files and folders combined in KB. We can convert it to the MB as shown below.(Get-ChildItem C:\Temp\ -Recurse | Measure-Object -Property Length -Sum).Sum / 1MB 354.824545860291We can get the round figure, [Math]::Round( ... Read More

23K+ Views
To run the PowerShell script from the command prompt, we can use the below command.ExampleFor example, we have a script TestPS.ps1 which first starts the spooler service and then copies a file to a different location. We need to call this script using the command prompt.C:\> PowerShell.exe -command "C:\temp\TestPS.ps1"The above command is similar to running individual PowerShell commands. Here we are providing the path of the script.OutputC:\>PowerShell.exe -command "C:\temp\TestPS.ps1" VERBOSE: Performing the operation "Start-Service" on target "Print Spooler (Spooler)". Status Name DisplayName ------ ----- ---------- Running Spooler Print Spooler VERBOSE: Performing the operation "Copy File" on target "Item: C:\Temp\EnvVariable.txt Destination: ... Read More

10K+ Views
To run Powershell commands from the command prompt or cmd, we need to call the PowerShell process PowerShell.exe.ExampleSee the sample example, C:\> Powershell.exe -Command "Write-Output 'Hello world'" Hello worldSimilarly, you can call any command. We will use another example to get service informationC:\> Powershell.exe -Command "Get-Service Spooler" Status Name DisplayName ------ ---- ----------- Running Spooler Print SpoolerTo run multiple commands, C:\> Powershell.exe -Command "Stop-Service Spooler -verbose -passthru; Start-Service Spooler -verbose -passthru"OutputVERBOSE: Performing the operation "Stop-Service" on target "Print Spooler (Spooler)". Status Name DisplayName ------ ---- ----------- Stopped Spooler Print Spooler VERBOSE: Performing the operation "Start-Service" on ... Read More

6K+ Views
If we want to delete the hidden files and folders from the C:\temp on the local computer, we need to use the command shown in this example.ExampleBut first, the below command helps us to retrieve the hidden files and folders from the C:\temp.Get-ChildItem C:\Temp -Hidden -RecurseWe just need to pipe the Remove-Item command and to remove forcibly use -Force parameter.Get-ChildItem C:\Temp -Hidden -Recurse | Remove-Item -Force -VerboseOutput

3K+ Views
To delete empty files and folders, we need to first retrieve the list and which has been shown in the earlier articles.ExampleIn this article, we are using the logic that if we find an empty file or folder we will delete them. To implement that logic, use the below script.gci C:\Temp -Recurse | foreach { if($_.Length -eq 0){ Write-Output "Removing Empty File $($_.FullName)" $_.FullName | Remove-Item -Force } if( $_.psiscontainer -eq $true){ if((gci ... Read More

2K+ Views
To get the list of empty folder on the windows OS using PowerShell, we can use the below method.gci C:\Temp -Recurse | foreach { if( $_.psiscontainer -eq $true){ if((gci $_.FullName) -eq $null){$_.FullName} } }The above command checks the C:\Temp folder and its subfolders and if the content is empty it returns the Folder full path. The PSISContainer property stands for the folder and GCI is the alias of the Get-ChildItem command. We can alternatively use the below command, instead of using the PSISContainer property.gci C:\Temp -Recurse -Directory | foreach { if((gci $_.FullName) -eq $null){$_.FullName} }

1K+ Views
To get the list of empty files in Windows OS using PowerShell, there are two ways, a) Using Length parameter. We will count the length of the file. If it is 0 then the file is empty as shown below.Get-ChildItem C:\Temp\ -Recurse | where{$_.Length -eq 0} | Select @{N='EmptyFiles';E={$_.FullName}}Output:b) Another method is a long one that we don’t want to go into. We need to check each file's content and if it is empty then we will declare that file as an empty file.Get-ChildItem C:\Temp -Recurse -File | foreach{ if((Get-Content $_.FullName) -eq $null){ ... Read More