If i run this code it will run the file
{Write-host "Please Enter the email address of the user you want to check the permissions"
$user = Read-Host
Powershell.exe C:\Temp\Report\Reports.ps1}
But if i run it like this which is what i need to do
{ Write-host "Please Enter the email address of the user you want to check the permissions"
$user = Read-Host
Powershell.exe C:\Temp\Report\Reports.ps1 -processOneDrive $true -OneDriveEmail $user}
I get this error
Powershell.exe : C:\Temp\ReportSharedFiles\ReportSharedFiles.ps1 : Missing an argument for parameter 'OneDriveEmail'. Specify a
At C:\Temp\ReportSharedFiles\Full Exchange Script Menu.ps1:88 char:2
+ Powershell.exe "c:\Temp\ReportSharedFiles\ReportSharedFiles.ps1" -pr ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (C:\Temp\ReportS...il'. Specify a :String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
parameter of type 'System.String' and try again.
At line:1 char:71
+ ... haredFiles\ReportSharedFiles.ps1 -processOneDrive True -OneDriveEmail
+ ~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [ReportSharedFiles.ps1], ParameterBindingException
+ FullyQualifiedErrorId : MissingArgument,ReportSharedFiles.ps1
What am i doing wrong and how can i get this to work? any help will be appreciated
I believe its asking you for a sting parameter in the error
parameter of type 'System.String' and try again.
Hope this works out>
{ [string]$user = Read-Host "Please Enter the email address of the user you want to check the permissions"
Powershell.exe C:\Temp\Report\Reports.ps1 -processOneDrive $true -OneDriveEmail $user}
Type String >
I have figured it out. It seems when running the powershell script within another script and to have the arguments in. when it comes to the -processOneDrive $true It tried to convert that to boolem which caused errors. i changed this to 1 which im sure means true so code looks like this
Powershell.exe "c:\Temp\Report\Reports.ps1" -processOneDrive 1 -OneDriveEmail $user
Now it runs smoothly. Thanks for everyone that tried to help me with this :)
Related
I have been reading some questions and can find information on creating scripts but none seemingly using the object type "Computer".
Apologies if this is more suited to superuser. But this is still at the script level and as such I thought it would be best placed here.
Here is my script. I want to add a domain registered Server (Computer) to the performance monitor users group on a range of servers.
$ComputerName = Read-Host "Remote Computer name:"
$PmuGroup = [ADSI]"WinNT://$ComputerName/Performance Monitor Users,group"
$User = [ADSI]"WinNT://DOMAIN/ServerName,computer"
$PmuGroup.Add($User.Path)
The following error is displayed:
Exception calling "Add" with "1" argument(s): "A member could not be added to
or removed from the local group because
the member does not exist.
"
At line:1 char:1
+ $AdminGroup.Add($User.Path)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : CatchFromBaseAdapterMethodInvokeTI
If I enter $user into PS, it returns the Path and seemingly finds the machine.
Tried without .path as suggested in comments;
PS C:\WINDOWS> $PmuGroup.Add($User)
Exception calling "Add" with "1" argument(s): "Type mismatch. (Exception
from HRESULT: 0x80020005
(DISP_E_TYPEMISMATCH))"
At line:1 char:1
+ $PmuGroup.Add($User)
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : CatchFromBaseAdapterMethodInvokeTI
Is this an error with my script / can anyone please advise on any errors in it?
For info : Domain/ServerName is not what is being used. I have removed the actual name from here.
The samAccountName of a computer account always ends with a $:
$ComputerName = Read-Host "Remote Computer name:"
$PmuGroup = [ADSI]"WinNT://$ComputerName/Performance Monitor Users,group"
$Computer = [ADSI]"WinNT://DOMAIN/ServerName$"
$PmuGroup.Add($Computer.Path)
Basically, I run this application a lot with different launch parameters.
I usually open up PowerShell in the folder of application and write something like this.
.\Name.exe -specific -launch -parameters
The application will start running, so I'm trying to streamline this a little bit and grab the syntax for launching the application from its cfg file.
What I've been trying
function startfunction {
cls
echo "---------------------------------------------------------"
echo ""
echo " Enter Config Name"
echo ""
echo "---------------------------------------------------------"
$name = Read-Host -Prompt 'Enter Config';
Get-Content -Path .\application\configs\$name.cfg |
Write-Output -OutVariable launch;
Start-Process $launch;
}
Contents of $name.cfg:
.\Name.exe -specific -launch -parameters
Results/Error:
Enter Config: Name
.\Name.exe -specific -launch -parameters
Start-Process : Cannot convert 'System.Collections.ArrayList' to the type
'System.String' required by parameter 'FilePath'. Specified method is not
supported.
At C:\PSM0001.ps1:38 char:17
+ Start-Process $launch;
+ ~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Start-Process], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.StartProcessCommand
I have a funktion to list all email-addresses on a specified user in Office365 and I use this function to check if an email-address is available.
Why is the Try-Catch not working in VS Code but in PS ISE?
Function ListAllEmailAdresses
{
param ($ID)
Try
{
$Mailbox = Get-Mailbox -Identity $ID -ErrorAction Stop
$VarUser = Get-User -Identity $ID -ErrorAction Stop
Write-Output "Email is occupied by: $Mailbox, $($VarUser.Title)"
Write-Output $Mailbox.EmailAddresses
}
Catch
{
Write-Output "E-mail $ID is available"
}
}
when calling this function in VS Code the Try-Catch is not working.
PS C:\script> ListAllEmailAdresses -ID 'lidingo#elon.se'
The operation couldn't be performed because object 'lidingo#elon.se' couldn't be found on 'VI1PR03DC0025.eurprd03.prod.outlook.com'.
+ CategoryInfo : NotSpecified: (:) [Get-Mailbox], ManagementObjectNotFoundException
+ FullyQualifiedErrorId : [Server=VI1PR03MB3165,RequestId=62016320-c687-41ed-9949-4b0fe854d821,TimeStamp=2017-08-09 13:54:40] [FailureCategory=Cmdlet-ManagementObjectNotFoundException] 2CD51ECE,Microsoft.Exchange.Management.RecipientTasks.GetMailbox
+ PSComputerName : ps.outlook.com
The operation couldn't be performed because object 'lidingo#elon.se' couldn't be found on 'VI1PR03DC0025.eurprd03.prod.outlook.com'.
+ CategoryInfo : NotSpecified: (:) [Get-User], ManagementObjectNotFoundException
+ FullyQualifiedErrorId : [Server=VI1PR03MB3165,RequestId=db435869-8b64-4edf-bb90-a2eb836b07fa,TimeStamp=2017-08-09 13:54:41] [FailureCategory=Cmdlet-ManagementObjectNotFoundException] DAFB12B9,Microsoft.Exchange.Management.RecipientTasks.GetUser
+ PSComputerName : ps.outlook.com
Email is occupied by: ,
The PS Error say that the called E-mailadrdress could not be found and therefore it should got to the Catch-code. But it doesnt :(
If I call the same function in Powershell ISE I get this result:
PS C:\Script> ListAllEmailAdresses -ID 'lidingo#elon.se'
E-mail lidingo#elon.se is available
The PS Error is catched and I get the wanted output.
/Anders
Below is my script for UCS
Remove-Item F:\Logs\UCS\*
$server= Read-Host -Prompt 'Please enter UCS IP'
$Chasis= '(ChassisId 1)'
connect-UCS $server
Get-UcsTechSupport -PathPattern 'F:\Logs\UCS\${ucs}-techsupp-chassis.tar' -RemoveFromUcs -TimeoutSec 1200 -$Chasis -CimcId all
I am getting below error when I try to run it..
Get-UcsTechSupport : A positional parameter cannot be found that accepts argument '-ChassisId 1'.
At F:\Logs\ucs1.ps1:5 char:1
+ Get-UcsTechSupport -PathPattern 'F:\Logs\UCS\${ucs}-techsupp-chassis.tar' -Remov ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-UcsTechSupport], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Cisco.Ucs.Cmdlets.GetUcsTechSupport
Your problem is this:
-$Chasis
Which resolves to:
-(ChassisId 1)
Pay particular attention to the hyphen (-)
PS is seeing this as the name of a parameter.
I don't know the arguments for the CmdLet you're using, so this corrected code is just an example:
... -TimeoutSec 1200 -ParameterName $Chasis -CimcId all
i have the following code
its to mass enable External Sharing on SPO and OD users
Connect-SPOService -Url https://######-admin.sharepoint.com
$currentSiteCollection = (Get-Content "siteCollectionsEnabled.txt")
$collectionCount = $currentSiteCollection.Count
if ($currentSiteCollection){
foreach ($currentSite in $currentSiteCollection)
{
Clear-Host
Write-Output "Enabling " $currentSite.ToString() $collectionCount.ToString() " sites left"
Set-SPOSite -Identity $currentSite -SharingCapability ExternalUserSharingOnly
Add-Content ODFBSiteSharingEnabled.log $currentSite.ToString()
$collectionCount = $collectionCount - 1
}
}
but when running i get this
8741
sites left
Set-SPOSite : No connection available. Use Connect-SPOService before running this CmdLet.
At C:###\siteCollectionsDisabledEnable\siteEnable.ps1:10 char:9
+ Set-SPOSite -Identity $currentSite -SharingCapability ExternalUserSharin ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Set-SPOSite], InvalidOperationException
some help here?
Are you able to run Connect-SPOService cmdlet on its own? Do you get any error?
If it works fine and you are able to sign in, then remove the first line of your script here and execute the rest of it.