English 中文(简体)
Troublestart PowerShell script from .bat file with multi-line elements
原标题:Trouble starting PowerShell script from .bat file with multi-line parameters

我需要从一个批号卷宗中开立一个权力书,而权力书则接受参数。 今天,我从一行手脚跟着:

cmd.exe /C pwsh.exe -Command "& {C:	emp	est.ps1 -ForceFullSync -AzureUserFilterOverride { $users | Where-Object { ($_.assignedLicenses.Count -ge 1) -and ($_.userPrincipalName -match  domain.com ) } } -CompanyId bb8083d14755f910291fe0e8036d43ea -ManageObjects Contact -AzureUserPropertyList @(@{ msProp =  accountEnabled ; mappedProp =  active  }, @{ msProp =  businessPhones ; mappedProp =  phone  }, @{ msProp =  givenName ; mappedProp =  first_name  }, @{ msProp =  mail ; mappedProp =  email  }, @{ msProp =  mobilePhone ; mappedProp =  mobile_phone  }, @{ msProp =  onPremisesImmutableId ; mappedProp =  u_correlation_id  }, @{ msProp =  surname ; mappedProp =  last_name  }, @{ msProp =  userPrincipalName ; mappedProp =  user_name  }, @{ msProp =  assignedLicenses ; mappedProp =    }) -SecretId 120953 -AzureAdTenantDomain domain.onmicrosoft.com -ServiceNowBaseUri  https://testinstance.service-now.com  -IdentityProviderSysId  5ffa40e4975a391077dd7a76f053afbf  -LogPath C:	empdomainlog.txt -Verbose; Exit $LASTEXITCODE }"

这项工作fine,但难以读(而且会随着附加参数而花更长时间),因此我要按行文加以打破。 我尝试如下:

cmd.exe /C pwsh.exe -Command "& {
    C:	emp	est.ps1 `
    -ForceFullSync `
    -AzureUserFilterOverride { `$users | Where-Object { ($_.assignedLicenses.Count -ge 1) -and ($_.userPrincipalName -match  domain.com ) } } `
    -CompanyId bb8083d14755f910291fe0e8036d43ea `
    -ManageObjects Contact `
    -AzureUserPropertyList @(
        @{ msProp =  accountEnabled ; mappedProp =  active  },
        @{ msProp =  businessPhones ; mappedProp =  phone  },
        @{ msProp =  givenName ; mappedProp =  first_name  },
        @{ msProp =  mail ; mappedProp =  email  },
        @{ msProp =  mobilePhone ; mappedProp =  mobile_phone  },
        @{ msProp =  onPremisesImmutableId ; mappedProp =  u_correlation_id  },
        @{ msProp =  surname ; mappedProp =  last_name  },
        @{ msProp =  userPrincipalName ; mappedProp =  user_name  },
        @{ msProp =  assignedLicenses ; mappedProp =    }
    ) `
    -SecretId 120953 `
    -AzureAdTenantDomain domain.onmicrosoft.com `
    -ServiceNowBaseUri  https://testinstance.service-now.com  `
    -IdentityProviderSysId  5ffa40e4975a391077dd7a76f053afbf  `
    -LogPath C:	empdomainlog.txt `
    -Verbose; `
    Exit `$LASTEXITCODE
}"

但是,当我管理下案卷时,我得到的是“灯塔”的开张。 在我结束发言时,指挥员向我显示:

c: emp>test.bat

