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
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
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
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
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
To add the attribute to the XML, we first need to add the Element and then we will add an attribute for it.Below is a sample of the XML file.Example Gambardella, Matthew XML Developer's Guide Computer 44.95 2000-10-01 An in-depth look at creating applications with XML. The below command will add the new element but the file won’t be saved. We will save the file after the attribute is added.$file = "C:\Temp\SampleXML.xml" $xmlfile = [xml](Get-Content $file) $newbookelement ... Read More
In web urls if we provide space in the url, the browser automatically replaces all the spaces with the string '%20'We are required to write a JavaScript function that takes in a string as the first and the only argument. The function should then construct and return a new string in which a whitespace, wherever it was in place, replaced by '%20'For example −If the input string is −const str = 'some extra Space';Then the output should be −const output = 'some%20extra%20%20Space';ExampleThe code for this will be − Live Democonst str = 'some extra Space'; const replaceWhitespace = (str = '') ... Read More
We are required to write a JavaScript function that takes in a string that might contain some continuous repeating characters.The function should compress the string like this −'wwwaabbbb' -> 'w3a2b4' 'kkkkj' -> 'k4j'And if the length of the compressed string is greater than or equal to the original string we should return the original string.For example −'aab' can be compressed to 'a2b1' but it increases its length to 4 so our function should return 'aab'ExampleThe code for this will be − Live Democonst str1 = 'wwwaabbbb'; const str2 = 'kkkkj'; const str3 = 'aab'; const compressString = (str = '') => ... Read More
We are required to write a JavaScript function that takes in an array of numbers, arr, as the first argument and a single number, num, as the second argument.The function should then find two such numbers whose sum is greatest in the array but just less than the number num. If there exists no two such numbers whose sum is less than num, our function should return -1.For example −If the input array and the number are −const arr = [34, 75, 33, 23, 1, 24, 54, 8]; const num = 60;Then the output should be −const output = 58;because ... Read More
We are required to write a JavaScript function that takes in an array of integers as the first and the only argument.The function should construct and return a new array that contains all such elements from the original array whose successor and predecessor are both present in the array. If means, if any element num is in the original array, it should be included in the result array if and only if num - 1 and num + 1 are also present in the array.For example −If the input array is −const arr = [4, 6, 8, 1, 9, 7, ... Read More