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
Microsoft Technologies Articles - Page 168 of 204
3K+ 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
1K+ Views
Sometimes changes in the Windows environment variable can be deadly because it saves information about user profiles, application information, and OS information. It is always better to keep the Environment backup handy and update that file whenever there are any changes or at the regular interval.Taking up the environment variables backup is easy. To retrieve the environment variable list we can use the below command, Get-ChildItem env:To store the environment variable, we can use the Out-File command with text file but if the particular environment variable length is larger enough then we can’t store it in the text file properly.Instead, ... Read More
1K+ Views
The ConvertFrom-String command converts the String to the Hashtable format as shown below.ExamplePS C:\> "This is string" | ConvertFrom-StringOutputP1 P2 P3 -- -- -- This is stringIn the above example, We haven’t specified any header so that the output is separated the delimiter by space P1, P2 and continuous. By default, this command separates the string with a ‘=’ delimiter as shown below.Example$stringhash = @" Name = Spooler Starttype = Manual Status = Stopped "@ $stringhash | ConvertFrom-StringDataOutputName Value ---- ----- ... Read More
4K+ Views
ExampleFor example, we have a below-created hashtable.PS C:\> $servicehash = @{Name='Spooler';State='Stopped';StartType='Automatic'} PS C:\> $servicehashOutputName Value ---- ----- Name Spooler StartType Automatic State StoppedWe need to add multiple values to the Name Key. If we directly append the value to the key it will treat it as a string and we will not get the desired output. See the example below.ExamplePS C:\> $servicehash.Name += "Winrm" PS C:\> $servicehashOutputName Value ---- ----- Name SpoolerWinrm StartType Automatic State StoppedSo to add the multiple ... Read More
19K+ Views
To uninstall the PowerShell module, we can directly use the Uninstall-Module command but the module should not be in use, otherwise, it will throw an error.When we use the Uninstall-Module command, it can uninstall the module from the current user profile or from the all users profile.Uninstall-Module 7Zip4PowerShell -Force -VerboseAnother method, Get-InstalledModule 7Zip4Powershell | Uninstall-Module -Force -VerboseIf you have multiple versions of the same module installed in the PowerShell, and if you want to uninstall all of them then use the -AllVersions Parameter.Uninstall-Module 7Zip4PowerShell -AllVersions -Force -VerboseIf you want to uninstall the specific version, we can use -RequiredVersion.Uninstall-Module 7Zip4PowerShell -RequiredVersion ... Read More
2K+ Views
Although simply running Install-Module command picks up the latest version of the module, we can still use the -RequiredVersion and -MinimumVersion parameter to install the latest version manually. Below command directly installs the latest available version of the module.In this example we are using 7Zip4PowerShell module.Install-Module 7Zip4PowerShell -Scope AllUsers -Force -VerboseTo manually install the latest version of the PowerShell module, there are two methods.Use the -RequiredVersion parameter if you know the latest version of the module.Use the -MinimumVersion parameter if you know the minor version of the module and it will pick up the latest version.Using -RequiredVersion ParameterThis parameter installs ... Read More
7K+ Views
To install the specific version of the PowerShell module, we need to use the -RequiredVersion parameter with the Install-Module command.To find which module versions are available, we can use the Find-Module command with the -AllVersions parameter which retrieves all the versions of the module available in the PSGallery.In this example, we will use the 7Zip4PowerShell module.ExampleFind-Module 7zip4PowerShell -AllVersions | ft -AutoSizeWhen you run this command, you can see there are multiple versions available for this module.OutputVersion Name Repository ------- ---- ---------- 1.13.0 7Zip4Powershell PSGallery 1.12.0 7Zip4Powershell PSGallery 1.11.0 ... Read More
4K+ Views
Let say you want to update the host file particular entry, we have the below host file in our local computer.ExampleGet-Content $env:windir\system32\drivers\etc\hostsOutput# For example: # # 102.54.94.97 rhino.acme.com # source server # 38.25.63.10 x.acme.com # x client host # localhost name resolution is handled within DNS itself. # 127.0.0.1 localhost # ::1 localhost 8.8.8.8 Google.comWe need to update the google.com entry to IP address ... Read More
9K+ Views
To add the content to the host file, we need to first retrieve the content using the Get-Content command and the need to set the content to the host file after adding the entry. The Code is shown below. We need to add the global entry to it.Example$file = "C:\Windows\System32\drivers\etc\hosts" $hostfile = Get-Content $file $hostfile += "8.8.8.8 Google.com" Set-Content -Path $file -Value $hostfile -ForceOnce you check the host file entry "8.8.8.8 Google.com" will be added to the host file.To add the entry on the remote computer, you just need to point that file location to the host file of the remote server and the rest of ... Read More