So I think this should be pretty easily but its something I constantly trip over.
In this specific example, I am trying to compress a folder. The following code works fine:
However for obvious reasons, I don't want to hard-code common paths into my scripts. So instead of C:\Windows, I'd like to use $env:systemroot. However, Get-WmiObject always seems to choke when plugging in variables into parameters. Any variation of using that variable fails with "Get-WmiObject : Invalid Query". An example of what I am trying to do is listed below:
Is what I want to do even possible? If it is, I bet I'm overlooking something pretty simple?
In this specific example, I am trying to compress a folder. The following code works fine:
Code:
(Get-WmiObject -class "Win32_Directory" -filter "name='C:\\Windows\\System32\\LogFiles'").Compress()
However for obvious reasons, I don't want to hard-code common paths into my scripts. So instead of C:\Windows, I'd like to use $env:systemroot. However, Get-WmiObject always seems to choke when plugging in variables into parameters. Any variation of using that variable fails with "Get-WmiObject : Invalid Query". An example of what I am trying to do is listed below:
Code:
(Get-WmiObject -class "Win32_Directory" -filter "name=$env:systemroot\\System32\LogFiles").Compress()
Is what I want to do even possible? If it is, I bet I'm overlooking something pretty simple?