Can't share Folder with Powershell - powershell

I'm trying to create a share on a Folder with Powersherll but it just won't work and I don't know why. I'm trying to share it with this comand:
New-SmbShare -Name "$($Username) Share" -Path "$($StandardPath)$($Username)\home\" -ChangeAccess "Labor\$($Username)"
But I always get this error:
New-SmbShare : The system cannot find the file specified.
At C:\Users\ewzadmin\Desktop\AddADUsers.ps1:55 char:9
+ New-SmbShare -Name "$($Username) Share" -Path "$($StandardPat ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (MSFT_SMBShare:ROOT/Microsoft/Windows/SMB/MSFT_SMBShare) [New-SmbShare], CimException
+ FullyQualifiedErrorId : Windows System Error 2,New-SmbShare
I don't understand why he is trying to share a File when I want to share a Folder...

Okay I did find the Problem in my Script. It was that I was already using a \\192.168.1.32\users\$username\ path to create the folder. But because I didn't have a share the folder was never created...
Im so dump

Related

Issue with New-DFSNFolderTarget cmdlet

I'm trying to automate repointing DFS folders. This is my current script:
$ft=get-dfsnfolder "\\test.dfs.domain\testpath\zzTop\*" | get-dfsnfoldertarget
$ft|% {
if ($_.targetpath -like "*blah*") {
new-dfsnfoldertarget -Path $_.path -State online -TargetPath ($_.targetpath).replace("\\blah.test.domain\testpath\zzTop","\\new.test.domain\testpath\zzTop")
}
}
I'm receiving a very weird error that is completely non-specific and makes this basically impossible to debug below:
new-dfsnfoldertarget : Can't add DFS namespace folder target "\\blah.test.domain\testpath\zzTop\2two"
At C:\Users\my_username\Desktop\ChangeDFSTargetTEST.ps1:2 char:46
+ ... *blah*") {new-dfsnfoldertarget -Path $_.path -State online -TargetP ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (MSFT_DfsNamespaceFolderTarget:ROOT\Microsoft\...aceFolderTarget) [New-DfsnFolderTarget], CimException
+ FullyQualifiedErrorId : Windows System Error 80,New-DfsnFolderTarget
new-dfsnfoldertarget : A general error occurred that is not covered by a more specific error code.
At C:\Users\my_username\Desktop\ChangeDFSTargetTEST.ps1:2 char:46
+ ... *blah*") {new-dfsnfoldertarget -Path $_.path -State online -TargetP ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (MSFT_DfsNamespaceFolderTarget:ROOT\Microsoft\...aceFolderTarget) [New-DfsnFolderTarget], CimException
+ FullyQualifiedErrorId : MI RESULT 80,New-DfsnFolderTarget
I'm running this script as admin on the box that is hosting and managing the DFS, so no issues with remote connections. I also have a script to offline these paths which works fine and also uses the "$_.targetpath -like "blah".
Also, if I run the command:
new-dfsnfoldertarget -Path $_.path -State online -TargetPath ($_.targetpath).replace("\\blah.test.domain\testpath\zzTop","\\new.test.domain\testpath\zzTop")
Replacing the variables with the strings that are fed into it automatically (so running it manually), it works fine. This is from a Server 2019 Standard box with PSVersion 5.1.17763.1490.
Any insight would be appreciated.
This won't be terribly relevant, but I realized I had set up DFS using an admin share path which is locked down almost completely so the testing I was doing was useless.
This script works fine if your DFS is healthy.

Unable to Download Large File From SharePoint Using PowerShell

