Hello,
I'm trying to script some IIS configuration. Part of the script I'm writing does some stuff inside the PSDrive:
############################################################################## ## IIS Setup ## ##############################################################################
Import-Module WebAdministration
Write-Host Write-Host "Checking if IIS is running . . ."$iis = Get-WmiObject Win32_Service -ComputerName $computername -Filter "name='W3SVC'" # If IIS is running, delete the "www" local Web site if present. # The IIS: PSDrive is used to accomplish this. if($iis -and $iis.State -eq "Running") { Write-Host "IIS is running."$localsite = 'www1'$path = join-path -path IIS:\Sites -ChildPath $localsite if (test-path -path $path) {
# etc...
However, I get a NullReferenceException here because it can't find the 'IIS:\' part of the path.
I know that IIS is installed and running correctly, and that my module-import is successful (I can see IIS when I use Get-PSDrive:)
PS C:\> Get-PSDrive Name Used (GB) Free (GB) Provider Root CurrentLocation ---- --------- --------- -------- ---- --------------- Alias Alias C 8.96 0.00 FileSystem C:\ Cert Certificate \ D FileSystem D:\ Env Environment HKCU Registry HKEY_CURRENT_USER HKLM Registry HKEY_LOCAL_MACHINE IIS WebAdminis... \\CITLBLDEMO04 [...]
Plus, the error specifically says the path does not exist, not the drive. I've attempted commands before importing the module, and it complained that the drive itself didn't exist. So I'm pretty sure the drive's getting imported all right.
However, I can't use really any CmdLets with this PSDrive at all. Indeed, Get-ChildItem and Set-Location both fail:
PS C:\> Set-Location IIS: Set-Location : Cannot find path 'IIS:\' because it does not exist. At line:1 char:1+ Set-Location IIS:+ ~~~~~~~+ CategoryInfo : ObjectNotFound: (IIS:\:String) [Set-Location], ItemNotFoundException+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand PS C:\> Get-ChildItem -Path IIS:\ Get-ChildItem : Cannot find path '\\CITLBLDEMO04\' because it does not exist. At line:1 char:1+ Get-ChildItem -Path IIS:\+ ~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo : ObjectNotFound: (\\CITLBLDEMO04\:String) [Get-ChildItem], ItemNotFoundException+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
I'm running Powershell v5.0 on Windows 10. On my Windows 7 machine with Powershell v4.0, this works just fine.
Thoughts?