Merge 3 partial files with PowerShell Copy - powershell

I have 3 partial files that I need to merge to just 1 zip.
When using this PowerShell script:
copy /b v9_setup.1 + v9_setup.2 + v9_setup.3 v9_setup.zip
I get this error:
Copy-Item : A positional parameter cannot be found that accepts argument
'v9_setup.2'.
At line:1 char:1
+ copy /b v9_setup.1 v9_setup.2 v9_setup.3 v9_setup.zip
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Copy-Item], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.CopyItemCommand
I am using Windows 10 Pro.

As LotPings and user1287678 says, running the script in cmd.exe works. Thanks.

Related

Installing CCM client on PC via powershell

I'm trying to speed up how soon SCCM recognises a device on the domain and starts the process of installing applications.
I have the below in powershell
$CCMInstallerPath = "\\ServerFQDN\SMS_MAN\Client\ccmsetup.exe"
$args = "/mp:MPServer", "/LOGON", "/UsePKICert", "SMSSLP=SMSSLPServer", "SMSSITECODE=MAN"
& $CCMInstallerPath $args
I get the below error:
Program 'ccmsetup.exe' failed to run: Access is deniedAt line:1 char:5
+ & $CCMInstallerPath $args
+ ~~~~~~~~~~~~~~~~~~~~~~~~~.
At line:1 char:5
+ & $CCMInstallerPath $args
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (:) [], ApplicationFailedException
+ FullyQualifiedErrorId : NativeCommandFailed
I have read and execute access to this file, both by group and directly by name
I have also tried:
Start-Process -FilePath \\ServerFQDN\SMS_MAN\Client\ccmsetup.exe -ArgumentList "/mp:MPServer", "/logon SMSSITECODE-MAN", "/UsePKICert"
and get the error
Start-Process : This command cannot be run due to the error: Access is denied.
At line:1 char:5
+ Start-Process -FilePath \\ServerFQDN\SMS_MAN\Client\c ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
ServerFQDN is a replacement for one of our NM servers
I can fully connect to the folder and run the exe manually
I am running elevated powershell
Issue was caused by incorrect share permissions found in effective access.
Permission was granted to run the file but effective access was showing differences

Remove Git Hub related files

I am learning Git Hub. So I am a newbie.
Trying to remove git related files in project directory. I used this line:
rd .git /S/Q
However it gives me this error when I use VS Code:
Remove-Item : A positional parameter cannot be found that accepts argument '/q'.
At line:1 char:1
+ rd /s /q .git
+ ~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Remove-Item], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand
and when I use CMD - command promt it gives me this error:
.git\refs\remotes - The directory is not empty.
What is going on.
This is where I get my information about this:
From stackoverflow
From YouTube
I am using Windows 10 btw.
EDIT:
I tried:
rd /S /Q .git
and I get error:
Remove-Item : A positional parameter cannot be found that accepts argument '/Q'.
At line:1 char:1
+ rd /S /Q .git
+ ~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Remove-Item], ParameterBindingException
Tried:
rd /S/Q .git
Error:
Remove-Item : A positional parameter cannot be found that accepts argument '.git'.
At line:1 char:1
+ rd /S/Q .git
+ ~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Remove-Item], ParameterBindingException
However I tried in command promt:
rd /S /Q .git
And I get :
.git\refs\remotes - The directory is not empty.
I try it second time right after that and it works...
So what am I missing here?
EDIT 2:
All of these comands work in command promt but only if I type them for the second time. Including the command - rd .git /S/Q.
The first time I get :
.git\refs\remotes - The directory is not empty.
and if I type it for the second time it works.
In VS Code it is not working no matter how many times I type them.

Running MongoDB, not recognizing mongod.exe or mongo.exe

I have been running MongoDB fine on my system, ran it 2 days ago. Now I am not able to access my file folders at all. When I type DIR, I see the files but when I try to access them through command line I get ObjectNotFound.
PS C:\Program Files\MongoDB\Server\4.2\bin> cd ./mongo.exe
cd : Cannot find path './mongo.exe' because it does not exist.
At line:1 char:1
+ cd ./mongo.exe
+ ~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (./mongo.exe:String) [Set-
Location], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand

Unable to Use Windows Update COM object in RemotePS sessions

Im trying to change the windows update settings in a remote server using powershell, but when i run the below commands it gives me an error.
PS C:\Windows\system32> Enter-PSSession opalisbinary
[opalisbinary]: PS C:\Users\superv\Documents> $AUSettings = (New-Object -com "Microsoft.Update.AutoUpdate").Settings
[opalisbinary]: PS C:\Users\superv\Documents> $AUSettings.NotificationLevel=2
Property 'NotificationLevel' cannot be found on this object; make sure it exists and is settable.
At line:1 char:14
+ $AUSettings. <<<< NotificationLevel=2
+ CategoryInfo : InvalidOperation: (NotificationLevel:String) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
[opalisbinary]: PS C:\Users\superv\Documents> $AUSettings.IncludeRecommendedUpdates=$true
Property 'IncludeRecommendedUpdates' cannot be found on this object; make sure it exists and is settable.
At line:1 char:14
+ $AUSettings. <<<< IncludeRecommendedUpdates=$true
+ CategoryInfo : InvalidOperation: (IncludeRecommendedUpdates:String) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
[opalisbinary]: PS C:\Users\superv\Documents> $AUSettings.Save()
You cannot call a method on a null-valued expression.
At line:1 char:18
+ $AUSettings.Save <<<< ()
+ CategoryInfo : InvalidOperation: (Save:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Although when i run it locally on the server it works fine...
Could anyone please help me.
Does it work when you connect via Remote desktop and run the commands? It also depends on the bittnes. I don't know the Microsoft.Update.AutoUpdate, so I'm just guessing, but - is it available for x64 version of PowerShell? In other words if you run it locally in x64 version and x86, do you see the errors?
I am sorry, I could not find a real answer. What I found is this link which states that remote PS sessions can be used with SCCM 2012, but they could not with SCCM 2007.
This does not help you, but it seems that not all COM objects are compatible with remote PS sessions.

Executing an EXE in your $PATH, which starts with a numeric value, in Powershell?

So 7z.exe is in my $PATH environment variable.
PS C:\Users\jimmeh> 7z.exe
Bad numeric constant: 7.
At line:1 char:2
+ 7 <<<< z.exe
+ CategoryInfo : ParserError: (7:String) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : BadNumericConstant
Besides renaming the EXE, is there a way to do this, or is it a bug in Powershell?
It work like
& '.\7z.exe'
if you want to specify an archive to extract
& '.\7z.exe' e your.zip
This is no longer a problem with Powershell 4.0
http://www.microsoft.com/en-us/download/details.aspx?id=40855