I'm unable to download certain files from SharePoint. I think it's because of size but not sure. I was able to download a 500M file. I'm on Windows 7. I upgraded PS to 5.1 and installed the SharePointPnPPowerShellOnline module. My SharePoint authentication is based on multi-factor authentication.
Ultimately, I'm looking to create an script and automate it that gets a list of files and their attributes and based on some condition download specific ones. Some will be 5Gig+.
At PS Prompt:
Connect-PnPOnline –Url https://server.sharepoint.com/personal/user –UseWebLogin
Get-PnPFile -Url "Documents/5gig_file.csv" -AsFile
I was able to download other files. When trying this larger file I get error:
At line:1 char:1
+ Get-PnPFile -Url "Documents/5gig_file.csv" -AsFile
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [Get-PnPFile], FormatException
+ FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Files.GetFile
Edit - After more searching around I think this may be related to "MemoryStream" limit having to do with Powershell and not anything to do with SharePoint. https://github.com/PowerShell/PowerShell/issues/4129.

Using a space and slash with New-Item

So I have to add this registry entry using PowerShell and sadly it has a space and a / in it. I'd like to know what the syntax is for adding this kind of entry or a new method because I'm unable to find a good answer. To be clear this needs to create a key called RC4 128/128 under the ciphers folder.
New-Item -Path "HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Ciphers" -Name RC4 128/128
This is the error I got below:
New-Item : A positional parameter cannot be found that accepts argument '128/128'.
At line:1 char:1
+ New-Item -Path "HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProvid ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-Item], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.NewItemCommand
It's not a Powershell issue, but it's an issue with the way the New-Item cmdlet is written.
Here's how you do it though:
([Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, $env:COMPUTERNAME)).CreateSubKey('SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Ciphers\RC4 128/128')
Credit: u/bhudlemeyer from reddit
It's very strange that they require you to create a key path with a space and slash because even regedit doesn't allow that.

Can't remove some powershell commands

I thought I'd go this sorted out in this other question but I dont seem to be able to disable the Reset-BC command.
Normally I would use
Remove-Item -force alias:Reset-BC
However I just get the following error
Remove-Item : Cannot find path 'Alias:\Reset-BC' because it does not exist.
At line:1 char:1
+ Remove-Item -force alias:\Reset-BC
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Alias:\Reset-BC:String) [Remove-Item], ItemNot
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand
Could anyone explain this or tell me how to get rid of it?
Definitely the thing that annoys me about powershell the most - it just litters your path with loads of rubbish. On occasion it also actually hides proper applications like where and sc with its stuff aswell which is even worse. I would use cmd but the lack of autocomplete is painful :(
You can test existance of Cmdlet:
If(get-item alias:Reset-BC) {Remove-Item -force alias:Reset-BC} else {'not exist'}

Cannot Copy a file from a network share in powershell until I open the share in windows explorer

I have a very simple powershell script which to copy files from a networked server.
here's the script
Write-Output "Copying Backups"
copy \\sqlbox\SqlBackups\Client.bak c:\sqlbackups
It throws this exception
Invalid Path: '\\sqlbox\SqlBackups\Client.bak'.
At C:\Work\db\restore.ps1:5 char:1
+ copy \\sqlbox\SqlBackups\Client.bak c:\sqlbackups
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], ArgumentException
+ FullyQualifiedErrorId : CopyItemDynamicParametersProviderException
If I open a windows explorer up and goto \sqlbox\SqlBackups it opens fine and if I then run the powershel script it also starts working and will work until the next time I reboot the PC.
How can I address this in the script?
Try mapping the drive first, then carry out the copy operation.
New-PSDrive -Name S -Root \\sqlbox\SqlBackups\ -PSProvider FileSystem
Write-Output "Copying Backups"
copy S:\Client.bak c:\sqlbackups
I have a similar problem when copying files over servers with this error:
Cannot find path '\\computer1\d$\path' because it does not exist.
It works after adding Microsoft.PowerShell.Core\FileSystem:: in front of file name:
copy-item "Microsoft.PowerShell.Core\FileSystem::\\computer1\d$\path\installer.msi" "Microsoft.PowerShell.Core\FileSystem::\\computer2\d$\path\installer.msi"