好的,我有一个概念验证脚本,看起来像这样连接到iTunes:
$username = Read-Host "Please enter your userid for the local machine"
$password = Read-Host "Please enter a password to be encrypted" -AsSecureString
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList @($username,$password)
Invoke-Command -ScriptBlock {
$iTunes = New-Object -ComObject iTunes.application
$itunes | gm
} -ComputerName localhost -Credential $cred
但是它返回以下错误:
Retrieving the COM class factory for component with CLSID {DC0C2640-1415-4644-875C-6F4D769839BA} failed due to the following error: 80080005.
+ CategoryInfo : ResourceUnavailable: (:) [New-Object], COMException
+ FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand
如果它变得有趣,如果我从脚本块中删除-ComputerName localhost -Credential $cred
,它可以正常工作:
TypeName: System.__ComObject#{9dd6680b-3edc-40db-a771-e6fe4832e34a}
Name MemberType Definition
---- ---------- ----------
Authorize Method void Authorize (int, Variant, string)
BackTrack Method void BackTrack ()
CheckVersion Method bool CheckVersion (int, int)
ConvertFile Method IITOperationStatus ConvertFile (string)
ConvertFile2 Method IITConvertOperationStatus ConvertFile2 (string)
ConvertFiles Method IITOperationStatus ConvertFiles (Variant)
ConvertFiles2 Method IITConvertOperationStatus ConvertFiles2 (Variant)
ConvertTrack Method IITOperationStatus ConvertTrack (Variant)
ConvertTrack2 Method IITConvertOperationStatus ConvertTrack2 (Variant)
ConvertTracks Method IITOperationStatus ConvertTracks (Variant)
ConvertTracks2 Method IITConvertOperationStatus ConvertTracks2 (Variant)
CreateEQPreset Method IITEQPreset CreateEQPreset (string)
CreateFolder Method IITPlaylist CreateFolder (string)
CreateFolderInSource Method IITPlaylist CreateFolderInSource (string, Variant)
CreatePlaylist Method IITPlaylist CreatePlaylist (string)
CreatePlaylistInSource Method IITPlaylist CreatePlaylistInSource (string, Variant)
FastForward Method void FastForward ()
GetITObjectByID Method IITObject GetITObjectByID (int, int, int, int)
GetITObjectPersistentIDs Method void GetITObjectPersistentIDs (Variant, int, int)
GetPlayerButtonsState Method void GetPlayerButtonsState (bool, ITPlayButtonState, bool)
GotoMusicStoreHomePage Method void GotoMusicStoreHomePage ()
NextTrack Method void NextTrack ()
OpenURL Method void OpenURL (string)
Pause Method void Pause ()
Play Method void Play ()
PlayerButtonClicked Method void PlayerButtonClicked (ITPlayerButton, int)
PlayFile Method void PlayFile (string)
PlayPause Method void PlayPause ()
PreviousTrack Method void PreviousTrack ()
Quit Method void Quit ()
Resume Method void Resume ()
Rewind Method void Rewind ()
SetOptions Method void SetOptions (int)
Stop Method void Stop ()
SubscribeToPodcast Method void SubscribeToPodcast (string)
UpdateIPod Method void UpdateIPod ()
UpdatePodcastFeeds Method void UpdatePodcastFeeds ()
CanSetShuffle ParameterizedProperty bool CanSetShuffle (Variant) {get}
CanSetSongRepeat ParameterizedProperty bool CanSetSongRepeat (Variant) {get}
ITObjectPersistentIDHigh ParameterizedProperty int ITObjectPersistentIDHigh (Variant) {get}
ITObjectPersistentIDLow ParameterizedProperty int ITObjectPersistentIDLow (Variant) {get}
AppCommandMessageProcessingEnabled Property bool AppCommandMessageProcessingEnabled () {get} {set}
BrowserWindow Property IITBrowserWindow BrowserWindow () {get}
ConvertOperationStatus Property IITConvertOperationStatus ConvertOperationStatus () {get}
CurrentEncoder Property IITEncoder CurrentEncoder () {get} {set}
CurrentEQPreset Property IITEQPreset CurrentEQPreset () {get} {set}
CurrentPlaylist Property IITPlaylist CurrentPlaylist () {get}
CurrentStreamTitle Property string CurrentStreamTitle () {get}
CurrentStreamURL Property string CurrentStreamURL () {get}
CurrentTrack Property IITTrack CurrentTrack () {get}
CurrentVisual Property IITVisual CurrentVisual () {get} {set}
Encoders Property IITEncoderCollection Encoders () {get}
EQEnabled Property bool EQEnabled () {get} {set}
EQPresets Property IITEQPresetCollection EQPresets () {get}
EQWindow Property IITWindow EQWindow () {get}
ForceToForegroundOnDialog Property bool ForceToForegroundOnDialog () {get} {set}
FullScreenVisuals Property bool FullScreenVisuals () {get} {set}
LibraryPlaylist Property IITLibraryPlaylist LibraryPlaylist () {get}
LibrarySource Property IITSource LibrarySource () {get}
LibraryXMLPath Property string LibraryXMLPath () {get}
Mute Property bool Mute () {get} {set}
PlayerPosition Property int PlayerPosition () {get} {set}
PlayerState Property ITPlayerState PlayerState () {get}
SelectedTracks Property IITTrackCollection SelectedTracks () {get}
SoundVolume Property int SoundVolume () {get} {set}
SoundVolumeControlEnabled Property bool SoundVolumeControlEnabled () {get}
Sources Property IITSourceCollection Sources () {get}
Version Property string Version () {get}
Visuals Property IITVisualCollection Visuals () {get}
VisualsEnabled Property bool VisualsEnabled () {get} {set}
VisualSize Property ITVisualSize VisualSize () {get} {set}
Windows Property IITWindowCollection Windows () {get}
有谁知道为什么脚本块上的凭据可能导致此问题?
原因是我正在研究一种运行某些iTunes任务的方法,当从LOCAL SYSTEM服务调用时,所以在某种程度上,我正在尝试将呼叫提升回登录用户。