c: emp>cmd.exe /C pwsh.exe -Command“&{C:emp est.ps1

c) 帝国;-ForceFullSync ` -ForceFullSync is not recognized as an internal or external command, operable program or batch file.

c) 帝国;-AzureUserFilterOverride { $users | Where-Object { ($_.assignedLicenses.Count -ge 1) -and ($_.userPrincipalName -match domain.com ) } } -AzureUserFilterOverride is not recognized as an internal or external command, operable program or batch file.

c) 帝国;

为依据 利用多线权力 壳牌照,由厘米d.exe 我试图用这样的谨慎性质来取代线背书:

cmd.exe /C pwsh.exe -Command "& {
    C:	emp	est.ps1 ^
    -ForceFullSync ^
    -AzureUserFilterOverride { `$users | Where-Object { ($_.assignedLicenses.Count -ge 1) -and ($_.userPrincipalName -match  domain.com ) } } ^
    -CompanyId bb8083d14755f910291fe0e8036d43ea ^
    -ManageObjects Contact ^
    -AzureUserPropertyList @(
        @{ msProp =  accountEnabled ; mappedProp =  active  },
        @{ msProp =  businessPhones ; mappedProp =  phone  },
        @{ msProp =  givenName ; mappedProp =  first_name  },
        @{ msProp =  mail ; mappedProp =  email  },
        @{ msProp =  mobilePhone ; mappedProp =  mobile_phone  },
        @{ msProp =  onPremisesImmutableId ; mappedProp =  u_correlation_id  },
        @{ msProp =  surname ; mappedProp =  last_name  },
        @{ msProp =  userPrincipalName ; mappedProp =  user_name  },
        @{ msProp =  assignedLicenses ; mappedProp =    }
    ) ^
    -SecretId 120953 ^
    -AzureAdTenantDomain domain.onmicrosoft.com ^
    -ServiceNowBaseUri  https://testinstance.service-now.com  ^
    -IdentityProviderSysId  5ffa40e4975a391077dd7a76f053afbf  ^
    -LogPath C:	empdomainlog.txt ^
    -Verbose; ^
    Exit `$LASTEXITCODE
}"

但当时说的是,

c: emp>test.bat

c: emp>cmd.exe /C pwsh.exe - 通讯“和”;

c) 帝国;C: emp est.ps1 -ForceFullSync
-AzureUserFilterOverride { `$users | Where-Object { ($.assignedLicenses.Count -ge 1) -and ($.userPrincipalName -match domain.com ) } } -CompanyId bb8083d14755f910291fe0e8036d43ea
-ManageObjects Contact -AzureUserPropertyList @( Where-Object is not recognized as an internal or external command, operable program or batch file.

c) 帝国;

我感觉到,我必须结束,但失踪的人不多。

问题回答

我的第一个本能就是尝试这样的东西:

@pwsh.exe -File "C:	emp	est.ps1"^
 -ForceFullSync^
 -AzureUserFilterOverride {^
   $users ^| Where-Object {^
    ($_.assignedLicenses.Count -ge 1) -and ($_.userPrincipalName -match  domain.com )^
   }^
  }^
 -CompanyId bb8083d14755f910291fe0e8036d43ea^
 -ManageObjects Contact^
 -AzureUserPropertyList @(^
   @{ msProp =  accountEnabled ; mappedProp =  active  },^
   @{ msProp =  businessPhones ; mappedProp =  phone  },^
   @{ msProp =  givenName ; mappedProp =  first_name  },^
   @{ msProp =  mail ; mappedProp =  email  },^
   @{ msProp =  mobilePhone ; mappedProp =  mobile_phone  },^
   @{ msProp =  onPremisesImmutableId ; mappedProp =  u_correlation_id  },^
   @{ msProp =  surname ; mappedProp =  last_name  },^
   @{ msProp =  userPrincipalName ; mappedProp =  user_name  },^
   @{ msProp =  assignedLicenses ; mappedProp =    }^
  )^
 -SecretId 120953^
 -AzureAdTenantDomain domain.onmicrosoft.com^
 -ServiceNowBaseUri  https://testinstance.service-now.com ^
 -IdentityProviderSysId  5ffa40e4975a391077dd7a76f053afbf ^
 -LogPath  C:	empdomainlog.txt ^
 -Verbose

我删除了<代码>Exit和>(LASTEXITCODE的指令,因为应当在test.ps1 字母上登记。

关于从cmd.exe——包括必须在<代码>上遵守的附加规则>到—见


CLI 文件错误地建议&{......}要求更正,但此后一直予以纠正。 不幸的是,这一反家长仍然十分普遍。





相关问题
complex batch replacement linux

I m trying to do some batch replacement for/with a fairly complex pattern So far I find the pattern as: find ( -name *.php -o -name *.html ) -exec grep -i -n hello {} + The string I want ...

How to split a string by spaces in a Windows batch file?

Suppose I have a string "AAA BBB CCC DDD EEE FFF". How can I split the string and retrieve the nth substring, in a batch file? The equivalent in C# would be "AAA BBB CCC DDD EEE FFF".Split()[n]

How to check which Operating System?

How can I check OS version in a batch file or through a vbs in an Windows 2k/2k3 environment ? You know ... Something like ... : "If winver Win2k then ... or if winver Win2k3 then ....