Found 989 Articles for Software & Coding

How to copy only updated or newer files with PowerShell?

Chirag Nagrekar
Updated on 18-Mar-2021 07:31:41

8K+ Views

To copy only updated or newer files with PowerShell, we can use Copy-Item with some logic in the script that to check if the files exist on the destination folder if not then copy that file and if yes then compare the timestamp and copy the latest file. This would be tricky because we need to write several lines of code for it.But Windows support xCopy utility which can directly copy the newer or updated files and this utility we can accommodate in PowerShell as well.xCopy uses a switch called /d. its actual syntax is, Syntax/d [:MM-DD-YYYY]This means if the date ... Read More

Difference Between Algorithm and Pseudocode

Kiran Kumar Panigrahi
Updated on 22-Oct-2023 13:27:01

28K+ Views

Algorithm and Pseudocode are the two related terms in computer programming. The basic difference between algorithm and pseudocode is that an algorithm is a step-by-step procedure developed to solve a problem, while a pseudocode is a technique of developing an algorithm. In this article, we will discuss the other important differences between an algorithm and a pseudocode. Let's start with some basic concepts of algorithm and pseudocode. What is an Algorithm? A sequence of steps to solve a given problem is called as algorithm. Thus, an algorithm is a step-by-step procedure developed for solving a given problem. An ... Read More

How to check Azure VM Power state using PowerShell?

Chirag Nagrekar
Updated on 01-Mar-2021 10:51:55

7K+ Views

To check if the VMs are running, deallocated, or stopped using PowerShell, we need to use the - Status parameter.If you write only the Get-AzVM command to get the VM details, it won’t show up the Azure VM power status default.ExampleTo check the Azure VM Power Status, Get-AzVM -statusOutput The above command will show the Power State for all VMs for that particular subscription. For different subscriptions, you need to change the subscription and run this command.To get the VM Power State for the specific ResourceGroup, use the ResourceGroup name parameter.ExampleFor example, Get-AzVM -ResourceGroupName TestVMRG -StatusThe above command will retrieve all ... Read More

How to get the list of shared folders using PowerShell?

Chirag Nagrekar
Updated on 01-Mar-2021 10:49:21

6K+ Views

Get-SmbShare gives all the shared folders on the local system.PS C:\Temp> Get-SmbShare Name    ScopeName    Path       Description ----    ---------    ----       ----------- ADMIN$    *       C:\Windows    Remote Admin C$        *       C:\ Default    share DSC       *       E:\DSC E$        *       E:\           Default share IPC$      *                      Remote IPC Shared1   *       E:\ExtractExampleTo ... Read More

How to get the Shared folder permissions with PowerShell?

Chirag Nagrekar
Updated on 01-Mar-2021 10:47:51

19K+ Views

To get the shared folder permissions using PowerShell, we can use the Get-SmbShare cmdlet.For example, we have a shared folder name DSC and we need to retrieve its permissions, we can use the below command.CommandGet-SmbShare -Name DSCOutputName ScopeName Path Description ---- --------- ---- ----------- DSC       *   E:\DSCIt doesn’t show the permission by default and we can retrieve the full list using Fl *. For example, Get-SmbShare -Name DSC | fl *And you can see the PresentPathACL property there. This property is used to retrieve the permissions on the shared folder. So we can directly use the command, Command(Get-SmbShare -Name ... Read More

How to change SMB shared folder access permission using PowerShell?

Chirag Nagrekar
Updated on 01-Mar-2021 10:46:23

6K+ Views

We can use the command Grant-SmbShareAccess to change the shared folder access permission or to assign the new user to the shared folder with permission.In this example, we have already shared a folder name called “Shared Folder” and everyone's user permission is assigned with the read access and we will change it to the Full access permission.PS C:\Temp> Get-SmbShareAccess -Name "Shared folder" Name          ScopeName AccountName AccessControlType AccessRight ----          --------- ----------- ----------------- ----------- Shared folder    *       Everyone          Allow         ReadExampleTo change the permission ... Read More

How to remove windows folder sharing using PowerShell?

Chirag Nagrekar
Updated on 01-Mar-2021 10:09:16

2K+ Views

To remove the windows folder sharing using PowerShell, we can use the Remove-Smbshare command. For example, PS C:\Temp> Remove-SmbShare -Name DSC Confirm Are you sure you want to perform this action? Performing operation 'Remove-Share' on Target '*, DSC'. [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"):Once you use this command, it will ask for confirmation. To remove the sharing forcefully, use - Force parameter. For example, Remove-SmbShare -Name DSC -ForceTo remove the shared folder permissions on the remote computer, you need to use the CIM session.In the below example, ... Read More

How to share a windows folder using PowerShell?

Chirag Nagrekar
Updated on 01-Mar-2021 10:45:13

10K+ Views

To share a windows folder using PowerShell, we can use the New-SmbShare command. This command is a part of the module SmbShare.In this example, we have a folder called “DSC” and we want to share. The below command will simply share folderNew-SmbShare -Path E:\DSC\ -Name "Shared Folder"OutputName          ScopeName Path Description ----          --------- ---- ----------- Shared Folder    *      E:\DSCDSC folder will be shared with a “Shared Folder” name with everyone’s Read Permission by default because we haven’t specified the scope yet.To assign the Full Access permission to the specific user, ... Read More

How to update the specific node of the XML file using PowerShell?

Chirag Nagrekar
Updated on 01-Mar-2021 12:09:27

7K+ Views

To update the specific XML node using PowerShell, we first need to select that node with the attribute with SelectSingleNode() method.We have below the XML file from the link stored in SampleXml.XML on C:\Temp location.https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ms762271(v=vs.85)In this example, we are going to update Autor and Genre properties of the Book having attribute Id = ‘bk102’$xml=[xml](Get-Content C:\Temp\SampleXML.xml)$node=$xml.SelectSingleNode("//book[@id='bk102']")The above commands will load the XML file and select node with attribute value ‘bk102’.$node.genre='Non-Fiction' $node.author='Dell James' $xml.Save("C:\Temp\SampleXML.xml")The above commands will update the genre and author property.Read More

How to delete the specific node from the XML file using PowerShell?

Chirag Nagrekar
Updated on 01-Mar-2021 09:59:35

8K+ Views

To delete the specific XML node from the PowerShell, we can use the RemoveChild() method of the XML.For example, We have a sample XML file from Microsoft.https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ms762271(v=vs.85)We have saved the above file into C:\Temp\SampleXml.XML and we need to delete the book node with attribute ‘bk102’ and for that, we will use the XPath method of the XML.Below commands will first search the XML book node with the book attribute ‘bk102’ and then we will delete it.$xml = [xml](Get-Content C:\Temp\SampleXML.xml) $node = $xml.SelectSingleNode("//book[@id='bk102']") $node.ParentNode.RemoveChild($node) | Out-Null $xml.Save('C:\Temp\SampleXML.xml')If you want to delete all the nodes which have the name “Book”, we can ... Read More

Advertisements